[GRASS-SVN] r55614 - in grass/trunk: general/g.proj lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 3 10:27:00 PDT 2013


Author: martinl
Date: 2013-04-03 10:27:00 -0700 (Wed, 03 Apr 2013)
New Revision: 55614

Modified:
   grass/trunk/general/g.proj/create.c
   grass/trunk/lib/gis/make_loc.c
   grass/trunk/lib/gis/make_mapset.c
Log:
libgis: G_make_location() - check for legal name


Modified: grass/trunk/general/g.proj/create.c
===================================================================
--- grass/trunk/general/g.proj/create.c	2013-04-03 17:04:30 UTC (rev 55613)
+++ grass/trunk/general/g.proj/create.c	2013-04-03 17:27:00 UTC (rev 55614)
@@ -21,7 +21,7 @@
 		    strerror(errno));
     else
 	/* Shouldn't happen */
-	G_fatal_error(_("Unspecified error while creating new location"));
+      G_fatal_error(_("Unable to create location <%s>"), location);
 
     G_message(_("You can switch to the new location by\n`%s=%s`"),
 	      "g.mapset mapset=PERMANENT location", location);

Modified: grass/trunk/lib/gis/make_loc.c
===================================================================
--- grass/trunk/lib/gis/make_loc.c	2013-04-03 17:04:30 UTC (rev 55613)
+++ grass/trunk/lib/gis/make_loc.c	2013-04-03 17:27:00 UTC (rev 55614)
@@ -43,8 +43,10 @@
  * \param proj_units    projection units suitable to write to the PROJ_UNITS
  *                      file, or NULL.
  *
- * \returns 0 on success
- * \returns -1 to indicate a system error (check errno).
+ * \return 0 on success
+ * \return -1 to indicate a system error (check errno).
+ * \return -2 failed to create projection file (currently not used)
+ * \return -3 illegal name 
  */
 int G_make_location(const char *location_name,
                     struct Cell_head *wind,
@@ -53,6 +55,10 @@
 {
     char path[GPATH_MAX];
 
+    /* check if location name is legal */
+    if (G_legal_filename(location_name) != 1)
+        return -3;
+
     /* Try to create the location directory, under the gisdbase. */
     sprintf(path, "%s/%s", G_gisdbase(), location_name);
     if (G_mkdir(path) != 0)
@@ -61,7 +67,6 @@
     /* Make the PERMANENT mapset. */
     sprintf(path, "%s/%s/%s", G_gisdbase(), location_name, "PERMANENT");
     if (G_mkdir(path) != 0) {
-        perror("G_make_location");
 	return -1;
     }
 

Modified: grass/trunk/lib/gis/make_mapset.c
===================================================================
--- grass/trunk/lib/gis/make_mapset.c	2013-04-03 17:04:30 UTC (rev 55613)
+++ grass/trunk/lib/gis/make_mapset.c	2013-04-03 17:27:00 UTC (rev 55614)
@@ -36,6 +36,7 @@
  *
  * \return 0 on success
  * \return -1 to indicate a system error (check errno).
+ * \return -2 illegal name 
  */
 int G_make_mapset(const char *gisdbase_name, const char *location_name,
                   const char *mapset_name)
@@ -53,8 +54,9 @@
 
     /* TODO: Should probably check that user specified location and gisdbase are valid */
 
+    /* check if mapset name is legal */
     if (G_legal_filename(mapset_name) != 1)
-        return -1;
+        return -2;
     
     /* Make the mapset. */
     sprintf(path, "%s/%s/%s", gisdbase_name, location_name, mapset_name);



More information about the grass-commit mailing list