fgetln.c (9915c09cf91756410e2e028599e9a7348944e127) | fgetln.c (ce51cf0392a0b2cc80e5ddcdb01394a303093443) |
---|---|
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 --- 21 unchanged lines hidden (view full) --- 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 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) | 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 --- 21 unchanged lines hidden (view full) --- 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 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) |
38#if 0 |
|
38static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; | 39static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; |
40#endif 41static const char rcsid[] = 42 "$Id$"; |
|
39#endif /* LIBC_SCCS and not lint */ 40 41#include <stdio.h> 42#include <stdlib.h> 43#include <string.h> 44#include "local.h" 45 46/* 47 * Expand the line buffer. Return -1 on error. 48#ifdef notdef 49 * The `new size' does not account for a terminating '\0', 50 * so we add 1 here. 51#endif 52 */ | 43#endif /* LIBC_SCCS and not lint */ 44 45#include <stdio.h> 46#include <stdlib.h> 47#include <string.h> 48#include "local.h" 49 50/* 51 * Expand the line buffer. Return -1 on error. 52#ifdef notdef 53 * The `new size' does not account for a terminating '\0', 54 * so we add 1 here. 55#endif 56 */ |
53int __slbexpand(fp, newsize) | 57int 58__slbexpand(fp, newsize) |
54 FILE *fp; 55 size_t newsize; 56{ 57 void *p; 58 59#ifdef notdef 60 ++newsize; 61#endif --- 24 unchanged lines hidden (view full) --- 86 87 /* make sure there is input */ 88 if (fp->_r <= 0 && __srefill(fp)) { 89 *lenp = 0; 90 return (NULL); 91 } 92 93 /* look for a newline in the input */ | 59 FILE *fp; 60 size_t newsize; 61{ 62 void *p; 63 64#ifdef notdef 65 ++newsize; 66#endif --- 24 unchanged lines hidden (view full) --- 91 92 /* make sure there is input */ 93 if (fp->_r <= 0 && __srefill(fp)) { 94 *lenp = 0; 95 return (NULL); 96 } 97 98 /* look for a newline in the input */ |
94 if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) { | 99 if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) { |
95 register char *ret; 96 97 /* 98 * Found one. Flag buffer as modified to keep fseek from 99 * `optimising' a backward seek, in case the user stomps on 100 * the text. 101 */ 102 p++; /* advance over it */ --- 25 unchanged lines hidden (view full) --- 128 */ 129 if (__slbexpand(fp, len + OPTIMISTIC)) 130 goto error; 131 (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, 132 len - off); 133 off = len; 134 if (__srefill(fp)) 135 break; /* EOF or error: return partial line */ | 100 register char *ret; 101 102 /* 103 * Found one. Flag buffer as modified to keep fseek from 104 * `optimising' a backward seek, in case the user stomps on 105 * the text. 106 */ 107 p++; /* advance over it */ --- 25 unchanged lines hidden (view full) --- 133 */ 134 if (__slbexpand(fp, len + OPTIMISTIC)) 135 goto error; 136 (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, 137 len - off); 138 off = len; 139 if (__srefill(fp)) 140 break; /* EOF or error: return partial line */ |
136 if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL) | 141 if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL) |
137 continue; 138 139 /* got it: finish up the line (like code above) */ 140 p++; 141 diff = p - fp->_p; 142 len += diff; 143 if (__slbexpand(fp, len)) 144 goto error; --- 16 unchanged lines hidden --- | 142 continue; 143 144 /* got it: finish up the line (like code above) */ 145 p++; 146 diff = p - fp->_p; 147 len += diff; 148 if (__slbexpand(fp, len)) 149 goto error; --- 16 unchanged lines hidden --- |