[GRASS-SVN] r38832 - in grass/trunk: include lib/gis vector/v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 22 03:48:04 EDT 2009


Author: neteler
Date: 2009-08-22 03:48:03 -0400 (Sat, 22 Aug 2009)
New Revision: 38832

Modified:
   grass/trunk/include/gisdefs.h
   grass/trunk/lib/gis/strings.c
   grass/trunk/vector/v.in.ogr/main.c
Log:
G_strdup() back for Windows (merge from devel_branch6, r38567)

Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2009-08-21 21:17:33 UTC (rev 38831)
+++ grass/trunk/include/gisdefs.h	2009-08-22 07:48:03 UTC (rev 38832)
@@ -565,6 +565,7 @@
 void G_str_to_lower(char *);
 int G_str_to_sql(char *);
 char *G_squeeze(char *);
+char *G_strdup(const char *);
 
 /* system.c */
 int G_system(const char *);

Modified: grass/trunk/lib/gis/strings.c
===================================================================
--- grass/trunk/lib/gis/strings.c	2009-08-21 21:17:33 UTC (rev 38831)
+++ grass/trunk/lib/gis/strings.c	2009-08-22 07:48:03 UTC (rev 38832)
@@ -108,6 +108,29 @@
 }
 
 /*!
+ * \brief Copies the null-terminated string into a newly
+ * allocated string. The string is allocated using G_malloc().
+ *
+ * \param[in] string the string to duplicate
+ *
+ * \return pointer to a string that is a duplicate of the string
+ *  given to G_strdup().
+ * \return NULL if unable to allocate the required space
+ */
+char *G_strdup(const char *string)
+{
+    char *p;
+
+    p = G_malloc(strlen(string) + 1);
+
+    if (p != NULL) {
+	strcpy(p, string);
+    }
+
+    return p;
+}
+
+/*!
  * \brief Replace all occurencies of old_str in buffer with new_str
  *
  * Code example:

Modified: grass/trunk/vector/v.in.ogr/main.c
===================================================================
--- grass/trunk/vector/v.in.ogr/main.c	2009-08-21 21:17:33 UTC (rev 38831)
+++ grass/trunk/vector/v.in.ogr/main.c	2009-08-22 07:48:03 UTC (rev 38832)
@@ -663,7 +663,7 @@
 		G_debug(3, "Ogr_ftype: %i", Ogr_ftype);	/* look up below */
 
 		if (i < ncnames - 1) {
-		    Ogr_fieldname = strdup(cnames_opt->answers[i + 1]);
+		    Ogr_fieldname = G_strdup(cnames_opt->answers[i + 1]);
 		}
 		else {
 		    /* Change column names to [A-Za-z][A-Za-z0-9_]* */
@@ -679,7 +679,7 @@
 		/* avoid that we get the 'cat' column twice */
 		if (strcmp(Ogr_fieldname, "cat") == 0) {
 		    sprintf(namebuf, "%s_", Ogr_fieldname);
-		    Ogr_fieldname = strdup(namebuf);
+		    Ogr_fieldname = G_strdup(namebuf);
 		}
 
 		/* captial column names are a pain in SQL */



More information about the grass-commit mailing list