annotate port/strdup.c @ 316:4c0af1143fc4

Add wait operation (no tests yet)
author David Demelier <markand@malikania.fr>
date Tue, 03 Mar 2015 18:48:54 +0100
parents 2d6c466e56dc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 /*
122
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
2 * strdup.c -- duplicate a string
121
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 *
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
4 * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr>
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 *
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 * Permission to use, copy, modify, and/or distribute this software for any
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 * copyright notice and this permission notice appear in all copies.
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 *
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 */
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
18
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
19 #include <stdio.h>
122
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
20 #include <stdlib.h>
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
21 #include <string.h>
121
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
22
122
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
23 char *
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
24 strdup(const char *src)
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
25 {
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
26 char *dst;
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
27 size_t len;
121
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
28
122
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
29 len = strlen(src);
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
30
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
31 if ((dst = calloc(len + 1, sizeof (char))) == NULL)
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
32 return NULL;
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
33
2d6c466e56dc Add copies of strdup
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
34 return strcpy(dst, src);
121
0635f98a2227 Forgot to add port .h files
David Demelier <markand@malikania.fr>
parents:
diff changeset
35 }