[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.8 and 1.17

version 1.8, 1994/03/26 02:51:45 version 1.17, 1998/02/26 02:40:11
Line 1 
Line 1 
   /*      $NetBSD$        */
   
 /*-  /*-
  * Copyright (c) 1992 The Regents of the University of California.   * Copyright (c) 1992, 1993
  * All rights reserved.   *      The Regents of the University of California.  All rights reserved.
  *   *
  * This code is derived from software contributed to Berkeley by   * This code is derived from software contributed to Berkeley by
  * Casey Leedom of Lawrence Livermore National Laboratory.   * Casey Leedom of Lawrence Livermore National Laboratory.
Line 34 
Line 36 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)  #if defined(LIBC_SCCS) && !defined(lint)
 /*static char *sccsid = "from: @(#)getcap.c     5.15 (Berkeley) 3/19/93";*/  #if 0
 static char *rcsid = "$Id$";  static char sccsid[] = "@(#)getcap.c    8.3 (Berkeley) 3/25/94";
   #else
   __RCSID("$NetBSD$");
   #endif
 #endif /* LIBC_SCCS and not lint */  #endif /* LIBC_SCCS and not lint */
   
   #include "namespace.h"
 #include <sys/types.h>  #include <sys/types.h>
   
 #include <ctype.h>  #include <ctype.h>
 #include <db.h>  #include <db.h>
 #include <errno.h>  #include <errno.h>
Line 51  static char *rcsid = "$Id$";
Line 57  static char *rcsid = "$Id$";
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
   #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 BFRAG           1024
 #define BSIZE           1024  #define BSIZE           1024
 #define ESC             ('[' & 037)     /* ASCII ESC */  #define ESC             ('[' & 037)     /* ASCII ESC */
Line 91  cgetset(ent)
Line 110  cgetset(ent)
                 return (-1);                  return (-1);
         }          }
         gottoprec = 0;          gottoprec = 0;
         (void)strcpy(toprec, ent);          (void)strcpy(toprec, ent);      /* XXX: strcpy is safe */
         return (0);          return (0);
 }  }
   
Line 112  cgetcap(buf, cap, type)
Line 131  cgetcap(buf, cap, type)
         char *buf, *cap;          char *buf, *cap;
         int type;          int type;
 {  {
         register char *bp, *cp;          char *bp, *cp;
   
         bp = buf;          bp = buf;
         for (;;) {          for (;;) {
Line 189  cgetent(buf, db_array, name)
Line 208  cgetent(buf, db_array, name)
 static int  static int
 getent(cap, len, db_array, fd, name, depth, nfield)  getent(cap, len, db_array, fd, name, depth, nfield)
         char **cap, **db_array, *name, *nfield;          char **cap, **db_array, *name, *nfield;
         u_int *len;          size_t *len;
         int fd, depth;          int fd, depth;
 {  {
         DB *capdbp;          DB *capdbp;
         DBT key, data;          char *r_end, *rp = NULL, **db_p;        /* pacify gcc */
         register char *r_end, *rp, **db_p;          int myfd = 0, eof, foundit, retval;
         int myfd, eof, foundit, retval, clen;          size_t clen;
         char *record, *cbuf;          char *record, *cbuf;
         int tc_not_resolved;          int tc_not_resolved;
         char pbuf[_POSIX_PATH_MAX];          char pbuf[_POSIX_PATH_MAX];
Line 215  getent(cap, len, db_array, fd, name, dep
Line 234  getent(cap, len, db_array, fd, name, dep
                         errno = ENOMEM;                          errno = ENOMEM;
                         return (-2);                          return (-2);
                 }                  }
                 (void)strcpy(record, toprec);                  (void)strcpy(record, toprec);   /* XXX: strcpy is safe */
                 myfd = 0;  
                 db_p = db_array;                  db_p = db_array;
                 rp = record + topreclen + 1;                  rp = record + topreclen + 1;
                 r_end = rp + BFRAG;                  r_end = rp + BFRAG;
Line 243  getent(cap, len, db_array, fd, name, dep
Line 261  getent(cap, len, db_array, fd, name, dep
                  */                   */
   
                 if (fd >= 0) {                  if (fd >= 0) {
                         (void)lseek(fd, (off_t)0, L_SET);                          (void)lseek(fd, (off_t)0, SEEK_SET);
                         myfd = 0;  
                 } else {                  } else {
                         (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))
Line 254  getent(cap, len, db_array, fd, name, dep
Line 271  getent(cap, len, db_array, fd, name, dep
                                 if (retval < 0) {                                  if (retval < 0) {
                                         /* no record available */                                          /* no record available */
                                         (void)capdbp->close(capdbp);                                          (void)capdbp->close(capdbp);
                                         return (retval);                                          return (retval);
                                 }                                  }
                                 /* save the data; close frees it */                                  /* save the data; close frees it */
                                 clen = strlen(record);                                  clen = strlen(record);
Line 271  getent(cap, len, db_array, fd, name, dep
Line 288  getent(cap, len, db_array, fd, name, dep
                                 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. */
                                         if (errno == ENOENT)                                          continue;
                                                 continue;  
                                         free(record);  
                                         return (-2);  
                                 }                                  }
                                 myfd = 1;                                  myfd = 1;
                         }                          }
Line 284  getent(cap, len, db_array, fd, name, dep
Line 298  getent(cap, len, db_array, fd, name, dep
                  */                   */
                 {                  {
                 char buf[BUFSIZ];                  char buf[BUFSIZ];
                 register char *b_end, *bp;                  char *b_end, *bp;
                 register int c;                  int c;
   
                 /*                  /*
                  * Loop invariants:                   * Loop invariants:
Line 395  getent(cap, len, db_array, fd, name, dep
Line 409  getent(cap, len, db_array, fd, name, dep
          * references in it ...           * references in it ...
          */           */
 tc_exp: {  tc_exp: {
                 register char *newicap, *s;                  char *newicap, *s;
                 register int newilen;                  size_t ilen, newilen;
                 u_int ilen;  
                 int diff, iret, tclen;                  int diff, iret, tclen;
                 char *icap, *scan, *tc, *tcstart, *tcend;                  char *icap, *scan, *tc, *tcstart, *tcend;
   
Line 504  tc_exp: {
Line 517  tc_exp: {
                          * Insert tc'ed record into our record.                           * Insert tc'ed record into our record.
                          */                           */
                         s = tcstart + newilen;                          s = tcstart + newilen;
                         bcopy(tcend, s, rp - tcend);                          bcopy(tcend, s, (size_t)(rp - tcend));
                         bcopy(newicap, tcstart, newilen);                          bcopy(newicap, tcstart, newilen);
                         rp += diff;                          rp += diff;
                         free(icap);                          free(icap);
Line 543  cdbget(capdbp, bp, name)
Line 556  cdbget(capdbp, bp, name)
         char **bp, *name;          char **bp, *name;
 {  {
         DBT key, data;          DBT key, data;
         char *buf;  
         int st;  
   
         key.data = name;          key.data = name;
         key.size = strlen(name);          key.size = strlen(name);
Line 578  int
Line 589  int
 cgetmatch(buf, name)  cgetmatch(buf, name)
         char *buf, *name;          char *buf, *name;
 {  {
         register char *np, *bp;          char *np, *bp;
   
         /*          /*
          * Start search at beginning of record.           * Start search at beginning of record.
Line 648  cgetclose()
Line 659  cgetclose()
  */   */
 int  int
 cgetnext(bp, db_array)  cgetnext(bp, db_array)
         register char **bp;          char **bp;
         char **db_array;          char **db_array;
 {  {
         size_t len;          size_t len;
         int status, i, done;          int status, done;
         char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE];          char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE];
         u_int dummy;          u_int dummy;
   
Line 709  cgetnext(bp, db_array)
Line 720  cgetnext(bp, db_array)
                 /*                  /*
                  * Line points to a name line.                   * Line points to a name line.
                  */                   */
                 i = 0;  
                 done = 0;                  done = 0;
                 np = nbuf;                  np = nbuf;
                 for (;;) {                  for (;;) {
Line 739  cgetnext(bp, db_array)
Line 749  cgetnext(bp, db_array)
                         }                          }
                 }                  }
                 rp = buf;                  rp = buf;
                 for(cp = nbuf; *cp != NULL; cp++)                  for(cp = nbuf; *cp != '\0'; cp++)
                         if (*cp == '|' || *cp == ':')                          if (*cp == '|' || *cp == ':')
                                 break;                                  break;
                         else                          else
Line 777  cgetstr(buf, cap, str)
Line 787  cgetstr(buf, cap, str)
         char *buf, *cap;          char *buf, *cap;
         char **str;          char **str;
 {  {
         register u_int m_room;          u_int m_room;
         register char *bp, *mp;          char *bp, *mp;
         int len;          int len;
         char *mem;          char *mem;
   
Line 817  cgetstr(buf, cap, str)
Line 827  cgetstr(buf, cap, str)
                         if (*bp == ':' || *bp == '\0')                          if (*bp == ':' || *bp == '\0')
                                 break;  /* drop unfinished escape */                                  break;  /* drop unfinished escape */
                         if ('0' <= *bp && *bp <= '7') {                          if ('0' <= *bp && *bp <= '7') {
                                 register int n, i;                                  int n, i;
   
                                 n = 0;                                  n = 0;
                                 i = 3;  /* maximum of three octal digits */                                  i = 3;  /* maximum of three octal digits */
Line 901  int
Line 911  int
 cgetustr(buf, cap, str)  cgetustr(buf, cap, str)
         char *buf, *cap, **str;          char *buf, *cap, **str;
 {  {
         register u_int m_room;          u_int m_room;
         register char *bp, *mp;          char *bp, *mp;
         int len;          int len;
         char *mem;          char *mem;
   
Line 971  cgetnum(buf, cap, num)
Line 981  cgetnum(buf, cap, num)
         char *buf, *cap;          char *buf, *cap;
         long *num;          long *num;
 {  {
         register long n;          long n;
         register int base, digit;          int base, digit;
         register char *bp;          char *bp;
   
         /*          /*
          * Find numeric capability cap           * Find numeric capability cap

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.17

CVSweb <webmaster@jp.NetBSD.org>