diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2020-04-26 01:03:17 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2020-04-26 02:06:17 +0530 |
commit | 99d21531b45f61f0171cda4d1ae3a3262e8fde81 (patch) | |
tree | 69d732a56b08d1717f7f517a6424f2891dbf4e07 /src | |
parent | c732de32e48caadb3a7289be6902f2c21c061eab (diff) | |
download | nnn-99d21531b45f61f0171cda4d1ae3a3262e8fde81.tar.gz |
Use memrchr if available
Diffstat (limited to 'src')
-rw-r--r-- | src/nnn.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -926,7 +926,7 @@ static size_t xstrsncpy(char *restrict dst, const char *restrict src, size_t n) return end - dst; } -static inline size_t xstrlen(const char *s) +static inline size_t xstrlen(const char *restrict s) { #if !defined(__GLIBC__) return strlen(s); // NOLINT @@ -935,7 +935,7 @@ static inline size_t xstrlen(const char *s) #endif } -static char *xstrdup(const char *s) +static char *xstrdup(const char *restrict s) { size_t len = xstrlen(s) + 1; char *ptr = malloc(len); @@ -965,8 +965,12 @@ static bool is_suffix(const char *str, const char *suffix) * And we are NOT expecting a '/' at the end. * Ideally 0 < n <= xstrlen(s). */ -static void *xmemrchr(uchar *s, uchar ch, size_t n) +static void *xmemrchr(uchar *restrict s, uchar ch, size_t n) { +#if defined(__GLIBC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) + return memrchr(s, ch, n); +#else + if (!s || !n) return NULL; @@ -978,6 +982,7 @@ static void *xmemrchr(uchar *s, uchar ch, size_t n) while (s != ptr); return NULL; +#endif } /* Assumes both the paths passed are directories */ |