blob: b0592568c7ef9a7f8f089fda2784e35005e27d34 [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
Denis Vlasenko6a1d6612006-12-16 22:18:44 +000012/* Find out if the last character of a string matches the one given.
13 * Don't underrun the buffer if the string length is 0.
Eric Andersenc1bdffe2001-04-26 15:56:47 +000014 */
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000015char* FAST_FUNC last_char_is(const char *s, int c)
Eric Andersenc1bdffe2001-04-26 15:56:47 +000016{
Denis Vlasenko6a1d6612006-12-16 22:18:44 +000017 if (s && *s) {
18 size_t sz = strlen(s) - 1;
19 s += sz;
20 if ( (unsigned char)*s == c)
Denis Vlasenko809a6e32006-11-24 22:42:44 +000021 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}