From f77a8c867ecc2881d60345b9e1b1ee4259189e9a Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Thu, 21 Jan 2021 22:45:49 +0000 Subject: [PATCH] add ends_with --- gmid.c | 18 ++++++++++++++++++ gmid.h | 1 + 2 files changed, 19 insertions(+) diff --git a/gmid.c b/gmid.c index 227c60b..b72f571 100644 --- a/gmid.c +++ b/gmid.c @@ -162,6 +162,24 @@ starts_with(const char *str, const char *prefix) return 1; } +int +ends_with(const char *str, const char *sufx) +{ + size_t i, j; + + i = strlen(str); + j = strlen(sufx); + + if (j > i) + return 0; + + i -= j; + for (j = 0; str[i] != '\0'; i++, j++) + if (str[i] != sufx[j]) + return 0; + return 1; +} + ssize_t filesize(int fd) { diff --git a/gmid.h b/gmid.h index e647002..488ade6 100644 --- a/gmid.h +++ b/gmid.h @@ -150,6 +150,7 @@ void log_request(struct client*, char*, size_t); void sig_handler(int); int starts_with(const char*, const char*); +int ends_with(const char*, const char*); ssize_t filesize(int); char *absolutify_path(const char*); void yyerror(const char*);