summaryrefslogtreecommitdiff
path: root/nuttx/libc/string/lib_strndup.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-05 16:07:37 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-05 16:07:37 +0000
commit7f6ca26cb1b0fe979edd7bd4ba0535801178847a (patch)
treed9cc11059ec3daa938a3727c0073dc39ae619798 /nuttx/libc/string/lib_strndup.c
parentd010ac80c21ce2cae58d21c3e909a7c000ecdc3f (diff)
downloadpx4-nuttx-7f6ca26cb1b0fe979edd7bd4ba0535801178847a.tar.gz
px4-nuttx-7f6ca26cb1b0fe979edd7bd4ba0535801178847a.tar.bz2
px4-nuttx-7f6ca26cb1b0fe979edd7bd4ba0535801178847a.zip
Extend tools/configure.c for better compatibility with configure.sh
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5481 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/libc/string/lib_strndup.c')
-rw-r--r--nuttx/libc/string/lib_strndup.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/nuttx/libc/string/lib_strndup.c b/nuttx/libc/string/lib_strndup.c
index 524e09754..5a78e2dcf 100644
--- a/nuttx/libc/string/lib_strndup.c
+++ b/nuttx/libc/string/lib_strndup.c
@@ -1,7 +1,7 @@
/************************************************************************
* libc/string//lib_strndup.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -68,13 +68,9 @@ FAR char *strndup(FAR const char *s, size_t size)
FAR char *news = NULL;
if (s)
{
- /* Get the size of the new string = MIN(strlen(s), size) */
+ /* Get the size of the new string (limited to size) */
- size_t allocsize = strlen(s);
- if (allocsize > size)
- {
- allocsize = size;
- }
+ size_t allocsize = strnlen(s, size);
/* Allocate the new string, adding 1 for the NUL terminator */
@@ -89,5 +85,6 @@ FAR char *strndup(FAR const char *s, size_t size)
news[allocsize] = '\0';
}
}
+
return news;
}