Browse Source

G_strdup() back for Windows (merge from devel_branch6, https://trac.osgeo.org/grass/changeset/38567)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38832 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 15 years ago
parent
commit
1f0953aca0
3 changed files with 26 additions and 2 deletions
  1. 1 0
      include/gisdefs.h
  2. 23 0
      lib/gis/strings.c
  3. 2 2
      vector/v.in.ogr/main.c

+ 1 - 0
include/gisdefs.h

@@ -565,6 +565,7 @@ void G_str_to_upper(char *);
 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 *);

+ 23 - 0
lib/gis/strings.c

@@ -108,6 +108,29 @@ char *G_strchg(char *bug, char character, char new)
 }
 
 /*!
+ * \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:

+ 2 - 2
vector/v.in.ogr/main.c

@@ -663,7 +663,7 @@ int main(int argc, char *argv[])
 		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 @@ int main(int argc, char *argv[])
 		/* 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 */