diff options
author | drath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2006-06-25 20:44:25 +0000 |
---|---|---|
committer | drath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2006-06-25 20:44:25 +0000 |
commit | d4d36b0a9a778caec77fb8e4ce5b1e406d5a8f50 (patch) | |
tree | e93591472f0a6531631143da80ec9400f7fa09ab /src/server | |
parent | db0264db2af7c86959aeb821504c9dcd72134425 (diff) | |
download | openocd+libswd-d4d36b0a9a778caec77fb8e4ce5b1e406d5a8f50.tar.gz openocd+libswd-d4d36b0a9a778caec77fb8e4ce5b1e406d5a8f50.tar.bz2 openocd+libswd-d4d36b0a9a778caec77fb8e4ce5b1e406d5a8f50.tar.xz openocd+libswd-d4d36b0a9a778caec77fb8e4ce5b1e406d5a8f50.zip |
- changed use of bzero (deprecated) to memset (thanks to Spen for pointing this out)
- changed fallback implementation of strndup to something that works on all systems (thanks to Spen for this patch)
git-svn-id: svn://svn.berlios.de/openocd/trunk@75 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/gdb_server.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index e8664bb2..b0c09961 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -32,14 +32,18 @@ #include <unistd.h> #include <stdlib.h> -// -ino: 060521-1116 #ifndef HAVE_STRNDUP #include <stdio.h> -char * strndup(char * str, int n) { - unsigned char * tmp = malloc((size_t)n+1); - if (! tmp) perror("gdb_server malloc failed"); - if (strlcpy(tmp, str, n) > n) perror("gdb_server strndup: too long"); - return tmp; +char* strndup(const char *s, size_t n) +{ + size_t len = strnlen (s, n); + char *new = (char *) malloc (len + 1); + + if (new == NULL) + return NULL; + + new[len] = '\0'; + return (char *) memcpy (new, s, len); } #endif |