]> git.mdlowis.com Git - projs/opts.git/commitdiff
Removed dependency on strdup
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 26 Sep 2014 17:49:16 +0000 (13:49 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 26 Sep 2014 17:49:16 +0000 (13:49 -0400)
source/opts.c
source/opts.h

index f4713b039b85fdf46836f8993115e652cff30d1a..42e74c10ea316f46b598415770229fb207fa0465 100644 (file)
@@ -3,6 +3,8 @@
 #include <string.h>
 #include "opts.h"
 
+static char* strclone(const char* p_old);
+
 Result_T* OPTS_ParseOptions( OptionConfig_T* opts, int argc, char** argv )
 {
     // Setup the stream
@@ -185,7 +187,7 @@ void OPTS_AddOption( Result_T* res, char* name, char* arg )
     if( (NULL != res) && (NULL != res->options) )
     {
         Option_T* opt = (Option_T*)malloc( sizeof( Option_T ) );
-        opt->key = strdup( name );
+        opt->key = strclone( name );
         opt->val = arg;
         opt->next = NULL;
         if( res->options->head == NULL )
@@ -249,3 +251,12 @@ char* OPTS_AppendCharacter( char* str, char ch )
     return str;
 }
 
+
+static char* strclone(const char* p_old) {
+    size_t length = strlen(p_old);
+    char* p_str = (char*)malloc(length+1);
+    memcpy(p_str, p_old, length);
+    p_str[length] = '\0';
+    return p_str;
+}
+
index e922db648a2984c3b3ea3af3925ebf4430b25d7c..3f8571e14ced85cdf7ed93bf377cf44bfe84d4be 100644 (file)
@@ -34,7 +34,7 @@ typedef enum {
 } OptionType_T;
 
 typedef struct OptionConfig_T {
-    int type;
+    unsigned int type;
     char* name;
     char* dest;
     int has_arg;