diff options
author | Timo Teras <timo.teras@iki.fi> | 2011-06-29 02:19:58 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-06-29 02:19:58 +0200 |
commit | 0a5b310067abfde9bf74a42352fc421e1c27e2b9 (patch) | |
tree | ae491b7ba5150035850c7e535a16060ce63735d1 | |
parent | b9ba580917b59e4770ba99db7c61288f2476eb61 (diff) | |
download | busybox-w32-0a5b310067abfde9bf74a42352fc421e1c27e2b9.tar.gz busybox-w32-0a5b310067abfde9bf74a42352fc421e1c27e2b9.tar.bz2 busybox-w32-0a5b310067abfde9bf74a42352fc421e1c27e2b9.zip |
platform.c: provide getline implementation
Signed-off-by: Timo Teras <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/platform.h | 5 | ||||
-rw-r--r-- | libbb/platform.c | 29 |
2 files changed, 34 insertions, 0 deletions
diff --git a/include/platform.h b/include/platform.h index cbe85f469..eafc3fcfe 100644 --- a/include/platform.h +++ b/include/platform.h | |||
@@ -350,6 +350,7 @@ typedef unsigned smalluint; | |||
350 | #define HAVE_STRSIGNAL 1 | 350 | #define HAVE_STRSIGNAL 1 |
351 | #define HAVE_STRVERSCMP 1 | 351 | #define HAVE_STRVERSCMP 1 |
352 | #define HAVE_VASPRINTF 1 | 352 | #define HAVE_VASPRINTF 1 |
353 | #define HAVE_GETLINE 1 | ||
353 | #define HAVE_XTABS 1 | 354 | #define HAVE_XTABS 1 |
354 | #define HAVE_MNTENT_H 1 | 355 | #define HAVE_MNTENT_H 1 |
355 | #define HAVE_NET_ETHERNET_H 1 | 356 | #define HAVE_NET_ETHERNET_H 1 |
@@ -470,4 +471,8 @@ extern char *strsep(char **stringp, const char *delim) FAST_FUNC; | |||
470 | extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; | 471 | extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; |
471 | #endif | 472 | #endif |
472 | 473 | ||
474 | #ifndef HAVE_GETLINE | ||
475 | extern ssize_t getline(char **lineptr, size_t *n, FILE *stream) FAST_FUNC; | ||
476 | #endif | ||
477 | |||
473 | #endif | 478 | #endif |
diff --git a/libbb/platform.c b/libbb/platform.c index 04b8961de..2bf34f5bc 100644 --- a/libbb/platform.c +++ b/libbb/platform.c | |||
@@ -145,3 +145,32 @@ char* FAST_FUNC stpcpy(char *p, const char *to_add) | |||
145 | return p; | 145 | return p; |
146 | } | 146 | } |
147 | #endif | 147 | #endif |
148 | |||
149 | #ifndef HAVE_GETLINE | ||
150 | ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) | ||
151 | { | ||
152 | int ch; | ||
153 | char *line = *lineptr; | ||
154 | size_t alloced = *n; | ||
155 | size_t len = 0; | ||
156 | |||
157 | do { | ||
158 | ch = fgetc(stream); | ||
159 | if (ch == EOF) | ||
160 | break; | ||
161 | if (len + 1 >= alloced) { | ||
162 | alloced += alloced/4 + 64; | ||
163 | line = xrealloc(line, alloced); | ||
164 | } | ||
165 | line[len++] = ch; | ||
166 | } while (ch != '\n'); | ||
167 | |||
168 | if (len == 0) | ||
169 | return -1; | ||
170 | |||
171 | line[len] = '\0'; | ||
172 | *lineptr = line; | ||
173 | *n = alloced; | ||
174 | return len; | ||
175 | } | ||
176 | #endif | ||