X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=libbb%2Flast_char_is.c;h=aaa85ddd9c4e9b105964d2f0b38555c7c478a66e;hb=21b080daa8c180a43d10d6b3dee47134ef21e581;hp=ae2d24bf71894d479778cded3ed7643729f661bb;hpb=c911a4389bbaa5ac85d725c8c05e452dfba8583d;p=oweals%2Fbusybox.git diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index ae2d24bf7..aaa85ddd9 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c @@ -1,36 +1,24 @@ +/* vi: set sw=4 ts=4: */ /* * busybox library eXtended function * * Copyright (C) 2001 Larry Doolittle, * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ #include "libbb.h" -/* Find out if the last character of a string matches the one given Don't - * underrun the buffer if the string length is 0. Also avoids a possible - * space-hogging inline of strlen() per usage. +/* Find out if the last character of a string matches the one given. + * Don't underrun the buffer if the string length is 0. */ -char * last_char_is(const char *s, int c) +char* last_char_is(const char *s, int c) { - char *sret = (char *)s+strlen(s)-1; - if (sret>=s && *sret == c) { - return sret; - } else { - return NULL; + if (s && *s) { + size_t sz = strlen(s) - 1; + s += sz; + if ( (unsigned char)*s == c) + return (char*)s; } + return NULL; }