소스 검색

libgis: G_make_location() - check for legal name

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55614 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 년 전
부모
커밋
311392ebcb
3개의 변경된 파일12개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      general/g.proj/create.c
  2. 8 3
      lib/gis/make_loc.c
  3. 3 1
      lib/gis/make_mapset.c

+ 1 - 1
general/g.proj/create.c

@@ -21,7 +21,7 @@ void create_location(char *location)
 		    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);

+ 8 - 3
lib/gis/make_loc.c

@@ -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 @@ int G_make_location(const char *location_name,
 {
     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 @@ int G_make_location(const char *location_name,
     /* 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;
     }
 

+ 3 - 1
lib/gis/make_mapset.c

@@ -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 @@ int G_make_mapset(const char *gisdbase_name, const char *location_name,
 
     /* 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);