commit cd18973c44cfe405e1f65682aa089d017cff04ac from: Omar Polo date: Fri Aug 13 13:16:03 2021 UTC add has_suffix commit - 5d43215b6f73e6a45da02d7868786eb84195163a commit + cd18973c44cfe405e1f65682aa089d017cff04ac blob - 7e050239e727ed04e21c3f739374a371f9ea5707 blob + 7a2377bbac51378de25faa9e84af9711308db2e4 --- telescope.h +++ telescope.h @@ -339,6 +339,7 @@ void tofu_temp_trust(struct ohash *, const char *, /* util.c */ int mark_nonblock(int); int has_prefix(const char*, const char*); +int has_suffix(const char *, const char *); int unicode_isspace(uint32_t); int unicode_isgraph(uint32_t); int dispatch_imsg(struct imsgev *, short, imsg_handlerfn **, size_t); blob - 17fd68b29018f132049a6bb5b9dc2bbab5d83d65 blob + 117a06d2c1d495102c971d4a8ad30b718749fc3e --- util.c +++ util.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "telescope.h" @@ -50,6 +51,20 @@ has_prefix(const char *str, const char *prfx) } int +has_suffix(const char *str, const char *sufx) +{ + size_t l, s; + + l = strlen(str); + s = strlen(sufx); + + if (l < s) + return 0; + + return !strcmp(str + (l - s), sufx); +} + +int unicode_isspace(uint32_t cp) { if (cp < INT8_MAX)