Print this page
Latest round of fixes per RM and AL.  Fix bugs found in man.c.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/man/makewhatis.c
          +++ new/usr/src/cmd/man/makewhatis.c
↓ open down ↓ 20 lines elided ↑ open up ↑
  21   21   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22   22   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23   23   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24   24   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25   25   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26   26   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27   27   */
  28   28  
  29   29  /*
  30   30   * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
       31 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  31   32   */
  32   33  
  33   34  #include <sys/types.h>
  34   35  #include <sys/stat.h>
  35   36  #include <sys/param.h>
  36   37  
  37   38  #include <ctype.h>
  38   39  #include <dirent.h>
  39   40  #include <err.h>
  40   41  #include <signal.h>
↓ open down ↓ 128 lines elided ↑ open up ↑
 169  170  
 170  171  /*
 171  172   * Ensure that there is enough room in the sbuf
 172  173   * for nchars more characters.
 173  174   */
 174  175  static void
 175  176  sbuf_need(struct sbuf *sbuf, int nchars)
 176  177  {
 177  178          char *new_content;
 178  179          size_t size, cntsize;
      180 +        size_t grow = 128;
 179  181  
 180      -        /* Double the size of the allocation until the buffer is big enough */
 181      -        while (sbuf->end + nchars > sbuf->last) {
      182 +        while (grow < nchars) {
      183 +                grow += 128;    /* we grow in chunks of 128 bytes */
      184 +        }
      185 +
      186 +        /* Grow if the buffer isn't big enough */
      187 +        if (sbuf->end + nchars > sbuf->last) {
 182  188                  size = sbuf->last + 1 - sbuf->content;
 183      -                size *= 2;
      189 +                size += grow;
 184  190                  cntsize = sbuf->end - sbuf->content;
 185  191  
 186      -                new_content = (char *)malloc(size);
 187      -                (void) memcpy(new_content, sbuf->content, cntsize);
 188      -                free(sbuf->content);
      192 +                if ((new_content = realloc(sbuf->content, size)) == NULL) {
      193 +                        perror("realloc");
      194 +                        if (tempfile[0] != '\0')
      195 +                                (void) unlink(tempfile);
      196 +                        exit(1);
      197 +                }
 189  198                  sbuf->content = new_content;
 190  199                  sbuf->end = new_content + cntsize;
 191  200                  sbuf->last = new_content + size - 1;
 192  201          }
 193  202  }
 194  203  
 195  204  /*
 196  205   * Append a string of a given length to the sbuf.
 197  206   */
 198  207  static void
↓ open down ↓ 53 lines elided ↑ open up ↑
 252  261  }
 253  262  
 254  263  /*
 255  264   * Return true if no man page exists in the directory with
 256  265   * any of the names in the stringlist.
 257  266   */
 258  267  static int
 259  268  no_page_exists(char *dir, stringlist *names, char *suffix)
 260  269  {
 261  270          char    path[MAXPATHLEN];
      271 +        char    *suffixes[] = { "", ".gz", ".bz2", NULL };
 262  272          size_t  i;
      273 +        int     j;
 263  274  
 264  275          for (i = 0; i < names->sl_cur; i++) {
 265      -                (void) snprintf(path, MAXPATHLEN, "%s/%s.%s.gz",
 266      -                    dir, names->sl_str[i], suffix);
 267      -                if (access(path, F_OK) < 0) {
 268      -                        path[strlen(path) - 3] = '\0';
 269      -                        if (access(path, F_OK) < 0)
 270      -                                continue;
      276 +                for (j = 0; suffixes[j] != NULL; j++) {
      277 +                        (void) snprintf(path, MAXPATHLEN, "%s/%s.%s%s",
      278 +                            dir, names->sl_str[i], suffix, suffixes[j]);
      279 +                        if (access(path, F_OK) == 0) {
      280 +                                return (0);
      281 +                        }
 271  282                  }
 272      -                return (0);
 273  283          }
 274  284          return (1);
 275  285  }
 276  286  
 277  287  /* ARGSUSED sig */
 278  288  static void
 279  289  trap_signal(int sig)
 280  290  {
 281  291  
 282  292          if (tempfile[0] != '\0')
↓ open down ↓ 545 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX