2 * Copyright 2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
15 #define LINE_LENGTH 4096
19 fgetln(FILE *stream
, size_t *_length
)
21 // TODO: this function is not thread-safe
22 static size_t sBufferSize
;
28 if (sBuffer
== NULL
) {
29 sBuffer
= (char *)malloc(LINE_LENGTH
);
33 sBufferSize
= LINE_LENGTH
;
42 line
= fgets(line
, left
, stream
);
49 length
= strlen(line
);
52 if (line
[length
- 1] != '\n' && length
== sBufferSize
- 1) {
53 // more data is following, enlarge buffer
54 char *newBuffer
= realloc(sBuffer
, sBufferSize
+ LINE_LENGTH
);
55 if (newBuffer
== NULL
) {
62 sBufferSize
+= LINE_LENGTH
;
63 line
= sBuffer
+ length
;