[BACK]Return to cap_mkdb.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cap_mkdb

Diff for /src/usr.bin/cap_mkdb/cap_mkdb.c between version 1.14 and 1.15

version 1.14, 2006/03/04 20:32:51 version 1.15, 2009/08/28 11:43:50
Line 159 
Line 159 
         recno_t reccnt;          recno_t reccnt;
         size_t len, bplen;          size_t len, bplen;
         int st;          int st;
         char *bp, *p, *t;          char *bp, *p, *t, *out, ch;
   
         cgetusedb(0);           /* disable reading of .db files in getcap(3) */          cgetusedb(0);           /* disable reading of .db files in getcap(3) */
   
Line 169 
Line 169 
              (st = (info ? igetnext(&bp, ifiles) : cgetnext(&bp, ifiles))) > 0;) {               (st = (info ? igetnext(&bp, ifiles) : cgetnext(&bp, ifiles))) > 0;) {
   
                 /*                  /*
                  * Allocate enough memory to store record, terminating                   * Allocate enough memory to store four times the size of the
                  * NULL and one extra byte.                   * record (so an existing ':' can be expanded to '\072' for
                    * terminfo) plus a terminating NULL and one extra byte.
                  */                   */
                 len = strlen(bp);                  len = strlen(bp);
                 if (bplen <= len + 2) {                  if (bplen <= 4 * len + 2) {
                         int newbplen = bplen + MAX(256, len + 2);                          int newbplen = bplen + MAX(256, 4 * len + 2);
                         void *newdata;                          void *newdata;
   
                         if ((newdata = realloc(data.data, newbplen)) == NULL)                          if ((newdata = realloc(data.data, newbplen)) == NULL)
Line 202 
Line 203 
   
                 /* Create the stored record. */                  /* Create the stored record. */
                 if (info) {                  if (info) {
                         (void) memcpy(&((u_char *)(data.data))[1], bp, len + 1);                          /*
                            * The record separator is :, so it is necessary to
                            * change commas into colons. However, \, should be
                            * left alone, unless the \ is the last part of ^\.
                            */
                         data.size = len + 2;                          data.size = len + 2;
                         for (t = memchr((char *)data.data + 1, ',', data.size - 1);                          out = ((char *) data.data) + 1;
                              t;                          t = bp;
                              t = memchr(t, ',', data.size - (t - (char *)data.data)))                          while (t < bp + len) {
                                 *t++ = ':';                                  switch (ch = *t++) {
                                   case '^':
                                   case '\\':
                                           *out++ = ch;
                                           if (*t != '\0')
                                                   *out++ = *t++;
                                           break;
                                   case ':':
                                           memcpy(out, "\\072", 4);
                                           out += 4;
                                           data.size += 3; /* : already counted */
                                           break;
                                   case ',':
                                           *out++ = ':';
                                           break;
                                   default:
                                           *out++ = ch;
                                           break;
                                   }
                           }
                           *out++ = '\0';
                         if (memchr((char *)data.data + 1, '\0', data.size - 2)) {                          if (memchr((char *)data.data + 1, '\0', data.size - 2)) {
                                 warnx("NUL in entry: %.*s", (int)MIN(len, 20), bp);                                  warnx("NUL in entry: %.*s", (int)MIN(len, 20), bp);
                                 continue;                                  continue;

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15