blob: 9194ac05f03a24cac9da6870942f9db4716cfccf [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
Manuel Novoa III a2949aa2001-06-29 18:59:32 +000010#include <string.h>
Eric Andersenc1bdffe2001-04-26 15:56:47 +000011#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 Andersenc911a432001-05-15 17:42:16 +000017char * last_char_is(const char *s, int c)
Eric Andersenc1bdffe2001-04-26 15:56:47 +000018{
Glenn L McGrathbf91f2e2002-12-03 20:34:36 +000019 char *sret = (char *)s;
20 if (sret) {
21 sret = strrchr(sret, c);
22 if(sret != NULL && *(sret+1) != 0)
23 sret = NULL;
Eric Andersen186bf1d2001-05-07 23:10:16 +000024 }
Glenn L McGrathbf91f2e2002-12-03 20:34:36 +000025 return sret;
Eric Andersenc1bdffe2001-04-26 15:56:47 +000026}