[BACK]Return to getcap.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libc/gen/getcap.c between version 1.35 and 1.46

version 1.35, 2002/04/16 19:07:57 version 1.46, 2006/05/29 21:55:41
Line 15 
Line 15 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    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   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 36 
Line 32 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #if HAVE_NBTOOL_CONFIG_H
   #include "nbtool_config.h"
   #endif
   
 #include <sys/cdefs.h>  #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)  #if defined(LIBC_SCCS) && !defined(lint)
 #if 0  #if 0
Line 45  __RCSID("$NetBSD$");
Line 45  __RCSID("$NetBSD$");
 #endif  #endif
 #endif /* LIBC_SCCS and not lint */  #endif /* LIBC_SCCS and not lint */
   
   #ifndef SMALL
 #include "namespace.h"  #include "namespace.h"
   #endif
 #include <sys/types.h>  #include <sys/types.h>
   #include <sys/param.h>
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
   #ifndef SMALL
 #include <db.h>  #include <db.h>
   #endif
 #include <errno.h>  #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <limits.h>  #include <limits.h>
Line 86  static size_t  topreclen; /* toprec leng
Line 91  static size_t  topreclen; /* toprec leng
 static char     *toprec;        /* Additional record specified by cgetset() */  static char     *toprec;        /* Additional record specified by cgetset() */
 static int       gottoprec;     /* Flag indicating retrieval of toprecord */  static int       gottoprec;     /* Flag indicating retrieval of toprecord */
   
 static int      cdbget __P((DB *, char **, const char *));  #ifndef SMALL
 static int      getent __P((char **, size_t *, char **, int, const char *, int, char *));  static int      cdbget(DB *, char **, const char *);
 static int      nfcmp __P((char *, char *));  #endif
   static int      getent(char **, size_t *, const char * const *, int,
       const char *, int, char *);
   static int      nfcmp(char *, char *);
   
 /*  /*
  * Cgetset() allows the addition of a user specified buffer to be added   * Cgetset() allows the addition of a user specified buffer to be added
Line 96  static int nfcmp __P((char *, char *));
Line 104  static int nfcmp __P((char *, char *));
  * virtual database. 0 is returned on success, -1 on failure.   * virtual database. 0 is returned on success, -1 on failure.
  */   */
 int  int
 cgetset(ent)  cgetset(const char *ent)
         const char *ent;  
 {  {
         const char *source, *check;          const char *source, *check;
         char *dest;          char *dest;
Line 206  cgetcap(buf, cap, type)
Line 213  cgetcap(buf, cap, type)
  * encountered (couldn't open/read a file, etc.), and -3 if a potential   * encountered (couldn't open/read a file, etc.), and -3 if a potential
  * reference loop is detected.   * reference loop is detected.
  */   */
   /* coverity[+alloc : arg-*0] */
 int  int
 cgetent(buf, db_array, name)  cgetent(char **buf, const char * const *db_array, const char *name)
         char **buf, **db_array;  
         const char *name;  
 {  {
         size_t dummy;          size_t dummy;
   
Line 238  cgetent(buf, db_array, name)
Line 244  cgetent(buf, db_array, name)
  *        names interpolated, a name can't be found, or depth exceeds   *        names interpolated, a name can't be found, or depth exceeds
  *        MAX_RECURSION.   *        MAX_RECURSION.
  */   */
   /* coverity[+alloc : arg-*0] */
 static int  static int
 getent(cap, len, db_array, fd, name, depth, nfield)  getent(char **cap, size_t *len, const char * const *db_array, int fd,
         char **cap, **db_array, *nfield;      const char *name, int depth, char *nfield)
         const char *name;  
         size_t *len;  
         int fd, depth;  
 {  {
   #ifndef SMALL
         DB *capdbp;          DB *capdbp;
         char *r_end, *rp = NULL, **db_p;        /* pacify gcc */          char pbuf[MAXPATHLEN];
         int myfd = 0, eof, foundit, retval;          char *cbuf;
           int retval;
         size_t clen;          size_t clen;
         char *record, *cbuf, *newrecord;  #endif
           char *record, *newrecord;
           char *r_end, *rp = NULL;        /* pacify gcc */
           const char * const *db_p;
           int myfd = 0, eof, foundit;
         int tc_not_resolved;          int tc_not_resolved;
         char pbuf[_POSIX_PATH_MAX];  
   
         _DIAGASSERT(cap != NULL);          _DIAGASSERT(cap != NULL);
         _DIAGASSERT(len != NULL);          _DIAGASSERT(len != NULL);
Line 304  getent(cap, len, db_array, fd, name, dep
Line 313  getent(cap, len, db_array, fd, name, dep
                 if (fd >= 0) {                  if (fd >= 0) {
                         (void)lseek(fd, (off_t)0, SEEK_SET);                          (void)lseek(fd, (off_t)0, SEEK_SET);
                 } else {                  } else {
   #ifndef SMALL
                         (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);                          (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
                         if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))                          if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))
                              != NULL) {                               != NULL) {
Line 316  getent(cap, len, db_array, fd, name, dep
Line 326  getent(cap, len, db_array, fd, name, dep
                                 }                                  }
                                 /* save the data; close frees it */                                  /* save the data; close frees it */
                                 clen = strlen(record);                                  clen = strlen(record);
                                 cbuf = malloc(clen + 1);                                  if ((cbuf = malloc(clen + 1)) == NULL) {
                                           (void)capdbp->close(capdbp);
                                           errno = ENOMEM;
                                           return (-2);
                                   }
                                 memmove(cbuf, record, clen + 1);                                  memmove(cbuf, record, clen + 1);
                                 if (capdbp->close(capdbp) < 0) {                                  if (capdbp->close(capdbp) < 0) {
                                         int serrno = errno;                                          int serrno = errno;
Line 328  getent(cap, len, db_array, fd, name, dep
Line 342  getent(cap, len, db_array, fd, name, dep
                                 *len = clen;                                  *len = clen;
                                 *cap = cbuf;                                  *cap = cbuf;
                                 return (retval);                                  return (retval);
                         } else {                          } else
   #endif
                           {
                                 fd = open(*db_p, O_RDONLY, 0);                                  fd = open(*db_p, O_RDONLY, 0);
                                 if (fd < 0) {                                  if (fd < 0) {
                                         /* No error on unfound file. */                                          /* No error on unfound file. */
Line 635  tc_exp: {
Line 651  tc_exp: {
         return (0);          return (0);
 }  }
   
   #ifndef SMALL
 static int  static int
 cdbget(capdbp, bp, name)  cdbget(DB *capdbp, char **bp, const char *name)
         DB *capdbp;  
         char **bp;  
         const char *name;  
 {  {
         DBT key;          DBT key;
         DBT data;          DBT data;
Line 648  cdbget(capdbp, bp, name)
Line 662  cdbget(capdbp, bp, name)
         _DIAGASSERT(bp != NULL);          _DIAGASSERT(bp != NULL);
         _DIAGASSERT(name != NULL);          _DIAGASSERT(name != NULL);
   
         /* LINTED key is not modified */          key.data = __UNCONST(name);
         key.data = (char *)name;  
         key.size = strlen(name);          key.size = strlen(name);
   
         for (;;) {          for (;;) {
Line 672  cdbget(capdbp, bp, name)
Line 685  cdbget(capdbp, bp, name)
         *bp = (char *)data.data + 1;          *bp = (char *)data.data + 1;
         return (((char *)(data.data))[0] == TCERR ? 1 : 0);          return (((char *)(data.data))[0] == TCERR ? 1 : 0);
 }  }
   #endif
   
 /*  /*
  * Cgetmatch will return 0 if name is one of the names of the capability   * Cgetmatch will return 0 if name is one of the names of the capability
  * record buf, -1 if not.   * record buf, -1 if not.
  */   */
 int  int
 cgetmatch(buf, name)  cgetmatch(const char *buf, const char *name)
         const char *buf, *name;  
 {  {
         const char *np, *bp;          const char *np, *bp;
   
Line 722  cgetmatch(buf, name)
Line 735  cgetmatch(buf, name)
 }  }
   
 int  int
 cgetfirst(buf, db_array)  cgetfirst(char **buf, const char * const *db_array)
         char **buf, **db_array;  
 {  {
   
         _DIAGASSERT(buf != NULL);          _DIAGASSERT(buf != NULL);
Line 735  cgetfirst(buf, db_array)
Line 747  cgetfirst(buf, db_array)
   
 static FILE *pfp;  static FILE *pfp;
 static int slash;  static int slash;
 static char **dbp;  static const char * const *dbp;
   
 int  int
 cgetclose()  cgetclose(void)
 {  {
         if (pfp != NULL) {          if (pfp != NULL) {
                 (void)fclose(pfp);                  (void)fclose(pfp);
Line 755  cgetclose()
Line 767  cgetclose()
  * specified by db_array.  It returns 0 upon completion of the database, 1   * specified by db_array.  It returns 0 upon completion of the database, 1
  * upon returning an entry with more remaining, and -1 if an error occurs.   * upon returning an entry with more remaining, and -1 if an error occurs.
  */   */
   /* coverity[+alloc : arg-*0] */
 int  int
 cgetnext(bp, db_array)  cgetnext(char **bp, const char * const *db_array)
         char **bp;  
         char **db_array;  
 {  {
         size_t len;          size_t len = 0;
         int status, done;          int status, done;
         char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE];          char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE];
         size_t dummy;          size_t dummy;
Line 781  cgetnext(bp, db_array)
Line 792  cgetnext(bp, db_array)
                         line = toprec;                          line = toprec;
                 } else {                  } else {
                         line = fgetln(pfp, &len);                          line = fgetln(pfp, &len);
                         if (line == NULL && pfp) {                          if (line == NULL) {
                                   if (pfp == NULL)
                                           return -1;
                                 if (ferror(pfp)) {                                  if (ferror(pfp)) {
                                         (void)cgetclose();                                          (void)cgetclose();
                                         return (-1);                                          return (-1);
Line 892  cgetnext(bp, db_array)
Line 905  cgetnext(bp, db_array)
  * allocation failure).   * allocation failure).
  */   */
 int  int
 cgetstr(buf, cap, str)  cgetstr(char *buf, const char *cap, char **str)
         char *buf;  
         const char *cap;  
         char **str;  
 {  {
         u_int m_room;          u_int m_room;
         const char *bp;          const char *bp;
Line 1030  cgetstr(buf, cap, str)
Line 1040  cgetstr(buf, cap, str)
  * error was encountered (storage allocation failure).   * error was encountered (storage allocation failure).
  */   */
 int  int
 cgetustr(buf, cap, str)  cgetustr(char *buf, const char *cap, char **str)
         char *buf;  
         const char *cap;  
         char **str;  
 {  {
         u_int m_room;          u_int m_room;
         const char *bp;          const char *bp;
Line 1113  cgetustr(buf, cap, str)
Line 1120  cgetustr(buf, cap, str)
  * numeric capability couldn't be found.   * numeric capability couldn't be found.
  */   */
 int  int
 cgetnum(buf, cap, num)  cgetnum(char *buf, const char *cap, long *num)
         char *buf;  
         const char *cap;  
         long *num;  
 {  {
         long n;          long n;
         int base, digit;          int base, digit;
Line 1182  cgetnum(buf, cap, num)
Line 1186  cgetnum(buf, cap, num)
  * Compare name field of record.   * Compare name field of record.
  */   */
 static int  static int
 nfcmp(nf, rec)  nfcmp(char *nf, char *rec)
         char *nf, *rec;  
 {  {
         char *cp, tmp;          char *cp, tmp;
         int ret;          int ret;

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.46

CVSweb <webmaster@jp.NetBSD.org>