Patch by Joshua R. Elsasser: (ticket #4647)
Fix fgetln() in libbsd to actually return the length of the string. Thanks a bunch! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33315 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -34,6 +34,8 @@ fgetln(FILE *stream, size_t *_length)
|
|||||||
|
|
||||||
line = sBuffer;
|
line = sBuffer;
|
||||||
left = sBufferSize;
|
left = sBufferSize;
|
||||||
|
if (_length != NULL)
|
||||||
|
*_length = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
line = fgets(line, left, stream);
|
line = fgets(line, left, stream);
|
||||||
@@ -44,6 +46,8 @@ fgetln(FILE *stream, size_t *_length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
length = strlen(line);
|
length = strlen(line);
|
||||||
|
if (_length != NULL)
|
||||||
|
*_length += length;
|
||||||
if (line[length - 1] != '\n' && length == sBufferSize - 1) {
|
if (line[length - 1] != '\n' && length == sBufferSize - 1) {
|
||||||
// more data is following, enlarge buffer
|
// more data is following, enlarge buffer
|
||||||
char *newBuffer = realloc(sBuffer, sBufferSize + LINE_LENGTH);
|
char *newBuffer = realloc(sBuffer, sBufferSize + LINE_LENGTH);
|
||||||
|
|||||||
Reference in New Issue
Block a user