[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.17 and 1.26

version 1.17, 1998/02/26 02:40:11 version 1.26, 1999/03/16 18:13:45
Line 84  static size_t  topreclen; /* toprec leng
Line 84  static size_t  topreclen; /* toprec leng
 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      cdbget __P((DB *, char **, char *));  static int      cdbget __P((DB *, char **, const char *));
 static int      getent __P((char **, u_int *, char **, int, char *, int, char *));  static int      getent __P((char **, size_t *, char **, int, const char *, int, char *));
 static int      nfcmp __P((char *, char *));  static int      nfcmp __P((char *, char *));
   
 /*  /*
Line 95  static int nfcmp __P((char *, char *));
Line 95  static int nfcmp __P((char *, char *));
  */   */
 int  int
 cgetset(ent)  cgetset(ent)
         char *ent;          const char *ent;
 {  {
         if (ent == NULL) {          if (ent == NULL) {
                 if (toprec)                  if (toprec)
Line 128  cgetset(ent)
Line 128  cgetset(ent)
  */   */
 char *  char *
 cgetcap(buf, cap, type)  cgetcap(buf, cap, type)
         char *buf, *cap;          char *buf;
           const char *cap;
         int type;          int type;
 {  {
         char *bp, *cp;          char *bp;
           const char *cp;
   
         bp = buf;          bp = buf;
         for (;;) {          for (;;) {
Line 180  cgetcap(buf, cap, type)
Line 182  cgetcap(buf, cap, type)
  */   */
 int  int
 cgetent(buf, db_array, name)  cgetent(buf, db_array, name)
         char **buf, **db_array, *name;          char **buf, **db_array;
           const char *name;
 {  {
         u_int dummy;          size_t dummy;
   
         return (getent(buf, &dummy, db_array, -1, name, 0, NULL));          return (getent(buf, &dummy, db_array, -1, name, 0, NULL));
 }  }
Line 207  cgetent(buf, db_array, name)
Line 210  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, *nfield;
           const char *name;
         size_t *len;          size_t *len;
         int fd, depth;          int fd, depth;
 {  {
Line 276  getent(cap, len, db_array, fd, name, dep
Line 280  getent(cap, len, db_array, fd, name, dep
                                 /* save the data; close frees it */                                  /* save the data; close frees it */
                                 clen = strlen(record);                                  clen = strlen(record);
                                 cbuf = malloc(clen + 1);                                  cbuf = malloc(clen + 1);
                                 memcpy(cbuf, record, clen + 1);                                  memmove(cbuf, record, clen + 1);
                                 if (capdbp->close(capdbp) < 0) {                                  if (capdbp->close(capdbp) < 0) {
                                         free(cbuf);                                          free(cbuf);
                                         return (-2);                                          return (-2);
Line 298  getent(cap, len, db_array, fd, name, dep
Line 302  getent(cap, len, db_array, fd, name, dep
                  */                   */
                 {                  {
                 char buf[BUFSIZ];                  char buf[BUFSIZ];
                 char *b_end, *bp;                  char *b_end, *bp, *cp;
                 int c;                  int c, slash;
   
                 /*                  /*
                  * Loop invariants:                   * Loop invariants:
Line 308  getent(cap, len, db_array, fd, name, dep
Line 312  getent(cap, len, db_array, fd, name, dep
                  *      Rp always points just past last character in record.                   *      Rp always points just past last character in record.
                  *      B_end always points just past last character in buf.                   *      B_end always points just past last character in buf.
                  *      Bp always points at next character in buf.                   *      Bp always points at next character in buf.
                    *      Cp remembers where the last colon was.
                  */                   */
                 b_end = buf;                  b_end = buf;
                 bp = buf;                  bp = buf;
                   cp = 0;
                   slash = 0;
                 for (;;) {                  for (;;) {
   
                         /*                          /*
Line 341  getent(cap, len, db_array, fd, name, dep
Line 348  getent(cap, len, db_array, fd, name, dep
   
                                 c = *bp++;                                  c = *bp++;
                                 if (c == '\n') {                                  if (c == '\n') {
                                         if (rp > record && *(rp-1) == '\\') {                                          if (slash) {
                                                   slash = 0;
                                                 rp--;                                                  rp--;
                                                 continue;                                                  continue;
                                         } else                                          } else
                                                 break;                                                  break;
                                 }                                  }
                                   if (slash) {
                                           slash = 0;
                                           cp = 0;
                                   }
                                   if (c == ':') {
                                           /*
                                            * If the field was `empty' (i.e.
                                            * contained only white space), back up
                                            * to the colon (eliminating the
                                            * field).
                                            */
                                           if (cp)
                                                   rp = cp;
                                           else
                                                   cp = rp;
                                   } else if (c == '\\') {
                                           slash = 1;
                                   } else if (c != ' ' && c != '\t') {
                                           /*
                                            * Forget where the colon was, as this
                                            * is not an empty field.
                                            */
                                           cp = 0;
                                   }
                                 *rp++ = c;                                  *rp++ = c;
   
                                 /*                                  /*
Line 371  getent(cap, len, db_array, fd, name, dep
Line 403  getent(cap, len, db_array, fd, name, dep
                                         rp = record + pos;                                          rp = record + pos;
                                 }                                  }
                         }                          }
                                 /* loop invariant let's us do this */                          /* Eliminate any white space after the last colon. */
                           if (cp)
                                   rp = cp + 1;
                           /* Loop invariant lets us do this. */
                         *rp++ = '\0';                          *rp++ = '\0';
   
                         /*                          /*
Line 517  tc_exp: {
Line 552  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, (size_t)(rp - tcend));                          memmove(s, tcend,  (size_t)(rp - tcend));
                         bcopy(newicap, tcstart, newilen);                          memmove(tcstart, newicap, newilen);
                         rp += diff;                          rp += diff;
                         free(icap);                          free(icap);
   
Line 553  tc_exp: {
Line 588  tc_exp: {
 static int  static int
 cdbget(capdbp, bp, name)  cdbget(capdbp, bp, name)
         DB *capdbp;          DB *capdbp;
         char **bp, *name;          char **bp;
           const char *name;
 {  {
         DBT key, data;          DBT key;
           DBT data;
   
         key.data = name;          /* LINTED key is not modified */
           key.data = (char *)name;
         key.size = strlen(name);          key.size = strlen(name);
   
         for (;;) {          for (;;) {
Line 587  cdbget(capdbp, bp, name)
Line 625  cdbget(capdbp, bp, name)
  */   */
 int  int
 cgetmatch(buf, name)  cgetmatch(buf, name)
         char *buf, *name;          const char *buf, *name;
 {  {
         char *np, *bp;          const char *np, *bp;
   
         /*          /*
          * Start search at beginning of record.           * Start search at beginning of record.
Line 601  cgetmatch(buf, name)
Line 639  cgetmatch(buf, name)
                  */                   */
                 np = name;                  np = name;
                 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;
   
Line 623  cgetmatch(buf, name)
Line 661  cgetmatch(buf, name)
         }          }
 }  }
   
   
   
   
   
 int  int
 cgetfirst(buf, db_array)  cgetfirst(buf, db_array)
         char **buf, **db_array;          char **buf, **db_array;
Line 665  cgetnext(bp, db_array)
Line 699  cgetnext(bp, db_array)
         size_t len;          size_t len;
         int status, 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;          size_t dummy;
   
         if (dbp == NULL)          if (dbp == NULL)
                 dbp = db_array;                  dbp = db_array;
Line 681  cgetnext(bp, db_array)
Line 715  cgetnext(bp, db_array)
                 } else {                  } else {
                         line = fgetln(pfp, &len);                          line = fgetln(pfp, &len);
                         if (line == NULL && pfp) {                          if (line == NULL && pfp) {
                                 (void)fclose(pfp);  
                                 if (ferror(pfp)) {                                  if (ferror(pfp)) {
                                         (void)cgetclose();                                          (void)cgetclose();
                                         return (-1);                                          return (-1);
                                 } else {                                  } else {
                                           (void)fclose(pfp);
                                           pfp = NULL;
                                         if (*++dbp == NULL) {                                          if (*++dbp == NULL) {
                                                 (void)cgetclose();                                                  (void)cgetclose();
                                                 return (0);                                                  return (0);
Line 702  cgetnext(bp, db_array)
Line 737  cgetnext(bp, db_array)
                                 slash = 0;                                  slash = 0;
                                 continue;                                  continue;
                         }                          }
                         if (isspace(*line) ||                          if (isspace((unsigned char)*line) ||
                             *line == ':' || *line == '#' || slash) {                              *line == ':' || *line == '#' || slash) {
                                 if (line[len - 2] == '\\')                                  if (line[len - 2] == '\\')
                                         slash = 1;                                          slash = 1;
Line 739  cgetnext(bp, db_array)
Line 774  cgetnext(bp, db_array)
                         } else { /* name field extends beyond the line */                          } else { /* name field extends beyond the line */
                                 line = fgetln(pfp, &len);                                  line = fgetln(pfp, &len);
                                 if (line == NULL && pfp) {                                  if (line == NULL && pfp) {
                                         (void)fclose(pfp);  
                                         if (ferror(pfp)) {                                          if (ferror(pfp)) {
                                                 (void)cgetclose();                                                  (void)cgetclose();
                                                 return (-1);                                                  return (-1);
                                         }                                          }
                                           (void)fclose(pfp);
                                           pfp = NULL;
                                           *np = '\0';
                                           break;
                                 } else                                  } else
                                         line[len - 1] = '\0';                                          line[len - 1] = '\0';
                         }                          }
Line 784  cgetnext(bp, db_array)
Line 822  cgetnext(bp, db_array)
  */   */
 int  int
 cgetstr(buf, cap, str)  cgetstr(buf, cap, str)
         char *buf, *cap;          char *buf;
           const char *cap;
         char **str;          char **str;
 {  {
         u_int m_room;          u_int m_room;
         char *bp, *mp;          const char *bp;
           char *mp;
         int len;          int len;
         char *mem;          char *mem;
   
Line 909  cgetstr(buf, cap, str)
Line 949  cgetstr(buf, cap, str)
  */   */
 int  int
 cgetustr(buf, cap, str)  cgetustr(buf, cap, str)
         char *buf, *cap, **str;          char *buf;
           const char *cap;
           char **str;
 {  {
         u_int m_room;          u_int m_room;
         char *bp, *mp;          const char *bp;
           char *mp;
         int len;          int len;
         char *mem;          char *mem;
   
Line 978  cgetustr(buf, cap, str)
Line 1021  cgetustr(buf, cap, str)
  */   */
 int  int
 cgetnum(buf, cap, num)  cgetnum(buf, cap, num)
         char *buf, *cap;          char *buf;
           const char *cap;
         long *num;          long *num;
 {  {
         long n;          long n;
         int base, digit;          int base, digit;
         char *bp;          const char *bp;
   
         /*          /*
          * Find numeric capability cap           * Find numeric capability cap

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

CVSweb <webmaster@jp.NetBSD.org>