204
|
1 #include <stdlib.h> |
|
2 #include <string.h> |
|
3 /* ----------------------------- MNI Header ----------------------------------- |
|
4 @NAME : strdup |
|
5 @INPUT : string - string to duplicate |
|
6 @OUTPUT : (none) |
|
7 @RETURNS : Pointer to duplicate string or NULL if an error occurs |
|
8 @DESCRIPTION: Makes a duplicate of a string and returns a pointer to it. |
|
9 @METHOD : VAX CC rtl does not have strdup, so we provide it here to |
|
10 be included in minc.olb. |
|
11 @GLOBALS : |
|
12 @CALLS : |
|
13 @CREATED : June 18, 1993 (Peter Neelin) |
1232
|
14 @MODIFIED : |
|
15 * $Log: strdup.c,v $ |
|
16 * Revision 6.1 1999-10-19 14:45:11 neelin |
|
17 * Fixed Log subsitutions for CVS |
|
18 * |
|
19 * Revision 6.0 1997/09/12 13:24:54 neelin |
|
20 * Release of minc version 0.6 |
|
21 * |
1112
|
22 * Revision 5.0 1997/08/21 13:25:53 neelin |
|
23 * Release of minc version 0.5 |
|
24 * |
1094
|
25 * Revision 4.0 1997/05/07 20:07:52 neelin |
|
26 * Release of minc version 0.4 |
|
27 * |
1062
|
28 * Revision 3.0 1995/05/15 19:33:12 neelin |
|
29 * Release of minc version 0.3 |
|
30 * |
870
|
31 * Revision 2.0 1994/09/28 10:38:18 neelin |
|
32 * Release of minc version 0.2 |
|
33 * |
619
|
34 * Revision 1.3 94/09/28 10:37:36 neelin |
|
35 * Pre-release |
|
36 * |
618
|
37 * Revision 1.2 93/08/11 12:06:30 neelin |
|
38 * Added RCS logging in source. |
|
39 * |
204
|
40 ---------------------------------------------------------------------------- */ |
|
41 char *strdup(const char *string) |
|
42 { |
|
43 int length; |
|
44 char *new_string; |
|
45 |
|
46 /* Get the string length */ |
|
47 length = strlen(string); |
|
48 |
|
49 /* Allocate space */ |
|
50 new_string = malloc((size_t) length+1); |
|
51 if (new_string == NULL) { |
|
52 return NULL; |
|
53 } |
|
54 |
|
55 /* Copy the string */ |
|
56 return strcpy(new_string, string); |
|
57 |
|
58 } |