stddef.h: add size_t definition
[neatlibc.git] / stringc.c
blob12044c15aef34840707d2d64483a7d23329cecbc
1 #include <string.h>
3 char *strncpy(char *d, char *s, int n)
5 int len = strlen(s);
6 if (len > n)
7 len = n;
8 memcpy(d, s, len);
9 memcpy(d + len, 0, n - len);
10 return d;
13 char *strcat(char *d, char *s)
15 strcpy(d + strlen(d), s);
16 return d;
19 int strncmp(char *d, char *s, int n)
21 int len = strlen(d);
22 if (len >= n)
23 len = n - 1;
24 return memcmp(d, s, len + 1);
27 char *strstr(char *s, char *r)
29 int len = strlen(r);
30 if (!len)
31 return s;
32 while (s) {
33 if (!memcmp(s, r, len))
34 return s;
35 s = strchr(s + 1, *r);
37 return NULL;