blob: 3616d5916df60f60a91634e35d1ad5e16b614cdc [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Eric Andersenc1bdffe2001-04-26 15:56:47 +00002/*
3 * busybox library eXtended function
4 *
5 * Copyright (C) 2001 Larry Doolittle, <ldoolitt@recycle.lbl.gov>
6 *
"Robert P. J. Day"5d8843e2006-07-10 11:41:19 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersenc1bdffe2001-04-26 15:56:47 +00008 */
9
10#include "libbb.h"
11
12/* Find out if the last character of a string matches the one given Don't
13 * underrun the buffer if the string length is 0. Also avoids a possible
14 * space-hogging inline of strlen() per usage.
15 */
Denis Vlasenko3feb2fc2006-11-24 21:55:55 +000016char* last_char_is(const char *s, int c)
Eric Andersenc1bdffe2001-04-26 15:56:47 +000017{
Denis Vlasenko3feb2fc2006-11-24 21:55:55 +000018 if (s) {
Denis Vlasenko809a6e32006-11-24 22:42:44 +000019 s = strrchr(s, c);
20 if (s && !s[1])
21 return (char*)s;
Eric Andersen186bf1d2001-05-07 23:10:16 +000022 }
Denis Vlasenko3feb2fc2006-11-24 21:55:55 +000023 return NULL;
Eric Andersenc1bdffe2001-04-26 15:56:47 +000024}