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);
33 *string_ptr = xstrdup(buf);
37 *string_ptr = xmalloc(r+1);
38 r = vsnprintf(*string_ptr, r+1, format, p2);
46 /* dprintf is now actually part of POSIX.1, but was only added in 2008 */
47 int fdprintf(int fd, const char *format, ...)
54 r = vasprintf(&string_ptr, format, p);
57 r = full_write(fd, string_ptr, r);
65 /* Copyright (C) 2005 Free Software Foundation, Inc.
66 * memrchr() is a GNU function that might not be available everywhere.
67 * It's basically the inverse of memchr() - search backwards in a
68 * memory block for a particular character.
70 void* FAST_FUNC memrchr(const void *s, int c, size_t n)
72 const char *start = s, *end = s;
76 while (end >= start) {
87 /* This is now actually part of POSIX.1, but was only added in 2008 */
88 char* FAST_FUNC mkdtemp(char *template)
90 if (mktemp(template) == NULL || mkdir(template, 0700) != 0)
96 #ifndef HAVE_STRCASESTR
97 /* Copyright (c) 1999, 2000 The ht://Dig Group */
98 char* FAST_FUNC strcasestr(const char *s, const char *pattern)
100 int length = strlen(pattern);
103 if (strncasecmp(s, pattern, length) == 0)