summaryrefslogtreecommitdiffstats
path: root/src/lib/string_utils.C
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/string_utils.C')
-rw-r--r--src/lib/string_utils.C59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/lib/string_utils.C b/src/lib/string_utils.C
index 79a8bf709..27d9228fb 100644
--- a/src/lib/string_utils.C
+++ b/src/lib/string_utils.C
@@ -120,4 +120,61 @@ extern "C" int memcmp(const void *p1, const void *p2, size_t len)
}
return 0;
-} \ No newline at end of file
+}
+
+extern "C" int strncmp(const char* a, const char* b, size_t l)
+{
+ if(l==0)
+ {
+ return 0;
+ }
+
+ const char* begin=a;
+ while( (*a != '\0') && (*b != '\0')
+ && (static_cast<size_t>(a-begin)+1<l) )
+ {
+ if (*a == *b)
+ {
+ a++; b++;
+ }
+ else
+ {
+ return (*a > *b) ? 1 : -1;
+ }
+ }
+ if (*a == *b)
+ {
+ return 0;
+ }
+ if (*a == '\0')
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+}
+
+extern "C" char* strncpy(char* d, const char* s, size_t l)
+{
+ char* d1 = d;
+ size_t len = 0;
+
+ do
+ {
+ if (len++ >= l) break;
+ *d1 = *s;
+ if (*s == '\0') break;
+ d1++; s++;
+ } while(1);
+
+ // pad the remainder
+ while( len < l )
+ {
+ d1[len++] = '\0';
+ }
+
+ return d;
+}
+
OpenPOWER on IntegriCloud