[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.31 and 1.37

version 1.31, 1999/09/20 04:38:59 version 1.37, 2003/01/31 20:50:30
Line 36 
Line 36 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #if HAVE_CONFIG_H
   #include "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 47  __RCSID("$NetBSD$");
Line 51  __RCSID("$NetBSD$");
   
 #include "namespace.h"  #include "namespace.h"
 #include <sys/types.h>  #include <sys/types.h>
   #include <sys/param.h>
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
Line 60  __RCSID("$NetBSD$");
Line 65  __RCSID("$NetBSD$");
 #include <unistd.h>  #include <unistd.h>
   
 #ifdef __weak_alias  #ifdef __weak_alias
 __weak_alias(cgetcap,_cgetcap);  __weak_alias(cgetcap,_cgetcap)
 __weak_alias(cgetclose,_cgetclose);  __weak_alias(cgetclose,_cgetclose)
 __weak_alias(cgetent,_cgetent);  __weak_alias(cgetent,_cgetent)
 __weak_alias(cgetfirst,_cgetfirst);  __weak_alias(cgetfirst,_cgetfirst)
 __weak_alias(cgetmatch,_cgetmatch);  __weak_alias(cgetmatch,_cgetmatch)
 __weak_alias(cgetnext,_cgetnext);  __weak_alias(cgetnext,_cgetnext)
 __weak_alias(cgetnum,_cgetnum);  __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)
 #endif  #endif
   
 #define BFRAG           1024  #define BFRAG           1024
Line 249  getent(cap, len, db_array, fd, name, dep
Line 254  getent(cap, len, db_array, fd, name, dep
         char *r_end, *rp = NULL, **db_p;        /* pacify gcc */          char *r_end, *rp = NULL, **db_p;        /* pacify gcc */
         int myfd = 0, eof, foundit, retval;          int myfd = 0, eof, foundit, retval;
         size_t clen;          size_t clen;
         char *record, *cbuf;          char *record, *cbuf, *newrecord;
         int tc_not_resolved;          int tc_not_resolved;
         char pbuf[_POSIX_PATH_MAX];          char pbuf[MAXPATHLEN];
   
         _DIAGASSERT(cap != NULL);          _DIAGASSERT(cap != NULL);
         _DIAGASSERT(len != NULL);          _DIAGASSERT(len != NULL);
Line 435  getent(cap, len, db_array, fd, name, dep
Line 440  getent(cap, len, db_array, fd, name, dep
   
                                         pos = rp - record;                                          pos = rp - record;
                                         newsize = r_end - record + BFRAG;                                          newsize = r_end - record + BFRAG;
                                         record = realloc(record, newsize);                                          newrecord = realloc(record, newsize);
                                         if (record == NULL) {                                          if (newrecord == NULL) {
                                                   free(record);
                                                 if (myfd)                                                  if (myfd)
                                                         (void)close(fd);                                                          (void)close(fd);
                                                 errno = ENOMEM;                                                  errno = ENOMEM;
                                                 return (-2);                                                  return (-2);
                                         }                                          }
                                           record = newrecord;
                                         r_end = record + newsize;                                          r_end = record + newsize;
                                         rp = record + pos;                                          rp = record + pos;
                                 }                                  }
Line 577  tc_exp: {
Line 584  tc_exp: {
                                 newsize = r_end - record + diff + BFRAG;                                  newsize = r_end - record + diff + BFRAG;
                                 tcpos = tcstart - record;                                  tcpos = tcstart - record;
                                 tcposend = tcend - record;                                  tcposend = tcend - record;
                                 record = realloc(record, newsize);                                  newrecord = realloc(record, newsize);
                                 if (record == NULL) {                                  if (newrecord == NULL) {
                                           free(record);
                                         if (myfd)                                          if (myfd)
                                                 (void)close(fd);                                                  (void)close(fd);
                                         free(icap);                                          free(icap);
                                         errno = ENOMEM;                                          errno = ENOMEM;
                                         return (-2);                                          return (-2);
                                 }                                  }
                                   record = newrecord;
                                 r_end = record + newsize;                                  r_end = record + newsize;
                                 rp = record + pos;                                  rp = record + pos;
                                 tcstart = record + tcpos;                                  tcstart = record + tcpos;
Line 615  tc_exp: {
Line 624  tc_exp: {
         if (myfd)          if (myfd)
                 (void)close(fd);                  (void)close(fd);
         *len = rp - record - 1; /* don't count NUL */          *len = rp - record - 1; /* don't count NUL */
         if (r_end > rp)          if (r_end > rp) {
                 if ((record =                  if ((newrecord =
                      realloc(record, (size_t)(rp - record))) == NULL) {                       realloc(record, (size_t)(rp - record))) == NULL) {
                           free(record);
                         errno = ENOMEM;                          errno = ENOMEM;
                         return (-2);                          return (-2);
                 }                  }
                   record = newrecord;
           }
   
         *cap = record;          *cap = record;
         if (tc_not_resolved)          if (tc_not_resolved)
Line 701  cgetmatch(buf, name)
Line 713  cgetmatch(buf, name)
                 /*                  /*
                  * Match failed, skip to next name in record.                   * Match failed, skip to next name in record.
                  */                   */
                 bp--;   /* a '|' or ':' may have stopped the match */                  if (bp > buf)
                           bp--;   /* a '|' or ':' may have stopped the match */
                   else
                           return (-1);
                 for (;;)                  for (;;)
                         if (*bp == '\0' || *bp == ':')                          if (*bp == '\0' || *bp == ':')
                                 return (-1);    /* match failed totally */                                  return (-1);    /* match failed totally */
Line 812  cgetnext(bp, db_array)
Line 827  cgetnext(bp, db_array)
                 /*                  /*
                  * Line points to a name line.                   * Line points to a name line.
                  */                   */
                   if (len > sizeof(nbuf))
                           return -1;
                 done = 0;                  done = 0;
                 np = nbuf;                  np = nbuf;
                 for (;;) {                  for (;;) {
Line 843  cgetnext(bp, db_array)
Line 860  cgetnext(bp, db_array)
                                         line[len - 1] = '\0';                                          line[len - 1] = '\0';
                         }                          }
                 }                  }
                   if (len > sizeof(buf))
                           return -1;
                 rp = buf;                  rp = buf;
                 for(cp = nbuf; *cp != '\0'; cp++)                  for(cp = nbuf; *cp != '\0'; cp++)
                         if (*cp == '|' || *cp == ':')                          if (*cp == '|' || *cp == ':')
Line 887  cgetstr(buf, cap, str)
Line 906  cgetstr(buf, cap, str)
         const char *bp;          const char *bp;
         char *mp;          char *mp;
         int len;          int len;
         char *mem;          char *mem, *newmem;
   
         _DIAGASSERT(buf != NULL);          _DIAGASSERT(buf != NULL);
         _DIAGASSERT(cap != NULL);          _DIAGASSERT(cap != NULL);
Line 978  cgetstr(buf, cap, str)
Line 997  cgetstr(buf, cap, str)
                 if (m_room == 0) {                  if (m_room == 0) {
                         size_t size = mp - mem;                          size_t size = mp - mem;
   
                         if ((mem = realloc(mem, size + SFRAG)) == NULL)                          if ((newmem = realloc(mem, size + SFRAG)) == NULL) {
                                   free(mem);
                                 return (-2);                                  return (-2);
                           }
                           mem = newmem;
                         m_room = SFRAG;                          m_room = SFRAG;
                         mp = mem + size;                          mp = mem + size;
                 }                  }
Line 991  cgetstr(buf, cap, str)
Line 1013  cgetstr(buf, cap, str)
         /*          /*
          * Give back any extra memory and return value and success.           * Give back any extra memory and return value and success.
          */           */
         if (m_room != 0)          if (m_room != 0) {
                 if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL)                  if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) {
                           free(mem);
                         return (-2);                          return (-2);
                   }
                   mem = newmem;
           }
         *str = mem;          *str = mem;
         return (len);          return (len);
 }  }
Line 1018  cgetustr(buf, cap, str)
Line 1044  cgetustr(buf, cap, str)
         const char *bp;          const char *bp;
         char *mp;          char *mp;
         int len;          int len;
         char *mem;          char *mem, *newmem;
   
         _DIAGASSERT(buf != NULL);          _DIAGASSERT(buf != NULL);
         _DIAGASSERT(cap != NULL);          _DIAGASSERT(cap != NULL);
Line 1058  cgetustr(buf, cap, str)
Line 1084  cgetustr(buf, cap, str)
                 if (m_room == 0) {                  if (m_room == 0) {
                         size_t size = mp - mem;                          size_t size = mp - mem;
   
                         if ((mem = realloc(mem, size + SFRAG)) == NULL)                          if ((newmem = realloc(mem, size + SFRAG)) == NULL) {
                                   free(mem);
                                 return (-2);                                  return (-2);
                           }
                           mem = newmem;
                         m_room = SFRAG;                          m_room = SFRAG;
                         mp = mem + size;                          mp = mem + size;
                 }                  }
Line 1071  cgetustr(buf, cap, str)
Line 1100  cgetustr(buf, cap, str)
         /*          /*
          * Give back any extra memory and return value and success.           * Give back any extra memory and return value and success.
          */           */
         if (m_room != 0)          if (m_room != 0) {
                 if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL)                  if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) {
                           free(mem);
                         return (-2);                          return (-2);
                   }
                   mem = newmem;
           }
         *str = mem;          *str = mem;
         return (len);          return (len);
 }  }

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.37

CVSweb <webmaster@jp.NetBSD.org>