diff options
author | Dan Fandrich <dan@coneharvesters.com> | 2009-10-27 11:05:00 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-27 11:05:00 +0100 |
commit | 21a542d7d732735a522c413c0c385e577528ec63 (patch) | |
tree | f0873e7eb57524ca9306d12b6dd2ecd5224f8a0a /libbb/platform.c | |
parent | d83bbf41934382631161845302f5d77027383aba (diff) | |
download | busybox-w32-21a542d7d732735a522c413c0c385e577528ec63.tar.gz busybox-w32-21a542d7d732735a522c413c0c385e577528ec63.tar.bz2 busybox-w32-21a542d7d732735a522c413c0c385e577528ec63.zip |
platform compatibility work (by Dan Fandrich)
Signed-off-by: Dan Fandrich <dan@coneharvesters.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/platform.c')
-rw-r--r-- | libbb/platform.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/libbb/platform.c b/libbb/platform.c new file mode 100644 index 000000000..470185a68 --- /dev/null +++ b/libbb/platform.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * Replacements for common but usually nonstandard functions that aren't | ||
3 | * supplied by all platforms. | ||
4 | * | ||
5 | * Copyright (C) 2009 by Dan Fandrich <dan@coneharvesters.com>, et. al. | ||
6 | * | ||
7 | * Licensed under the GPL version 2, see the file LICENSE in this tarball. | ||
8 | */ | ||
9 | |||
10 | #include "libbb.h" | ||
11 | |||
12 | #ifndef HAVE_STRCHRNUL | ||
13 | char * FAST_FUNC strchrnul(const char *s, int c) | ||
14 | { | ||
15 | while (*s && *s != c) ++s; | ||
16 | return (char*)s; | ||
17 | } | ||
18 | #endif | ||
19 | |||
20 | #ifndef HAVE_VASPRINTF | ||
21 | int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p) | ||
22 | { | ||
23 | int r; | ||
24 | va_list p2; | ||
25 | |||
26 | va_copy(p2, p); | ||
27 | r = vsnprintf(NULL, 0, format, p); | ||
28 | va_end(p); | ||
29 | *string_ptr = xmalloc(r+1); | ||
30 | if (!*string_ptr) | ||
31 | r = -1; | ||
32 | else | ||
33 | r = vsnprintf(*string_ptr, r+1, format, p2); | ||
34 | va_end(p2); | ||
35 | |||
36 | return r; | ||
37 | } | ||
38 | #endif | ||
39 | |||
40 | #ifndef HAVE_FDPRINTF | ||
41 | int fdprintf(int fd, const char *format, ...) | ||
42 | { | ||
43 | va_list p; | ||
44 | int r; | ||
45 | char *string_ptr; | ||
46 | |||
47 | va_start(p, format); | ||
48 | r = vasprintf(&string_ptr, format, p); | ||
49 | va_end(p); | ||
50 | if (r >= 0) { | ||
51 | r = full_write(fd, string_ptr, r); | ||
52 | free(string_ptr); | ||
53 | } | ||
54 | return r; | ||
55 | } | ||
56 | #endif | ||
57 | |||