[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.48 and 1.56

version 1.48, 2008/02/02 20:56:46 version 1.56, 2014/09/24 13:18:52
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 159  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 256  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 324  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 (expandtc &&                          if ((capdbp = dbopen(pbuf, O_RDONLY | O_CLOEXEC, 0,
                             (capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))                              DB_HASH, 0)) != NULL) {
                              != NULL) {  
                                 free(record);                                  free(record);
                                 retval = cdbget(capdbp, &record, name);                                  retval = cdbget(capdbp, &record, name);
                                 if (retval < 0) {                                  if (retval < 0) {
Line 356  getent(char **cap, size_t *len, const ch
Line 352  getent(char **cap, size_t *len, const ch
                         } else                          } else
 #endif  #endif
                         {                          {
                                 fd = open(*db_p, O_RDONLY, 0);                                  fd = open(*db_p, O_RDONLY | O_CLOEXEC, 0);
                                 if (fd < 0) {                                  if (fd < 0) {
                                         /* No error on unfound file. */                                          /* No error on unfound file. */
                                         continue;                                          continue;
Line 393  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 456  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 518  tc_exp:
Line 514  tc_exp:
         if (expandtc) {          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 597  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 789  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 812  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 917  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 1033  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 1052  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 1117  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.48  
changed lines
  Added in v.1.56

CVSweb <webmaster@jp.NetBSD.org>