projects
/
oweals
/
busybox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a7512d7
)
Return NULL if EOF is encountered before terminating_string.
author
Matt Kraai
<kraai@debian.org>
Thu, 18 Oct 2001 17:04:22 +0000
(17:04 -0000)
committer
Matt Kraai
<kraai@debian.org>
Thu, 18 Oct 2001 17:04:22 +0000
(17:04 -0000)
libbb/fgets_str.c
patch
|
blob
|
history
diff --git
a/libbb/fgets_str.c
b/libbb/fgets_str.c
index 33d8d00ccc3c2d37ab79e55f373e05e16a7e6011..4943464d56a8604f28366de5d9227258165d11dd 100644
(file)
--- a/
libbb/fgets_str.c
+++ b/
libbb/fgets_str.c
@@
-19,11
+19,10
@@
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
-/*
- * Continue reading from file until the terminating string is encountered.
- * Return data as string.
- * e.g. fgets_str(file, "\n"); will read till end of file
- */
+#include "libbb.h"
+
+/* Read up to (and including) TERMINATING_STRING from FILE and return it.
+ * Return NULL on EOF. */
char *fgets_str(FILE *file, const char *terminating_string)
{
char *fgets_str(FILE *file, const char *terminating_string)
{
@@
-37,12
+36,13
@@
char *fgets_str(FILE *file, const char *terminating_string)
while (1) {
ch = fgetc(file);
if (ch == EOF) {
while (1) {
ch = fgetc(file);
if (ch == EOF) {
- break;
+ free(linebuf);
+ return NULL;
}
/* grow the line buffer as necessary */
while (idx > linebufsz - 2) {
}
/* grow the line buffer as necessary */
while (idx > linebufsz - 2) {
- linebuf =
realloc(linebuf, linebufsz += 1000); /* GROWBY */
+ linebuf =
xrealloc(linebuf, linebufsz += 1000);
}
linebuf[idx] = ch;
}
linebuf[idx] = ch;
@@
-55,9
+55,6
@@
char *fgets_str(FILE *file, const char *terminating_string)
break;
}
}
break;
}
}
- if (idx == 0) {
- return NULL;
- }
linebuf[idx] = '\0';
return(linebuf);
}
linebuf[idx] = '\0';
return(linebuf);
}