* 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.
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"
{
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];
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 {
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();
(void)cgetclose();
return (-1);
}
- for(;;) {
+ for (;;) {
if (toprec && !gottoprec) {
gottoprec = 1;
line = toprec;
/*
* Line points to a name line.
*/
- i = 0;
done = 0;
np = nbuf;
for (;;) {