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.kiszka@siemens.com>
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);
*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;
+}