From 9266387d534a8ca397824e07e62e390ca1dbb236 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 26 Sep 2014 13:49:16 -0400 Subject: [PATCH] Removed dependency on strdup --- source/opts.c | 13 ++++++++++++- source/opts.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/opts.c b/source/opts.c index f4713b0..42e74c1 100644 --- a/source/opts.c +++ b/source/opts.c @@ -3,6 +3,8 @@ #include #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; +} + diff --git a/source/opts.h b/source/opts.h index e922db6..3f8571e 100644 --- a/source/opts.h +++ b/source/opts.h @@ -34,7 +34,7 @@ typedef enum { } OptionType_T; typedef struct OptionConfig_T { - int type; + unsigned int type; char* name; char* dest; int has_arg; -- 2.55.0