nckernel  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
strdup.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <stddef.h>
4 #include <stdlib.h>
5 #include <string.h>
6 
7 char *strdup(const char *s)
8 {
9  char *ret;
10 
11  ret = malloc(strlen(s) + 1);
12  if (!ret) {
13  return NULL;
14  }
15 
16  strcpy(ret, s);
17  return ret;
18 }
19 
20 char *strndup(const char *s, size_t n)
21 {
22  char *ret;
23  int len;
24 
25  len = strlen(s);
26  len = len < n ? len : n;
27 
28  ret = malloc(len + 1);
29  if (!ret) {
30  return NULL;
31  }
32 
33  strncpy(ret, (char*)s, n);
34  ret[n] = '\0';
35  return ret;
36 }
37 
38 char *strdupa(const char *s)
39 {
40  return NULL;
41 }
42 
43 char *strndupa(const char *s, size_t n)
44 {
45  return NULL;
46 }
47 
48 /* End of a file */