2 * Replacements for common but usually nonstandard functions that aren't
3 * supplied by all platforms.
5 * Copyright (C) 2009 by Dan Fandrich <dan@coneharvesters.com>, et. al.
7 * Licensed under the GPL version 2, see the file LICENSE in this tarball.
11 #ifndef HAVE_STRCHRNUL
12 char* FAST_FUNC strchrnul(const char *s, int c)
14 while (*s != '\0' && *s != c)
20 #ifndef HAVE_VASPRINTF
21 int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
28 r = vsnprintf(buf, 128, format, p);
36 *string_ptr = xmalloc(r+1);
37 r = vsnprintf(*string_ptr, r+1, format, p2);
45 /* dprintf is now actually part of POSIX.1, but was only added in 2008 */
46 int fdprintf(int fd, const char *format, ...)
53 r = vasprintf(&string_ptr, format, p);
56 r = full_write(fd, string_ptr, r);
64 /* Copyright (C) 2005 Free Software Foundation, Inc.
65 * memrchr() is a GNU function that might not be available everywhere.
66 * It's basically the inverse of memchr() - search backwards in a
67 * memory block for a particular character.
69 void* FAST_FUNC memrchr(const void *s, int c, size_t n)
71 const char *start = s, *end = s;
75 while (end >= start) {
86 /* This is now actually part of POSIX.1, but was only added in 2008 */
87 char* FAST_FUNC mkdtemp(char *template)
89 if (mktemp(template) == NULL || mkdir(template, 0700) != 0)
95 #ifndef HAVE_STRCASESTR
96 /* Copyright (c) 1999, 2000 The ht://Dig Group */
97 char* FAST_FUNC strcasestr(const char *s, const char *pattern)
99 int length = strlen(pattern);
102 if (strncasecmp(s, pattern, length) == 0)