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 rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/gen/getcap.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.7 retrieving revision 1.14 diff -u -p -r1.7 -r1.14 --- src/lib/libc/gen/getcap.c 1994/03/06 07:54:35 1.7 +++ src/lib/libc/gen/getcap.c 1997/07/21 14:07:03 1.14 @@ -1,6 +1,8 @@ +/* $NetBSD: getcap.c,v 1.14 1997/07/21 14:07:03 jtc Exp $ */ + /*- - * 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. @@ -34,13 +36,17 @@ * SUCH DAMAGE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) -/*static char *sccsid = "from: @(#)getcap.c 5.15 (Berkeley) 3/19/93";*/ -static char *rcsid = "$Id: getcap.c,v 1.7 1994/03/06 07:54:35 cgd Exp $"; +#if 0 +static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; +#else +__RCSID("$NetBSD: getcap.c,v 1.14 1997/07/21 14:07:03 jtc Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include - #include #include #include @@ -51,6 +57,19 @@ static char *rcsid = "$Id: getcap.c,v 1. #include #include +#ifdef __weak_alias +__weak_alias(cgetcap,_cgetcap); +__weak_alias(cgetclose,_cgetclose); +__weak_alias(cgetent,_cgetent); +__weak_alias(cgetfirst,_cgetfirst); +__weak_alias(cgetmatch,_cgetmatch); +__weak_alias(cgetnext,_cgetnext); +__weak_alias(cgetnum,_cgetnum); +__weak_alias(cgetset,_cgetset); +__weak_alias(cgetstr,_cgetstr); +__weak_alias(cgetustr,_cgetustr); +#endif + #define BFRAG 1024 #define BSIZE 1024 #define ESC ('[' & 037) /* ASCII ESC */ @@ -91,7 +110,7 @@ cgetset(ent) return (-1); } gottoprec = 0; - (void)strcpy(toprec, ent); + (void)strcpy(toprec, ent); /* XXX: strcpy is safe */ return (0); } @@ -193,9 +212,8 @@ getent(cap, len, db_array, fd, name, dep int fd, depth; { DB *capdbp; - DBT key, data; - register char *r_end, *rp, **db_p; - int myfd, eof, foundit, retval, clen; + register char *r_end, *rp = NULL, **db_p; /* pacify gcc */ + int myfd = 0, eof, foundit, retval, clen; char *record, *cbuf; int tc_not_resolved; char pbuf[_POSIX_PATH_MAX]; @@ -215,8 +233,7 @@ getent(cap, len, db_array, fd, name, dep errno = ENOMEM; return (-2); } - (void)strcpy(record, toprec); - myfd = 0; + (void)strcpy(record, toprec); /* XXX: strcpy is safe */ db_p = db_array; rp = record + topreclen + 1; r_end = rp + BFRAG; @@ -244,19 +261,21 @@ getent(cap, len, db_array, fd, name, dep if (fd >= 0) { (void)lseek(fd, (off_t)0, L_SET); - myfd = 0; } else { (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) != NULL) { free(record); retval = cdbget(capdbp, &record, name); - clen = strlen(record); - if ((cbuf = malloc(clen + 1)) == NULL) { - errno = ENOMEM; - return (-2); + if (retval < 0) { + /* no record available */ + (void)capdbp->close(capdbp); + return (retval); } - memmove(cbuf, record, clen + 1); + /* 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); @@ -268,10 +287,7 @@ getent(cap, len, db_array, fd, name, dep fd = open(*db_p, O_RDONLY, 0); if (fd < 0) { /* No error on unfound file. */ - if (errno == ENOENT) - continue; - free(record); - return (-2); + continue; } myfd = 1; } @@ -540,8 +556,6 @@ cdbget(capdbp, bp, name) char **bp, *name; { DBT key, data; - char *buf; - int st; key.data = name; key.size = strlen(name); @@ -736,7 +750,7 @@ cgetnext(bp, db_array) } } rp = buf; - for(cp = nbuf; *cp != NULL; cp++) + for(cp = nbuf; *cp != '\0'; cp++) if (*cp == '|' || *cp == ':') break; else