X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..1f2f436a38f7ae2d39a943ad2898d8fed4ed2e58:/gen/FreeBSD/getcap.c diff --git a/gen/FreeBSD/getcap.c b/gen/FreeBSD/getcap.c index 3cf07fa..649a9f4 100644 --- a/gen/FreeBSD/getcap.c +++ b/gen/FreeBSD/getcap.c @@ -13,10 +13,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -38,7 +34,7 @@ static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #endif /* LIBC_SCCS and not lint */ #include -__FBSDID("$FreeBSD: src/lib/libc/gen/getcap.c,v 1.19 2003/01/02 10:19:43 thomas Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/gen/getcap.c,v 1.23 2009/11/25 04:45:45 wollman Exp $"); #include "namespace.h" #include @@ -193,7 +189,7 @@ getent(char **cap, u_int *len, char **db_array, int fd, const char *name, { DB *capdbp; char *r_end, *rp, **db_p; - int myfd, eof, foundit, retval, clen; + int myfd, eof, foundit, retval; char *record, *cbuf; int tc_not_resolved; char pbuf[_POSIX_PATH_MAX]; @@ -255,14 +251,16 @@ getent(char **cap, u_int *len, char **db_array, int fd, const char *name, return (retval); } /* save the data; close frees it */ - clen = strlen(record); - cbuf = malloc(clen + 1); - memcpy(cbuf, record, clen + 1); + cbuf = strdup(record); if (capdbp->close(capdbp) < 0) { free(cbuf); return (-2); } - *len = clen; + if (cbuf == NULL) { + errno = ENOMEM; + return (-2); + } + *len = strlen(cbuf); *cap = cbuf; return (retval); } else { @@ -649,7 +647,7 @@ int cgetnext(char **bp, char **db_array) { size_t len; - int done, hadreaderr, i, savederrno, status; + int done, hadreaderr, savederrno, status; char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; u_int dummy; @@ -660,7 +658,7 @@ cgetnext(char **bp, char **db_array) (void)cgetclose(); return (-1); } - for(;;) { + for (;;) { if (toprec && !gottoprec) { gottoprec = 1; line = toprec; @@ -711,7 +709,6 @@ cgetnext(char **bp, char **db_array) /* * Line points to a name line. */ - i = 0; done = 0; np = nbuf; for (;;) {