"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | c1bdffe | 2001-04-26 15:56:47 +0000 | [diff] [blame] | 2 | /* |
| 3 | * busybox library eXtended function |
| 4 | * |
| 5 | * Copyright (C) 2001 Larry Doolittle, <ldoolitt@recycle.lbl.gov> |
| 6 | * |
"Robert P. J. Day" | 5d8843e | 2006-07-10 11:41:19 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | c1bdffe | 2001-04-26 15:56:47 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Manuel Novoa III | a2949aa | 2001-06-29 18:59:32 +0000 | [diff] [blame] | 10 | #include <string.h> |
Eric Andersen | c1bdffe | 2001-04-26 15:56:47 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
| 12 | |
| 13 | /* Find out if the last character of a string matches the one given Don't |
| 14 | * underrun the buffer if the string length is 0. Also avoids a possible |
| 15 | * space-hogging inline of strlen() per usage. |
| 16 | */ |
Eric Andersen | c911a43 | 2001-05-15 17:42:16 +0000 | [diff] [blame] | 17 | char * last_char_is(const char *s, int c) |
Eric Andersen | c1bdffe | 2001-04-26 15:56:47 +0000 | [diff] [blame] | 18 | { |
Glenn L McGrath | bf91f2e | 2002-12-03 20:34:36 +0000 | [diff] [blame] | 19 | char *sret = (char *)s; |
| 20 | if (sret) { |
| 21 | sret = strrchr(sret, c); |
| 22 | if(sret != NULL && *(sret+1) != 0) |
| 23 | sret = NULL; |
Eric Andersen | 186bf1d | 2001-05-07 23:10:16 +0000 | [diff] [blame] | 24 | } |
Glenn L McGrath | bf91f2e | 2002-12-03 20:34:36 +0000 | [diff] [blame] | 25 | return sret; |
Eric Andersen | c1bdffe | 2001-04-26 15:56:47 +0000 | [diff] [blame] | 26 | } |