diff options
author | Eric Andersen | 2001-05-07 23:10:16 +0000 |
---|---|---|
committer | Eric Andersen | 2001-05-07 23:10:16 +0000 |
commit | 186bf1defcd67eb633eded5685864ce1fa36fdff (patch) | |
tree | 01324734c757fcccb90765f2a0fe1bf82fd35f13 | |
parent | de0ca0cd9ee677a1d465039e30235d0fe63e5558 (diff) | |
download | busybox-186bf1defcd67eb633eded5685864ce1fa36fdff.zip busybox-186bf1defcd67eb633eded5685864ce1fa36fdff.tar.gz |
This is Vladimir's update to last_char_is(). Since 'char *' is
the least common denominator, I modified it to use that (not const),
which will minimize the need for casting elsewhere.
-rw-r--r-- | libbb/last_char_is.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index b4bb7ec..36b695b 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c @@ -25,9 +25,12 @@ * underrun the buffer if the string length is 0. Also avoids a possible * space-hogging inline of strlen() per usage. */ -int last_char_is(const char *s, const int c) +char * last_char_is(char *s, int c) { - int l = strlen(s); - if (l==0) return 0; - return (s[l-1] == c); + char *sret = s+strlen(s)-1; + if (sret>=s && *sret == c) { + return sret; + } else { + return NULL; + } } |