diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-16 22:18:44 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-16 22:18:44 +0000 |
commit | 64dec33725690adf8cbe9dc931b8a0517e09bf1c (patch) | |
tree | 5d78605c22fa0cc8a36e774929c7b3e7dfbad0f4 /libbb | |
parent | 1a3fc4a74b65f20a7d8ae92fc68463406f4cb1f6 (diff) | |
download | busybox-w32-64dec33725690adf8cbe9dc931b8a0517e09bf1c.tar.gz busybox-w32-64dec33725690adf8cbe9dc931b8a0517e09bf1c.tar.bz2 busybox-w32-64dec33725690adf8cbe9dc931b8a0517e09bf1c.zip |
diff: fix -q exit code
last_char_is: sacrifice 9 bytes but avoid double-scan
git-svn-id: svn://busybox.net/trunk/busybox@16974 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/last_char_is.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index 3616d5916..aaa85ddd9 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c | |||
@@ -9,15 +9,15 @@ | |||
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | /* Find out if the last character of a string matches the one given Don't | 12 | /* Find out if the last character of a string matches the one given. |
13 | * underrun the buffer if the string length is 0. Also avoids a possible | 13 | * Don't underrun the buffer if the string length is 0. |
14 | * space-hogging inline of strlen() per usage. | ||
15 | */ | 14 | */ |
16 | char* last_char_is(const char *s, int c) | 15 | char* last_char_is(const char *s, int c) |
17 | { | 16 | { |
18 | if (s) { | 17 | if (s && *s) { |
19 | s = strrchr(s, c); | 18 | size_t sz = strlen(s) - 1; |
20 | if (s && !s[1]) | 19 | s += sz; |
20 | if ( (unsigned char)*s == c) | ||
21 | return (char*)s; | 21 | return (char*)s; |
22 | } | 22 | } |
23 | return NULL; | 23 | return NULL; |