Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/fgets_str.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/fgets_str.c
r821 r1770 6 6 * If you wrote this, please acknowledge your work. 7 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 21 9 */ 22 23 24 #include <stdio.h>25 #include <stdlib.h>26 #include <string.h>27 10 28 11 #include "libbb.h" … … 31 14 * Return NULL on EOF. */ 32 15 33 char * fgets_str(FILE *file, const char *terminating_string)16 char *xmalloc_fgets_str(FILE *file, const char *terminating_string) 34 17 { 35 18 char *linebuf = NULL; … … 49 32 /* grow the line buffer as necessary */ 50 33 while (idx > linebufsz - 2) { 51 linebuf = xrealloc(linebuf, linebufsz += 1000); 34 linebufsz += 200; 35 linebuf = xrealloc(linebuf, linebufsz); 52 36 } 53 37 … … 57 41 /* Check for terminating string */ 58 42 end_string_offset = idx - term_length; 59 if ((end_string_offset > 0) && (memcmp(&linebuf[end_string_offset], terminating_string, term_length) == 0)) { 43 if (end_string_offset > 0 44 && memcmp(&linebuf[end_string_offset], terminating_string, term_length) == 0 45 ) { 60 46 idx -= term_length; 61 47 break; 62 48 } 63 49 } 50 linebuf = xrealloc(linebuf, idx + 1); 64 51 linebuf[idx] = '\0'; 65 return (linebuf);52 return linebuf; 66 53 } 67
Note:
See TracChangeset
for help on using the changeset viewer.