[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.18 and 1.21

version 1.18, 1998/03/02 23:39:49 version 1.21, 1998/07/27 07:41:53
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 **, size_t *, 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;
 {  {
         size_t dummy;          size_t dummy;
   
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 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 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, data;
   
         key.data = name;          key.data = (char *)name;
         key.size = strlen(name);          key.size = strlen(name);
   
         for (;;) {          for (;;) {
Line 587  cdbget(capdbp, bp, name)
Line 623  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 623  cgetmatch(buf, name)
Line 659  cgetmatch(buf, name)
         }          }
 }  }
   
   
   
   
   
 int  int
 cgetfirst(buf, db_array)  cgetfirst(buf, db_array)
         char **buf, **db_array;          char **buf, **db_array;
Line 681  cgetnext(bp, db_array)
Line 713  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 739  cgetnext(bp, db_array)
Line 772  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 820  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 947  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 1019  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.18  
changed lines
  Added in v.1.21

CVSweb <webmaster@jp.NetBSD.org>