[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.45 and 1.52.2.1

version 1.45, 2006/04/02 03:26:03 version 1.52.2.1, 2014/08/20 00:02:14
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 110  cgetset(const char *ent)
Line 113  cgetset(const char *ent)
         char *dest;          char *dest;
   
         if (ent == NULL) {          if (ent == NULL) {
                 if (toprec)                  if (toprec != NULL)
                         free(toprec);                          free(toprec);
                 toprec = NULL;                  toprec = NULL;
                 topreclen = 0;                  topreclen = 0;
                 return (0);                  return 0;
         }          }
         topreclen = strlen(ent);          topreclen = strlen(ent);
         if ((toprec = malloc (topreclen + 1)) == NULL) {          if ((toprec = malloc(topreclen + 1)) == NULL) {
                 errno = ENOMEM;                  errno = ENOMEM;
                 return (-1);                  return -1;
         }          }
         gottoprec = 0;          gottoprec = 0;
   
         source=ent;          source = ent;
         dest=toprec;          dest = toprec;
         while (*source) { /* Strip whitespace */          while (*source != '\0') { /* Strip whitespace */
                 *dest++ = *source++; /* Do not check first field */                  *dest++ = *source++; /* Do not check first field */
                 while (*source == ':') {                  while (*source == ':') {
                         check=source+1;                          check = source + 1;
                         while (*check && (isspace((unsigned char)*check) ||                          while (*check && (isspace((unsigned char)*check) ||
                             (*check=='\\' && isspace((unsigned char)check[1]))))                              (*check=='\\' && isspace((unsigned char)check[1]))))
                                 ++check;                                  ++check;
                         if( *check == ':' )                          if (*check == ':')
                                 source=check;                                  source = check;
                         else                          else
                                 break;                                  break;
   
                 }                  }
         }          }
         *dest=0;          *dest = 0;
   
         return (0);          return 0;
 }  }
   
 /*  /*
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 177  cgetcap(buf, cap, type)
Line 177  cgetcap(buf, cap, type)
                  */                   */
                 for (;;)                  for (;;)
                         if (*bp == '\0')                          if (*bp == '\0')
                                 return (NULL);                                  return NULL;
                         else                          else if (*bp++ == ':')
                                 if (*bp++ == ':')                                  break;
                                         break;  
   
                 /*                  /*
                  * Try to match (cap, type) in buf.                   * Try to match (cap, type) in buf.
Line 190  cgetcap(buf, cap, type)
Line 189  cgetcap(buf, cap, type)
                 if (*cp != '\0')                  if (*cp != '\0')
                         continue;                          continue;
                 if (*bp == '@')                  if (*bp == '@')
                         return (NULL);                          return NULL;
                 if (type == ':') {                  if (type == ':') {
                         if (*bp != '\0' && *bp != ':')                          if (*bp != '\0' && *bp != ':')
                                 continue;                                  continue;
                         return(bp);                          return bp;
                 }                  }
                 if (*bp != type)                  if (*bp != type)
                         continue;                          continue;
                 bp++;                  bp++;
                 return (*bp == '@' ? NULL : bp);                  return *bp == '@' ? NULL : bp;
         }          }
         /* NOTREACHED */          /* NOTREACHED */
 }  }
Line 223  cgetent(char **buf, const char * const *
Line 222  cgetent(char **buf, const char * const *
         _DIAGASSERT(db_array != NULL);          _DIAGASSERT(db_array != NULL);
         _DIAGASSERT(name != NULL);          _DIAGASSERT(name != NULL);
   
         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;
 }  }
   
 /*  /*
Line 249  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 = NULL;        /* pacify gcc */          char *r_end, *rp;       /* pacify gcc */
         const char * const *db_p;          const char * const *db_p;
         int myfd = 0, eof, foundit;          int myfd, eof, foundit;
         int tc_not_resolved;          int tc_not_resolved;
   
         _DIAGASSERT(cap != NULL);          _DIAGASSERT(cap != NULL);
Line 269  getent(char **cap, size_t *len, const ch
Line 267  getent(char **cap, size_t *len, const ch
         _DIAGASSERT(name != NULL);          _DIAGASSERT(name != NULL);
         /* nfield may be NULL */          /* nfield may be NULL */
   
           myfd = 0;
           rp = NULL;
   
         /*          /*
          * Return with ``loop detected'' error if we've recursed more than           * Return with ``loop detected'' error if we've recursed more than
          * MAX_RECURSION times.           * MAX_RECURSION times.
          */           */
         if (depth > MAX_RECURSION)          if (depth > MAX_RECURSION)
                 return (-3);                  return -3;
   
         /*          /*
          * Check if we have a top record from cgetset().           * Check if we have a top record from cgetset().
          */           */
         if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) {          if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) {
                 if ((record = malloc (topreclen + BFRAG)) == NULL) {                  if ((record = malloc(topreclen + BFRAG)) == NULL) {
                         errno = ENOMEM;                          errno = ENOMEM;
                         return (-2);                          return -2;
                 }                  }
                 (void)strcpy(record, toprec);   /* XXX: strcpy is safe */                  (void)strcpy(record, toprec);   /* XXX: strcpy is safe */
                 db_p = db_array;                  db_p = db_array;
Line 295  getent(char **cap, size_t *len, const ch
Line 296  getent(char **cap, size_t *len, const ch
          */           */
         if ((record = malloc(BFRAG)) == NULL) {          if ((record = malloc(BFRAG)) == NULL) {
                 errno = ENOMEM;                  errno = ENOMEM;
                 return (-2);                  return -2;
         }          }
         r_end = record + BFRAG;          r_end = record + BFRAG;
         foundit = 0;          foundit = 0;
Line 314  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 322  getent(char **cap, size_t *len, const ch
Line 329  getent(char **cap, size_t *len, const ch
                                 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);
                                 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;
   
                                         free(cbuf);                                          free(cbuf);
                                         errno = serrno;                                          errno = serrno;
                                         return (-2);                                          return -2;
                                 }                                  }
                                 *len = clen;                                  *len = clen;
                                 *cap = cbuf;                                  *cap = cbuf;
                                 return (retval);                                  return retval;
                         } else                          } else
 #endif  #endif
                         {                          {
Line 368  getent(char **cap, size_t *len, const ch
Line 379  getent(char **cap, size_t *len, const ch
                  */                   */
                 b_end = buf;                  b_end = buf;
                 bp = buf;                  bp = buf;
                 cp = 0;                  cp = NULL;
                 slash = 0;                  slash = 0;
                 for (;;) {                  for (;;) {
   
                         /*                          /*
                          * Read in a line implementing (\, newline)                           * Read in a line implementing (\, newline)
                          * line continuation.                           * line continuation.
Line 379  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 390  getent(char **cap, size_t *len, const ch
Line 400  getent(char **cap, size_t *len, const ch
   
                                                         free(record);                                                          free(record);
                                                         errno = serrno;                                                          errno = serrno;
                                                         return (-2);                                                          return -2;
                                                 } else {                                                  } else {
                                                         fd = -1;                                                          fd = -1;
                                                         eof = 1;                                                          eof = 1;
Line 421  getent(char **cap, size_t *len, const ch
Line 431  getent(char **cap, size_t *len, const ch
                                          * to the colon (eliminating the                                           * to the colon (eliminating the
                                          * field).                                           * field).
                                          */                                           */
                                         if (cp)                                          if (cp != NULL)
                                                 rp = cp;                                                  rp = cp;
                                         else                                          else
                                                 cp = rp;                                                  cp = rp;
Line 442  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 453  getent(char **cap, size_t *len, const ch
Line 463  getent(char **cap, size_t *len, const ch
                                                 if (myfd)                                                  if (myfd)
                                                         (void)close(fd);                                                          (void)close(fd);
                                                 errno = ENOMEM;                                                  errno = ENOMEM;
                                                 return (-2);                                                  return -2;
                                         }                                          }
                                         record = newrecord;                                          record = newrecord;
                                         r_end = record + newsize;                                          r_end = record + newsize;
Line 481  getent(char **cap, size_t *len, const ch
Line 491  getent(char **cap, size_t *len, const ch
                         /*                          /*
                          * See if this is the record we want ...                           * See if this is the record we want ...
                          */                           */
                         if (cgetmatch(record, name) == 0) {                          if (cgetmatch(record, name) == 0)
                                 if (nfield == NULL || !nfcmp(nfield, record)) {                                  if (nfield == NULL || !nfcmp(nfield, record)) {
                                         foundit = 1;                                          foundit = 1;
                                         break;  /* found it! */                                          break;  /* found it! */
                                 }                                  }
                         }  
                 }                  }
         }                  }
                 if (foundit)                  if (foundit)
                         break;                          break;
         }          }
   
         if (!foundit)          if (!foundit)
                 return (-1);                  return -1;
   
         /*          /*
          * 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 515  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 547  tc_exp: {
Line 558  tc_exp: {
                                         if (myfd)                                          if (myfd)
                                                 (void)close(fd);                                                  (void)close(fd);
                                         free(record);                                          free(record);
                                         return (iret);                                          return iret;
                                 }                                  }
                                 if (iret == 1)                                  if (iret == 1)
                                         tc_not_resolved = 1;                                          tc_not_resolved = 1;
Line 565  tc_exp: {
Line 576  tc_exp: {
                         for (;;)                          for (;;)
                                 if (*s == '\0')                                  if (*s == '\0')
                                         break;                                          break;
                                 else                                  else if (*s++ == ':')
                                         if (*s++ == ':')                                          break;
                                                 break;  
                         newilen -= s - newicap;                          newilen -= s - newicap;
                         newicap = s;                          newicap = s;
   
                         /* make sure interpolated record is `:'-terminated */                          /* make sure interpolated record is `:'-terminated */
                         s += newilen;                          s += newilen;
                         if (*(s-1) != ':') {                          if (*(s - 1) != ':') {
                                 *s = ':';       /* overwrite NUL with : */                                  *s = ':';       /* overwrite NUL with : */
                                 newilen++;                                  newilen++;
                         }                          }
Line 584  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 598  tc_exp: {
Line 608  tc_exp: {
                                                 (void)close(fd);                                                  (void)close(fd);
                                         free(icap);                                          free(icap);
                                         errno = ENOMEM;                                          errno = ENOMEM;
                                         return (-2);                                          return -2;
                                 }                                  }
                                 record = newrecord;                                  record = newrecord;
                                 r_end = record + newsize;                                  r_end = record + newsize;
Line 620  tc_exp: {
Line 630  tc_exp: {
                          * Start scan on `:' so next cgetcap works properly                           * Start scan on `:' so next cgetcap works properly
                          * (cgetcap always skips first field).                           * (cgetcap always skips first field).
                          */                           */
                         scan = s-1;                          scan = s - 1;
                 }                  }
   
         }          }
Line 636  tc_exp: {
Line 646  tc_exp: {
                      realloc(record, (size_t)(rp - record))) == NULL) {                       realloc(record, (size_t)(rp - record))) == NULL) {
                         free(record);                          free(record);
                         errno = ENOMEM;                          errno = ENOMEM;
                         return (-2);                          return -2;
                 }                  }
                 record = newrecord;                  record = newrecord;
         }          }
   
         *cap = record;          *cap = record;
         if (tc_not_resolved)          if (tc_not_resolved)
                 return (1);                  return 1;
         return (0);          return 0;
 }  }
   
 #ifndef SMALL  #ifndef SMALL
Line 665  cdbget(DB *capdbp, char **bp, const char
Line 675  cdbget(DB *capdbp, char **bp, const char
                 /* Get the reference. */                  /* Get the reference. */
                 switch(capdbp->get(capdbp, &key, &data, 0)) {                  switch(capdbp->get(capdbp, &key, &data, 0)) {
                 case -1:                  case -1:
                         return (-2);                          return -2;
                 case 1:                  case 1:
                         return (-1);                          return -1;
                 }                  }
   
                 /* If not an index to another record, leave. */                  /* If not an index to another record, leave. */
Line 679  cdbget(DB *capdbp, char **bp, const char
Line 689  cdbget(DB *capdbp, char **bp, const char
         }          }
   
         *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  #endif
   
Line 707  cgetmatch(const char *buf, const char *n
Line 717  cgetmatch(const char *buf, const char *n
                 for (;;)                  for (;;)
                         if (*np == '\0') {                          if (*np == '\0') {
                                 if (*bp == '|' || *bp == ':' || *bp == '\0')                                  if (*bp == '|' || *bp == ':' || *bp == '\0')
                                         return (0);                                          return 0;
                                 else                                  else
                                         break;                                          break;
                         } else                          } else if (*bp++ != *np++)
                                 if (*bp++ != *np++)                                  break;
                                         break;  
   
                 /*                  /*
                  * Match failed, skip to next name in record.                   * Match failed, skip to next name in record.
Line 720  cgetmatch(const char *buf, const char *n
Line 729  cgetmatch(const char *buf, const char *n
                 if (bp > buf)                  if (bp > buf)
                         bp--;   /* a '|' or ':' may have stopped the match */                          bp--;   /* a '|' or ':' may have stopped the match */
                 else                  else
                         return (-1);                          return -1;
                 for (;;)                  for (;;)
                         if (*bp == '\0' || *bp == ':')                          if (*bp == '\0' || *bp == ':')
                                 return (-1);    /* match failed totally */                                  return -1;      /* match failed totally */
                         else                          else if (*bp++ == '|')
                                 if (*bp++ == '|')                                  break;          /* found next name */
                                         break;  /* found next name */  
         }          }
 }  }
   
Line 738  cgetfirst(char **buf, const char * const
Line 746  cgetfirst(char **buf, const char * const
         _DIAGASSERT(db_array != NULL);          _DIAGASSERT(db_array != NULL);
   
         (void)cgetclose();          (void)cgetclose();
         return (cgetnext(buf, db_array));          return cgetnext(buf, db_array);
 }  }
   
 static FILE *pfp;  static FILE *pfp;
Line 755  cgetclose(void)
Line 763  cgetclose(void)
         dbp = NULL;          dbp = NULL;
         gottoprec = 0;          gottoprec = 0;
         slash = 0;          slash = 0;
         return(0);          return 0;
 }  }
   
 /*  /*
Line 778  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;
         }          }
         for(;;) {          for (;;) {
                 if (toprec && !gottoprec) {                  if (toprec != NULL && !gottoprec) {
                         gottoprec = 1;                          gottoprec = 1;
                         line = toprec;                          line = toprec;
                 } else {                  } else {
Line 793  cgetnext(char **bp, const char * const *
Line 801  cgetnext(char **bp, const char * const *
                                         return -1;                                          return -1;
                                 if (ferror(pfp)) {                                  if (ferror(pfp)) {
                                         (void)cgetclose();                                          (void)cgetclose();
                                         return (-1);                                          return -1;
                                 } else {                                  } else {
                                         (void)fclose(pfp);                                          (void)fclose(pfp);
                                         pfp = NULL;                                          pfp = NULL;
                                         if (*++dbp == NULL) {                                          if (*++dbp == NULL) {
                                                 (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
                                                 continue;                                                  continue;
                                 }                                  }
Line 854  cgetnext(char **bp, const char * const *
Line 862  cgetnext(char **bp, const char * const *
                                 if (line == NULL && pfp) {                                  if (line == NULL && pfp) {
                                         if (ferror(pfp)) {                                          if (ferror(pfp)) {
                                                 (void)cgetclose();                                                  (void)cgetclose();
                                                 return (-1);                                                  return -1;
                                         }                                          }
                                         (void)fclose(pfp);                                          (void)fclose(pfp);
                                         pfp = NULL;                                          pfp = NULL;
Line 867  cgetnext(char **bp, const char * const *
Line 875  cgetnext(char **bp, const char * const *
                 if (len > sizeof(buf))                  if (len > sizeof(buf))
                         return -1;                          return -1;
                 rp = buf;                  rp = buf;
                 for(cp = nbuf; *cp != '\0'; cp++)                  for (cp = nbuf; *cp != '\0'; cp++)
                         if (*cp == '|' || *cp == ':')                          if (*cp == '|' || *cp == ':')
                                 break;                                  break;
                         else                          else
Line 886  cgetnext(char **bp, const char * const *
Line 894  cgetnext(char **bp, const char * const *
                 if (status == -2 || status == -3)                  if (status == -2 || status == -3)
                         (void)cgetclose();                          (void)cgetclose();
   
                 return (status + 1);                  return status + 1;
         }          }
         /* NOTREACHED */          /* NOTREACHED */
 }  }
Line 906  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 918  cgetstr(char *buf, const char *cap, char
Line 926  cgetstr(char *buf, const char *cap, char
          */           */
         bp = cgetcap(buf, cap, '=');          bp = cgetcap(buf, cap, '=');
         if (bp == NULL)          if (bp == NULL)
                 return (-1);                  return -1;
   
         /*          /*
          * Conversion / storage allocation loop ...  Allocate memory in           * Conversion / storage allocation loop ...  Allocate memory in
Line 926  cgetstr(char *buf, const char *cap, char
Line 934  cgetstr(char *buf, const char *cap, char
          */           */
         if ((mem = malloc(SFRAG)) == NULL) {          if ((mem = malloc(SFRAG)) == NULL) {
                 errno = ENOMEM;                  errno = ENOMEM;
                 return (-2);    /* couldn't even allocate the first fragment */                  return -2;      /* couldn't even allocate the first fragment */
         }          }
         m_room = SFRAG;          m_room = SFRAG;
         mp = mem;          mp = mem;
Line 1000  cgetstr(char *buf, const char *cap, char
Line 1008  cgetstr(char *buf, const char *cap, char
   
                         if ((newmem = realloc(mem, size + SFRAG)) == NULL) {                          if ((newmem = realloc(mem, size + SFRAG)) == NULL) {
                                 free(mem);                                  free(mem);
                                 return (-2);                                  return -2;
                         }                          }
                         mem = newmem;                          mem = newmem;
                         m_room = SFRAG;                          m_room = SFRAG;
Line 1017  cgetstr(char *buf, const char *cap, char
Line 1025  cgetstr(char *buf, const char *cap, char
         if (m_room != 0) {          if (m_room != 0) {
                 if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) {                  if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) {
                         free(mem);                          free(mem);
                         return (-2);                          return -2;
                 }                  }
                 mem = newmem;                  mem = newmem;
         }          }
         *str = mem;          *str = mem;
         return (len);          _DIAGASSERT(__type_fit(int, len));
           return (int)len;
 }  }
   
 /*  /*
Line 1041  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 1052  cgetustr(char *buf, const char *cap, cha
Line 1061  cgetustr(char *buf, const char *cap, cha
          * Find string capability cap           * Find string capability cap
          */           */
         if ((bp = cgetcap(buf, cap, '=')) == NULL)          if ((bp = cgetcap(buf, cap, '=')) == NULL)
                 return (-1);                  return -1;
   
         /*          /*
          * Conversion / storage allocation loop ...  Allocate memory in           * Conversion / storage allocation loop ...  Allocate memory in
Line 1060  cgetustr(char *buf, const char *cap, cha
Line 1069  cgetustr(char *buf, const char *cap, cha
          */           */
         if ((mem = malloc(SFRAG)) == NULL) {          if ((mem = malloc(SFRAG)) == NULL) {
                 errno = ENOMEM;                  errno = ENOMEM;
                 return (-2);    /* couldn't even allocate the first fragment */                  return -2;      /* couldn't even allocate the first fragment */
         }          }
         m_room = SFRAG;          m_room = SFRAG;
         mp = mem;          mp = mem;
Line 1084  cgetustr(char *buf, const char *cap, cha
Line 1093  cgetustr(char *buf, const char *cap, cha
   
                         if ((newmem = realloc(mem, size + SFRAG)) == NULL) {                          if ((newmem = realloc(mem, size + SFRAG)) == NULL) {
                                 free(mem);                                  free(mem);
                                 return (-2);                                  return -2;
                         }                          }
                         mem = newmem;                          mem = newmem;
                         m_room = SFRAG;                          m_room = SFRAG;
Line 1101  cgetustr(char *buf, const char *cap, cha
Line 1110  cgetustr(char *buf, const char *cap, cha
         if (m_room != 0) {          if (m_room != 0) {
                 if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) {                  if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) {
                         free(mem);                          free(mem);
                         return (-2);                          return -2;
                 }                  }
                 mem = newmem;                  mem = newmem;
         }          }
         *str = mem;          *str = mem;
         return (len);          _DIAGASSERT(__type_fit(int, len));
           return (int)len;
 }  }
   
 /*  /*
Line 1131  cgetnum(char *buf, const char *cap, long
Line 1141  cgetnum(char *buf, const char *cap, long
          */           */
         bp = cgetcap(buf, cap, '#');          bp = cgetcap(buf, cap, '#');
         if (bp == NULL)          if (bp == NULL)
                 return (-1);                  return -1;
   
         /*          /*
          * Look at value and determine numeric base:           * Look at value and determine numeric base:
Line 1174  cgetnum(char *buf, const char *cap, long
Line 1184  cgetnum(char *buf, const char *cap, long
          * Return value and success.           * Return value and success.
          */           */
         *num = n;          *num = n;
         return (0);          return 0;
 }  }
   
   
Line 1191  nfcmp(char *nf, char *rec)
Line 1201  nfcmp(char *nf, char *rec)
         _DIAGASSERT(rec != NULL);          _DIAGASSERT(rec != NULL);
   
         for (cp = rec; *cp != ':'; cp++)          for (cp = rec; *cp != ':'; cp++)
                 ;                  continue;
   
         tmp = *(cp + 1);          tmp = *(cp + 1);
         *(cp + 1) = '\0';          *(cp + 1) = '\0';
         ret = strcmp(nf, rec);          ret = strcmp(nf, rec);
         *(cp + 1) = tmp;          *(cp + 1) = tmp;
   
         return (ret);          return ret;
 }  }

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.52.2.1

CVSweb <webmaster@jp.NetBSD.org>