Deleted Added
full compact
fgetln.c (126802) fgetln.c (132241)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 24 unchanged lines hidden (view full) ---

33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
39#endif /* LIBC_SCCS and not lint */
40#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 24 unchanged lines hidden (view full) ---

33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
39#endif /* LIBC_SCCS and not lint */
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/lib/libc/stdio/fgetln.c 126802 2004-03-10 09:28:38Z tjr $");
41__FBSDID("$FreeBSD: head/lib/libc/stdio/fgetln.c 132241 2004-07-16 05:52:51Z tjr $");
42
43#include "namespace.h"
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47#include "un-namespace.h"
48#include "libc_private.h"
49#include "local.h"
50
51/*
52 * Expand the line buffer. Return -1 on error.
53#ifdef notdef
54 * The `new size' does not account for a terminating '\0',
55 * so we add 1 here.
56#endif
57 */
42
43#include "namespace.h"
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47#include "un-namespace.h"
48#include "libc_private.h"
49#include "local.h"
50
51/*
52 * Expand the line buffer. Return -1 on error.
53#ifdef notdef
54 * The `new size' does not account for a terminating '\0',
55 * so we add 1 here.
56#endif
57 */
58static int
59slbexpand(FILE *fp, size_t newsize)
58int
59__slbexpand(FILE *fp, size_t newsize)
60{
61 void *p;
62
63#ifdef notdef
64 ++newsize;
65#endif
66 if (fp->_lb._size >= newsize)
67 return (0);

--- 59 unchanged lines hidden (view full) ---

127 for (len = fp->_r, off = 0;; len += fp->_r) {
128 size_t diff;
129
130 /*
131 * Make sure there is room for more bytes. Copy data from
132 * file buffer to line buffer, refill file and look for
133 * newline. The loop stops only when we find a newline.
134 */
60{
61 void *p;
62
63#ifdef notdef
64 ++newsize;
65#endif
66 if (fp->_lb._size >= newsize)
67 return (0);

--- 59 unchanged lines hidden (view full) ---

127 for (len = fp->_r, off = 0;; len += fp->_r) {
128 size_t diff;
129
130 /*
131 * Make sure there is room for more bytes. Copy data from
132 * file buffer to line buffer, refill file and look for
133 * newline. The loop stops only when we find a newline.
134 */
135 if (slbexpand(fp, len + OPTIMISTIC))
135 if (__slbexpand(fp, len + OPTIMISTIC))
136 goto error;
137 (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
138 len - off);
139 off = len;
140 if (__srefill(fp))
141 break; /* EOF or error: return partial line */
142 if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL)
143 continue;
144
145 /* got it: finish up the line (like code above) */
146 p++;
147 diff = p - fp->_p;
148 len += diff;
136 goto error;
137 (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
138 len - off);
139 off = len;
140 if (__srefill(fp))
141 break; /* EOF or error: return partial line */
142 if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL)
143 continue;
144
145 /* got it: finish up the line (like code above) */
146 p++;
147 diff = p - fp->_p;
148 len += diff;
149 if (slbexpand(fp, len))
149 if (__slbexpand(fp, len))
150 goto error;
151 (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
152 diff);
153 fp->_r -= diff;
154 fp->_p = p;
155 break;
156 }
157 *lenp = len;
158#ifdef notdef
159 fp->_lb._base[len] = 0;
160#endif
161 FUNLOCKFILE(fp);
162 return ((char *)fp->_lb._base);
163
164error:
165 *lenp = 0; /* ??? */
166 FUNLOCKFILE(fp);
167 return (NULL); /* ??? */
168}
150 goto error;
151 (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
152 diff);
153 fp->_r -= diff;
154 fp->_p = p;
155 break;
156 }
157 *lenp = len;
158#ifdef notdef
159 fp->_lb._base[len] = 0;
160#endif
161 FUNLOCKFILE(fp);
162 return ((char *)fp->_lb._base);
163
164error:
165 *lenp = 0; /* ??? */
166 FUNLOCKFILE(fp);
167 return (NULL); /* ??? */
168}