[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.47 and 1.52.8.1

version 1.47, 2006/07/04 03:53:54 version 1.52.8.1, 2014/08/10 06:51:50
Line 52  __RCSID("$NetBSD$");
Line 52  __RCSID("$NetBSD$");
 #include <sys/param.h>  #include <sys/param.h>
   
 #include <assert.h>  #include <assert.h>
   #include <stddef.h>
 #include <ctype.h>  #include <ctype.h>
 #ifndef SMALL  #ifndef SMALL
 #include <db.h>  #include <db.h>
Line 64  __RCSID("$NetBSD$");
Line 65  __RCSID("$NetBSD$");
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
 #ifdef __weak_alias  #if defined(__weak_alias) && !defined(SMALL)
 __weak_alias(cgetcap,_cgetcap)  __weak_alias(cgetcap,_cgetcap)
 __weak_alias(cgetclose,_cgetclose)  __weak_alias(cgetclose,_cgetclose)
 __weak_alias(cgetent,_cgetent)  __weak_alias(cgetent,_cgetent)
Line 75  __weak_alias(cgetnum,_cgetnum)
Line 76  __weak_alias(cgetnum,_cgetnum)
 __weak_alias(cgetset,_cgetset)  __weak_alias(cgetset,_cgetset)
 __weak_alias(cgetstr,_cgetstr)  __weak_alias(cgetstr,_cgetstr)
 __weak_alias(cgetustr,_cgetustr)  __weak_alias(cgetustr,_cgetustr)
   __weak_alias(csetexpandtc,_csetexpandtc)
 #endif  #endif
   
 #define BFRAG           1024  #define BFRAG           1024
Line 90  __weak_alias(cgetustr,_cgetustr)
Line 92  __weak_alias(cgetustr,_cgetustr)
 static size_t    topreclen;     /* toprec length */  static size_t    topreclen;     /* toprec length */
 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       expandtc = 1;  /* flag to expand tc= or not */
   
 #ifndef SMALL  #ifndef SMALL
 static int      cdbget(DB *, char **, const char *);  static int      cdbget(DB *, char **, const char *);
Line 157  cgetset(const char *ent)
Line 160  cgetset(const char *ent)
  * return NULL.   * return NULL.
  */   */
 char *  char *
 cgetcap(buf, cap, type)  cgetcap(char *buf, const char *cap, int type)
         char *buf;  
         const char *cap;  
         int type;  
 {  {
         char *bp;          char *bp;
         const char *cp;          const char *cp;
Line 225  cgetent(char **buf, const char * const *
Line 225  cgetent(char **buf, const char * const *
         return getent(buf, &dummy, db_array, -1, name, 0, NULL);          return getent(buf, &dummy, db_array, -1, name, 0, NULL);
 }  }
   
   void
   csetexpandtc(int etc)
   {
           expandtc = etc;
   }
   
 /*  /*
  * Getent implements the functions of cgetent.  If fd is non-negative,   * Getent implements the functions of cgetent.  If fd is non-negative,
  * *db_array has already been opened and fd is the open file descriptor.  We   * *db_array has already been opened and fd is the open file descriptor.  We
Line 248  static int
Line 254  static int
 getent(char **cap, size_t *len, const char * const *db_array, int fd,  getent(char **cap, size_t *len, const char * const *db_array, int fd,
     const char *name, int depth, char *nfield)      const char *name, int depth, char *nfield)
 {  {
 #ifndef SMALL  
         DB *capdbp;  
         char pbuf[MAXPATHLEN];  
         char *cbuf;  
         int retval;  
         size_t clen;  
 #endif  
         char *record, *newrecord;          char *record, *newrecord;
         char *r_end, *rp;       /* pacify gcc */          char *r_end, *rp;       /* pacify gcc */
         const char * const *db_p;          const char * const *db_p;
Line 316  getent(char **cap, size_t *len, const ch
Line 315  getent(char **cap, size_t *len, const ch
                         (void)lseek(fd, (off_t)0, SEEK_SET);                          (void)lseek(fd, (off_t)0, SEEK_SET);
                 } else {                  } else {
 #ifndef SMALL  #ifndef SMALL
                           DB *capdbp;
                           char pbuf[MAXPATHLEN];
                           char *cbuf;
                           int retval;
                           size_t clen;
   
                         (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 384  getent(char **cap, size_t *len, const ch
Line 389  getent(char **cap, size_t *len, const ch
                         rp = record;                          rp = record;
                         for (;;) {                          for (;;) {
                                 if (bp >= b_end) {                                  if (bp >= b_end) {
                                         int n;                                          ssize_t n;
   
                                         n = read(fd, buf, sizeof(buf));                                          n = read(fd, buf, sizeof(buf));
                                         if (n <= 0) {                                          if (n <= 0) {
Line 447  getent(char **cap, size_t *len, const ch
Line 452  getent(char **cap, size_t *len, const ch
                                  * some more.                                   * some more.
                                  */                                   */
                                 if (rp >= r_end) {                                  if (rp >= r_end) {
                                         u_int pos;                                          ptrdiff_t pos;
                                         size_t newsize;                                          size_t newsize;
   
                                         pos = rp - record;                                          pos = rp - record;
Line 504  getent(char **cap, size_t *len, const ch
Line 509  getent(char **cap, size_t *len, const ch
          * Got the capability record, but now we have to expand all tc=name           * Got the capability record, but now we have to expand all tc=name
          * references in it ...           * references in it ...
          */           */
 tc_exp: {  tc_exp:
           tc_not_resolved = 0;
           if (expandtc) {
                 char *newicap, *s;                  char *newicap, *s;
                 size_t ilen, newilen;                  size_t ilen, newilen;
                 int diff, iret, tclen;                  int iret;
                   ptrdiff_t diff, tclen;
                 char *icap, *scan, *tc, *tcstart, *tcend;                  char *icap, *scan, *tc, *tcstart, *tcend;
   
                 /*                  /*
Line 519  tc_exp: {
Line 527  tc_exp: {
                  *      scanned for tc=name constructs.                   *      scanned for tc=name constructs.
                  */                   */
                 scan = record;                  scan = record;
                 tc_not_resolved = 0;  
                 for (;;) {                  for (;;) {
                         if ((tc = cgetcap(scan, "tc", '=')) == NULL)                          if ((tc = cgetcap(scan, "tc", '=')) == NULL)
                                 break;                                  break;
Line 587  tc_exp: {
Line 594  tc_exp: {
                          */                           */
                         diff = newilen - tclen;                          diff = newilen - tclen;
                         if (diff >= r_end - rp) {                          if (diff >= r_end - rp) {
                                 u_int pos, tcpos, tcposend;                                  ptrdiff_t pos, tcpos, tcposend;
                                 size_t newsize;                                  size_t newsize;
   
                                 pos = rp - record;                                  pos = rp - record;
Line 779  cgetnext(char **bp, const char * const *
Line 786  cgetnext(char **bp, const char * const *
         if (dbp == NULL)          if (dbp == NULL)
                 dbp = db_array;                  dbp = db_array;
   
         if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) {          if (pfp == NULL && (pfp = fopen(*dbp, "re")) == NULL) {
                 (void)cgetclose();                  (void)cgetclose();
                 return -1;                  return -1;
         }          }
Line 802  cgetnext(char **bp, const char * const *
Line 809  cgetnext(char **bp, const char * const *
                                                 (void)cgetclose();                                                  (void)cgetclose();
                                                 return 0;                                                  return 0;
                                         } else if ((pfp =                                          } else if ((pfp =
                                             fopen(*dbp, "r")) == NULL) {                                              fopen(*dbp, "re")) == NULL) {
                                                 (void)cgetclose();                                                  (void)cgetclose();
                                                 return -1;                                                  return -1;
                                         } else                                          } else
Line 907  cgetstr(char *buf, const char *cap, char
Line 914  cgetstr(char *buf, const char *cap, char
         u_int m_room;          u_int m_room;
         const char *bp;          const char *bp;
         char *mp;          char *mp;
         int len;          ptrdiff_t len;
         char *mem, *newmem;          char *mem, *newmem;
   
         _DIAGASSERT(buf != NULL);          _DIAGASSERT(buf != NULL);
Line 1023  cgetstr(char *buf, const char *cap, char
Line 1030  cgetstr(char *buf, const char *cap, char
                 mem = newmem;                  mem = newmem;
         }          }
         *str = mem;          *str = mem;
         return len;          _DIAGASSERT(__type_fit(int, len));
           return (int)len;
 }  }
   
 /*  /*
Line 1042  cgetustr(char *buf, const char *cap, cha
Line 1050  cgetustr(char *buf, const char *cap, cha
         u_int m_room;          u_int m_room;
         const char *bp;          const char *bp;
         char *mp;          char *mp;
         int len;          size_t len;
         char *mem, *newmem;          char *mem, *newmem;
   
         _DIAGASSERT(buf != NULL);          _DIAGASSERT(buf != NULL);
Line 1107  cgetustr(char *buf, const char *cap, cha
Line 1115  cgetustr(char *buf, const char *cap, cha
                 mem = newmem;                  mem = newmem;
         }          }
         *str = mem;          *str = mem;
         return len;          _DIAGASSERT(__type_fit(int, len));
           return (int)len;
 }  }
   
 /*  /*

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.52.8.1

CVSweb <webmaster@jp.NetBSD.org>