regex: updates from neatvi
[neatlibc.git] / stringc.c
blob15dde06434e6e200c95cf2f959e7ccfa57d8198d
1 #include <stdlib.h>
2 #include <string.h>
4 char *strncpy(char *d, char *s, long n)
6 int len = strlen(s);
7 if (len > n)
8 len = n;
9 memcpy(d, s, len);
10 memset(d + len, 0, n - len);
11 return d;
14 char *strcat(char *d, char *s)
16 strcpy(d + strlen(d), s);
17 return d;
20 char *strstr(char *s, char *r)
22 int len = strlen(r);
23 if (!len)
24 return s;
25 while (s) {
26 if (!memcmp(s, r, len))
27 return s;
28 s = strchr(s + 1, *r);
30 return NULL;
33 char *strdup(const char *s)
35 size_t n = strlen(s) + 1;
36 char *res = malloc(n);
37 if (res)
38 memcpy(res, s, n);
39 return res;