From d74b562f508475192b6783b0b2d4dae4e5c2fa93 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 8 May 2017 23:01:06 -0500 Subject: Move strend() to lib/lib.c --- lib/lib.c | 9 +++++++++ lib/lib.h | 1 + 2 files changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/lib.c b/lib/lib.c index f6776142..ceced263 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -392,6 +392,15 @@ int unescape(char c) return (idx == -1) ? 0 : to[idx]; } +char *strend(char *str, char *suffix) +{ + long a = strlen(str), b = strlen(suffix); + + if (a>b && !strcmp(str += a-b, suffix)) return str; + + return 0; +} + // If *a starts with b, advance *a past it and return 1, else return 0; int strstart(char **a, char *b) { diff --git a/lib/lib.h b/lib/lib.h index d3f9b1dd..efdc1fa4 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -206,6 +206,7 @@ char *strlower(char *s); char *strafter(char *haystack, char *needle); char *chomp(char *s); int unescape(char c); +char *strend(char *str, char *suffix); int strstart(char **a, char *b); off_t fdlength(int fd); void loopfiles_rw(char **argv, int flags, int permissions, -- cgit v1.2.3