fix printf warning
[oweals/busybox.git] / libbb / get_line_from_file.c
index 5af89893403abba70de97563592a01114093927c..a27edc3bd96e973cd9e41772a51ee43fb2a3a2c3 100644 (file)
@@ -2,8 +2,8 @@
 /*
  * Utility routines.
  *
- * Copyright (C) many different people.  If you wrote this, please
- * acknowledge your work.
+ * Copyright (C) many different people.
+ * If you wrote this, please acknowledge your work.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,18 +40,18 @@ static char *private_get_line_from_file(FILE *file, int c)
 
        while ((ch = getc(file)) != EOF) {
                /* grow the line buffer as necessary */
-               if (idx > linebufsz-2) {
+               if (idx > linebufsz - 2) {
                        linebuf = xrealloc(linebuf, linebufsz += GROWBY);
                }
                linebuf[idx++] = (char)ch;
-               if (ch == '\n' || ch == '\0') {
+               if (!ch) return linebuf;
+               if (c<2 && ch == '\n') {
                        if (c) {
                                --idx;
                        }
                        break;
                }
        }
-
        if (linebuf) {
                if (ferror(file)) {
                        free(linebuf);
@@ -72,6 +72,11 @@ extern char *bb_get_chomped_line_from_file(FILE *file)
        return private_get_line_from_file(file, 1);
 }
 
+extern char *bb_get_chunk_from_file(FILE *file)
+{
+       return private_get_line_from_file(file, 2);
+}
+
 
 /* END CODE */
 /*