add ends_with

This commit is contained in:
Omar Polo 2021-01-21 22:45:49 +00:00
parent d1ca3911d2
commit f77a8c867e
2 changed files with 19 additions and 0 deletions

18
gmid.c
View File

@ -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)
{

1
gmid.h
View File

@ -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*);