From: Jan Kiszka <
jan.k...@siemens.com>
Add simplistic but generic implementations of strlen and strncmp to the
inmate library. Both will be used for the command line parser.
Signed-off-by: Jan Kiszka <
jan.k...@siemens.com>
---
inmates/lib/inmate_common.h | 2 ++
inmates/lib/string.c | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/inmates/lib/inmate_common.h b/inmates/lib/inmate_common.h
index 30d0d39..382b81b 100644
--- a/inmates/lib/inmate_common.h
+++ b/inmates/lib/inmate_common.h
@@ -40,6 +40,8 @@ void printk(const char *fmt, ...);
void *memset(void *s, int c, unsigned long n);
void *memcpy(void *d, const void *s, unsigned long n);
+unsigned long strlen(const char *s);
+int strncmp(const char *s1, const char *s2, unsigned long n);
void inmate_main(void);
diff --git a/inmates/lib/string.c b/inmates/lib/string.c
index af80517..a6a3874 100644
--- a/inmates/lib/string.c
+++ b/inmates/lib/string.c
@@ -20,3 +20,27 @@ void *memset(void *s, int c, unsigned long n)
*p++ = c;
return s;
}
+
+unsigned long strlen(const char *s1)
+{
+ unsigned long len = 0;
+
+ while (*s1++)
+ len++;
+
+ return len;
+}
+
+int strncmp(const char *s1, const char *s2, unsigned long n)
+{
+ int diff;
+
+ while (n-- > 0) {
+ diff = *s1 - *s2;
+ if (diff)
+ return diff;
+ if (*s1 == 0)
+ break;
+ }
+ return 0;
+}
--
2.1.4