summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/os_calls.c25
-rw-r--r--common/os_calls.h2
2 files changed, 27 insertions, 0 deletions
diff --git a/common/os_calls.c b/common/os_calls.c
index 80e5bad3..ae48fc94 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -1579,7 +1579,32 @@ g_strdup(const char* in)
}
return p;
}
+/*****************************************************************************/
+/* if in = 0, return 0 else return newly alloced copy of input string
+ * if the input string is larger than maxlen the returned string will be
+ * truncated. All strings returned will include null termination*/
+char* APP_CC
+g_strndup(const char* in, const unsigned int maxlen)
+{
+ int len;
+ char* p;
+ if (in == 0)
+ {
+ return 0;
+ }
+ len = g_strlen(in);
+ if(len>maxlen)
+ {
+ len = maxlen-1 ;
+ }
+ p = (char*)g_malloc(len + 2, 0);
+ if (p != NULL)
+ {
+ g_strncpy(p, in,len+1);
+ }
+ return p;
+}
/*****************************************************************************/
int APP_CC
g_strcmp(const char* c1, const char* c2)
diff --git a/common/os_calls.h b/common/os_calls.h
index ddcb59d8..7be659d6 100644
--- a/common/os_calls.h
+++ b/common/os_calls.h
@@ -178,6 +178,8 @@ char* APP_CC
g_strcat(char* dest, const char* src);
char* APP_CC
g_strdup(const char* in);
+char* APP_CC
+g_strndup(const char* in, const unsigned int maxlen);
int APP_CC
g_strcmp(const char* c1, const char* c2);
int APP_CC