getdelim.c (189136) | getdelim.c (190773) |
---|---|
1/*- 2 * Copyright (c) 2009 David Schultz <das@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009 David Schultz <das@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/lib/libc/stdio/getdelim.c 189136 2009-02-28 06:00:58Z das $"); | 28__FBSDID("$FreeBSD: head/lib/libc/stdio/getdelim.c 190773 2009-04-06 13:50:04Z das $"); |
29 30#include "namespace.h" 31#include <sys/param.h> 32#include <errno.h> 33#include <limits.h> 34#include <stdio.h> 35#include <stdlib.h> 36#include <string.h> --- 78 unchanged lines hidden (view full) --- 115 FLOCKFILE(fp); 116 ORIENT(fp, -1); 117 118 if (linep == NULL || linecapp == NULL) { 119 errno = EINVAL; 120 goto error; 121 } 122 | 29 30#include "namespace.h" 31#include <sys/param.h> 32#include <errno.h> 33#include <limits.h> 34#include <stdio.h> 35#include <stdlib.h> 36#include <string.h> --- 78 unchanged lines hidden (view full) --- 115 FLOCKFILE(fp); 116 ORIENT(fp, -1); 117 118 if (linep == NULL || linecapp == NULL) { 119 errno = EINVAL; 120 goto error; 121 } 122 |
123 linelen = 0; | |
124 if (*linecapp == 0) 125 *linep = NULL; 126 127 if (fp->_r <= 0 && __srefill(fp)) { 128 /* If fp is at EOF already, we just need space for the NUL. */ 129 if (__sferror(fp) || expandtofit(linep, 1, linecapp)) 130 goto error; | 123 if (*linecapp == 0) 124 *linep = NULL; 125 126 if (fp->_r <= 0 && __srefill(fp)) { 127 /* If fp is at EOF already, we just need space for the NUL. */ 128 if (__sferror(fp) || expandtofit(linep, 1, linecapp)) 129 goto error; |
131 goto done; | 130 FUNLOCKFILE(fp); 131 (*linep)[0] = '\0'; 132 return (-1); |
132 } 133 | 133 } 134 |
135 linelen = 0; |
|
134 while ((endp = memchr(fp->_p, delim, fp->_r)) == NULL) { 135 if (sappend(linep, &linelen, linecapp, fp->_p, fp->_r)) 136 goto error; 137 if (__srefill(fp)) { 138 if (__sferror(fp)) 139 goto error; 140 goto done; /* hit EOF */ 141 } --- 17 unchanged lines hidden --- | 136 while ((endp = memchr(fp->_p, delim, fp->_r)) == NULL) { 137 if (sappend(linep, &linelen, linecapp, fp->_p, fp->_r)) 138 goto error; 139 if (__srefill(fp)) { 140 if (__sferror(fp)) 141 goto error; 142 goto done; /* hit EOF */ 143 } --- 17 unchanged lines hidden --- |