aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDan Fandrich <dan@coneharvesters.com>2009-11-01 04:01:30 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-01 04:01:30 +0100
commitfe4e23f9ded69194d525775b1ef7648461a7f76d (patch)
tree524f5724e56b8fea8e0237cd300a7db4e75f302f /libbb
parent95a036e125c28dc93d91ae77923c02a1684fc5ef (diff)
downloadbusybox-w32-fe4e23f9ded69194d525775b1ef7648461a7f76d.tar.gz
busybox-w32-fe4e23f9ded69194d525775b1ef7648461a7f76d.tar.bz2
busybox-w32-fe4e23f9ded69194d525775b1ef7648461a7f76d.zip
Add more compat code for non GNU environments
Signed-off-by: Dan Fandrich <dan@coneharvesters.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/platform.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/libbb/platform.c b/libbb/platform.c
index 470185a68..fdd388259 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -6,13 +6,13 @@
6 * 6 *
7 * Licensed under the GPL version 2, see the file LICENSE in this tarball. 7 * Licensed under the GPL version 2, see the file LICENSE in this tarball.
8 */ 8 */
9
10#include "libbb.h" 9#include "libbb.h"
11 10
12#ifndef HAVE_STRCHRNUL 11#ifndef HAVE_STRCHRNUL
13char * FAST_FUNC strchrnul(const char *s, int c) 12char* FAST_FUNC strchrnul(const char *s, int c)
14{ 13{
15 while (*s && *s != c) ++s; 14 while (*s != '\0' && *s != c)
15 s++;
16 return (char*)s; 16 return (char*)s;
17} 17}
18#endif 18#endif
@@ -22,15 +22,19 @@ int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
22{ 22{
23 int r; 23 int r;
24 va_list p2; 24 va_list p2;
25 char buf[128];
25 26
26 va_copy(p2, p); 27 va_copy(p2, p);
27 r = vsnprintf(NULL, 0, format, p); 28 r = vsnprintf(buf, 128, format, p);
28 va_end(p); 29 va_end(p);
30
31 if (r < 128) {
32 va_end(p2);
33 return xstrdup(buf);
34 }
35
29 *string_ptr = xmalloc(r+1); 36 *string_ptr = xmalloc(r+1);
30 if (!*string_ptr) 37 r = vsnprintf(*string_ptr, r+1, format, p2);
31 r = -1;
32 else
33 r = vsnprintf(*string_ptr, r+1, format, p2);
34 va_end(p2); 38 va_end(p2);
35 39
36 return r; 40 return r;
@@ -38,6 +42,7 @@ int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
38#endif 42#endif
39 43
40#ifndef HAVE_FDPRINTF 44#ifndef HAVE_FDPRINTF
45/* dprintf is now actually part of POSIX.1, but was only added in 2008 */
41int fdprintf(int fd, const char *format, ...) 46int fdprintf(int fd, const char *format, ...)
42{ 47{
43 va_list p; 48 va_list p;
@@ -55,3 +60,49 @@ int fdprintf(int fd, const char *format, ...)
55} 60}
56#endif 61#endif
57 62
63#ifndef HAVE_MEMRCHR
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.
68 */
69void* FAST_FUNC memrchr(const void *s, int c, size_t n)
70{
71 const char *start = s, *end = s;
72
73 end += n - 1;
74
75 while (end >= start) {
76 if (*end == (char)c)
77 return (void *) end;
78 end--;
79 }
80
81 return NULL;
82}
83#endif
84
85#ifndef HAVE_MKDTEMP
86/* This is now actually part of POSIX.1, but was only added in 2008 */
87char* FAST_FUNC mkdtemp(char *template)
88{
89 if (mktemp(template) == NULL || mkdir(template, 0700) != 0)
90 return NULL;
91 return template;
92}
93#endif
94
95#ifndef HAVE_STRCASESTR
96/* Copyright (c) 1999, 2000 The ht://Dig Group */
97char* FAST_FUNC strcasestr(const char *s, const char *pattern)
98{
99 int length = strlen(pattern);
100
101 while (*s) {
102 if (strncasecmp(s, pattern, length) == 0)
103 return (char *)s;
104 s++;
105 }
106 return 0;
107}
108#endif