OLD | NEW |
1 /* | 1 /* |
2 * strdup() implementation with error checking (using xmalloc). | 2 * strdup() implementation with error checking (using xmalloc). |
3 * | 3 * |
4 * Copyright (c) 1988, 1993 | 4 * Copyright (c) 1988, 1993 |
5 * The Regents of the University of California. All rights reserved. | 5 * The Regents of the University of California. All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 11 matching lines...) Expand all Loading... |
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 * SUCH DAMAGE. | 29 * SUCH DAMAGE. |
30 */ | 30 */ |
31 #include "util.h" | 31 #include "util.h" |
32 RCSID("$Id: xstrdup.c 1893 2007-07-14 03:11:32Z peter $"); | |
33 | 32 |
34 #include "coretype.h" | 33 #include "coretype.h" |
35 | 34 |
36 #if defined(LIBC_SCCS) && !defined(lint) | 35 #if defined(LIBC_SCCS) && !defined(lint) |
37 static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; | 36 static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; |
38 #endif /* LIBC_SCCS and not lint */ | 37 #endif /* LIBC_SCCS and not lint */ |
39 | 38 |
40 | 39 |
41 #ifdef WITH_DMALLOC | 40 #ifdef WITH_DMALLOC |
42 #undef yasm__xstrdup | 41 #undef yasm__xstrdup |
(...skipping 17 matching lines...) Expand all Loading... |
60 size_t len = 0; | 59 size_t len = 0; |
61 char *copy; | 60 char *copy; |
62 | 61 |
63 while (len < max && str[len] != '\0') | 62 while (len < max && str[len] != '\0') |
64 len++; | 63 len++; |
65 copy = yasm_xmalloc(len+1); | 64 copy = yasm_xmalloc(len+1); |
66 memcpy(copy, str, len); | 65 memcpy(copy, str, len); |
67 copy[len] = '\0'; | 66 copy[len] = '\0'; |
68 return (copy); | 67 return (copy); |
69 } | 68 } |
OLD | NEW |