OSDN Git Service
(root)
/
android-x86
/
bionic.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
30a419a
)
string: tidy up strndup()
author
André Goddard Rosa
<andre.goddard@gmail.com>
Sun, 31 Jan 2010 00:29:59 +0000
(22:29 -0200)
committer
André Goddard Rosa
<andre.goddard@gmail.com>
Sun, 31 Jan 2010 00:29:59 +0000
(22:29 -0200)
It decreases code size:
text data bss dec hex filename
161 0 0 161 a1 strndup-BEFORE.o
153 0 0 153 99 strndup-AFTER.o
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
libc/string/strndup.c
patch
|
blob
|
history
diff --git
a/libc/string/strndup.c
b/libc/string/strndup.c
index
da9a55f
..
9dca79c
100644
(file)
--- a/
libc/string/strndup.c
+++ b/
libc/string/strndup.c
@@
-31,12
+31,14
@@
char* strndup(const char* s, size_t n)
{
size_t slen = (size_t)strlen(s);
- int len = slen < n ? slen : n;
- char* copy = malloc(len+1);
+ char* copy;
+ if (slen < n)
+ n = slen;
+ copy = malloc(n+1);
if (copy) {
- memcpy(
copy, s, len
);
- copy[
le
n] = 0;
+ memcpy(
copy, s, n
);
+ copy[n] = 0;
}
return copy;
}