X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Flast_char_is.c;h=aaa85ddd9c4e9b105964d2f0b38555c7c478a66e;hb=21b080daa8c180a43d10d6b3dee47134ef21e581;hp=b4bb7ec32fad30cbae5177498d6e3653a787af92;hpb=c1bdffe99b6fa6fdb0f43e0dec85d8bbfcab1572;p=oweals%2Fbusybox.git diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index b4bb7ec32..aaa85ddd9 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c @@ -1,33 +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. */ -int last_char_is(const char *s, const int c) +char* last_char_is(const char *s, int c) { - int l = strlen(s); - if (l==0) return 0; - return (s[l-1] == c); + if (s && *s) { + size_t sz = strlen(s) - 1; + s += sz; + if ( (unsigned char)*s == c) + return (char*)s; + } + return NULL; }