Skip to content

Commit

Permalink
Avoid memrchr() when not available
Browse files Browse the repository at this point in the history
Defining `_GNU_SOURCE` does not guarantee it's availablity, apparently.
  • Loading branch information
dr8co committed Jul 12, 2024
1 parent 3e3189a commit e4f4b3c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lite_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,8 @@ bool string_swap(lite_string *const restrict s1, lite_string *const restrict s2)
*/
LITE_ATTR_REPRODUCIBLE size_t string_find_last_of(const lite_string *const restrict s, const char c) {
if (s && s->size && c != '\0') {
#if defined(_GNU_SOURCE) && !(defined(_WIN32) || defined(WIN32) || _MSC_VER)
#if defined(_GNU_SOURCE) && defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 2 && !(defined(_WIN32) || defined(WIN32) || _MSC_VER)
// Use the GNU extension memrchr if available (GLIBC 2.2 or later)
const char *found = (const char *) memrchr(s->data, c, s->size);
if (found) return found - s->data;
#else
Expand Down

0 comments on commit e4f4b3c

Please sign in to comment.