]> git.neil.brown.name Git - metad.git/blob - strdup.c
Assorted reformating
[metad.git] / strdup.c
1
2 #define NULL (0)
3 char *malloc();
4
5 char *strdup(char *s)
6 {
7         if (s==NULL)
8                 return s;
9         return (char *)strcpy(malloc(strlen(s)+1), s);
10 }
11
12 char *strndup(char *s, int a)
13 {
14         char *r;
15         if (s == NULL)
16                 return s;
17
18         r = (char*)malloc(a+1);
19         strncpy(r, s, a);
20         r[a] = 0;
21         return r;
22 }