diff options
author | Holger Lubitz | 2007-08-02 01:48:20 +0200 |
---|---|---|
committer | Holger Lubitz | 2007-08-02 01:48:20 +0200 |
commit | bb94c143d9d4368337dc25d857237b16a2ee4603 (patch) | |
tree | 3a71c5476a96f2b88392f5c4a3754ccbbe2e0010 /src/core/string.c | |
parent | move strndup back to string.c - used by strdup (diff) | |
download | ipxe-bb94c143d9d4368337dc25d857237b16a2ee4603.tar.gz ipxe-bb94c143d9d4368337dc25d857237b16a2ee4603.tar.xz ipxe-bb94c143d9d4368337dc25d857237b16a2ee4603.zip |
move strndup back to string.c - used by strdup
Diffstat (limited to 'src/core/string.c')
-rw-r--r-- | src/core/string.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/core/string.c b/src/core/string.c index 8577215b..2e17bdcb 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -333,6 +333,21 @@ void * memchr(const void *s, int c, size_t n) #endif +char * strndup(const char *s, size_t n) +{ + size_t len = strlen(s); + char *new; + + if (len>n) + len = n; + new = malloc(len+1); + if (new) { + new[len] = '\0'; + memcpy(new,s,len); + } + return new; +} + char * strdup(const char *s) { return strndup(s, ~((size_t)0)); } |