]> git.saurik.com Git - apple/libc.git/blobdiff - gen/getcap-fbsd.c
Libc-763.11.tar.gz
[apple/libc.git] / gen / getcap-fbsd.c
index ff74872024a43bdae9dd2ac49aa988bc797ce1a1..ea8425fb99d867d13fe0bf9b50a7ef3f36ae0637 100644 (file)
  * 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 <sys/cdefs.h>
-__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 "xlocale_private.h"
 
@@ -195,7 +191,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];
@@ -257,14 +253,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 {
@@ -651,7 +649,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;
        locale_t loc = __current_locale();
@@ -663,7 +661,7 @@ cgetnext(char **bp, char **db_array)
                (void)cgetclose();
                return (-1);
        }
-       for(;;) {
+       for (;;) {
                if (toprec && !gottoprec) {
                        gottoprec = 1;
                        line = toprec;
@@ -714,7 +712,6 @@ cgetnext(char **bp, char **db_array)
                /*
                 * Line points to a name line.
                 */
-               i = 0;
                done = 0;
                np = nbuf;
                for (;;) {