Skip to content

Commit

Permalink
Add implementation of memrchr
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Sep 3, 2019
1 parent 11c1335 commit 0fd7d9c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -12498,6 +12498,7 @@ for ac_func in \
initgroups \
localtime_r \
mallopt \
memrchr \
mkdirat \
openat \
pthread_sigmask \
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ AC_CHECK_FUNCS( \
initgroups \
localtime_r \
mallopt \
memrchr \
mkdirat \
openat \
pthread_sigmask \
Expand Down
3 changes: 3 additions & 0 deletions src/include/autoconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* Define to 1 if you have the `memrchr' function. */
#undef HAVE_MEMRCHR

/* Define to 1 if you have the `mkdirat' function. */
#undef HAVE_MKDIRAT

Expand Down
4 changes: 4 additions & 0 deletions src/include/missing-h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ int strncasecmp(char *s1, char *s2, int n);
int strcasecmp(char *s1, char *s2);
#endif

#ifndef HAVE_MEMRCHR
void *memrchr(const void *s, int c, size_t n);
#endif

#ifndef HAVE_STRSEP
char *strsep(char **stringp, char const *delim);
#endif
Expand Down
19 changes: 18 additions & 1 deletion src/lib/util/missing.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ int strcasecmp(char *s1, char *s2)
}
#endif


#ifndef HAVE_MEMRCHR
/** GNU libc extension on some platforms
*
*/
void *memrchr(void const *s, int c, size_t n)
{
uint8_t *p;

if (n == 0) return NULL;

memcpy(&p, &s, sizeof(p)); /* defeat const */
for (p += (n - 1); p >= (uint8_t const *)s; p--) if (*p == (uint8_t)c) return (void *)p;

return NULL;
}
#endif

#ifndef HAVE_INET_ATON
int inet_aton(char const *cp, struct in_addr *inp)
{
Expand Down Expand Up @@ -478,4 +496,3 @@ char const *inet_ntop(int af, void const *src, char *dst, size_t cnt)
return NULL; /* don't support IPv6 */
}
#endif

0 comments on commit 0fd7d9c

Please sign in to comment.