getdelim.c (1829d5da5355930d5cfa8ec8add8ff47dc0bebab) | getdelim.c (6685ac34d91d361a03918777934cf037bedd8841) |
---|---|
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 --- 106 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 | 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 --- 106 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 --- |