Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/getcap.c,v retrieving revision 1.1 retrieving revision 1.1.1.1 diff -u -p -r1.1 -r1.1.1.1 --- src/lib/libc/gen/getcap.c 1993/05/18 07:37:54 1.1 +++ src/lib/libc/gen/getcap.c 1995/02/25 09:11:40 1.1.1.1 @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1992 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Casey Leedom of Lawrence Livermore National Laboratory. @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getcap.c 5.15 (Berkeley) 3/19/93"; +static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #endif /* LIBC_SCCS and not lint */ #include @@ -194,8 +194,8 @@ getent(cap, len, db_array, fd, name, dep DB *capdbp; DBT key, data; register char *r_end, *rp, **db_p; - int myfd, eof, foundit, retval; - char *record; + int myfd, eof, foundit, retval, clen; + char *record, *cbuf; int tc_not_resolved; char pbuf[_POSIX_PATH_MAX]; @@ -250,11 +250,21 @@ getent(cap, len, db_array, fd, name, dep != NULL) { free(record); retval = cdbget(capdbp, &record, name); - if (capdbp->close(capdbp) < 0) + if (retval < 0) { + /* no record available */ + (void)capdbp->close(capdbp); + return (retval); + } + /* save the data; close frees it */ + clen = strlen(record); + cbuf = malloc(clen + 1); + memcpy(cbuf, record, clen + 1); + if (capdbp->close(capdbp) < 0) { + free(cbuf); return (-2); - *len = strlen(record); - *cap = malloc(*len + 1); - memmove(*cap, record, *len + 1); + } + *len = clen; + *cap = cbuf; return (retval); } else { fd = open(*db_p, O_RDONLY, 0); @@ -657,7 +667,7 @@ cgetnext(bp, db_array) gottoprec = 1; line = toprec; } else { - line = fgetline(pfp, &len); + line = fgetln(pfp, &len); if (line == NULL && pfp) { (void)fclose(pfp); if (ferror(pfp)) { @@ -716,7 +726,7 @@ cgetnext(bp, db_array) *np = '\0'; break; } else { /* name field extends beyond the line */ - line = fgetline(pfp, &len); + line = fgetln(pfp, &len); if (line == NULL && pfp) { (void)fclose(pfp); if (ferror(pfp)) {