Thu Jul 18 16:01:25 2013 UTC ()
Set the string to NUL instread of providing an new empty string (from uwe)


(christos)
diff -r1.48 -r1.49 src/usr.bin/man/man.c

cvs diff -r1.48 -r1.49 src/usr.bin/man/man.c (expand / switch to unified diff)

--- src/usr.bin/man/man.c 2013/07/18 15:39:08 1.48
+++ src/usr.bin/man/man.c 2013/07/18 16:01:25 1.49
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: man.c,v 1.48 2013/07/18 15:39:08 christos Exp $ */ 1/* $NetBSD: man.c,v 1.49 2013/07/18 16:01:25 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1987, 1993, 1994, 1995 4 * Copyright (c) 1987, 1993, 1994, 1995
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33 33
34#ifndef lint 34#ifndef lint
35__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994, 1995\ 35__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994, 1995\
36 The Regents of the University of California. All rights reserved."); 36 The Regents of the University of California. All rights reserved.");
37#endif /* not lint */ 37#endif /* not lint */
38 38
39#ifndef lint 39#ifndef lint
40#if 0 40#if 0
41static char sccsid[] = "@(#)man.c 8.17 (Berkeley) 1/31/95"; 41static char sccsid[] = "@(#)man.c 8.17 (Berkeley) 1/31/95";
42#else 42#else
43__RCSID("$NetBSD: man.c,v 1.48 2013/07/18 15:39:08 christos Exp $"); 43__RCSID("$NetBSD: man.c,v 1.49 2013/07/18 16:01:25 christos Exp $");
44#endif 44#endif
45#endif /* not lint */ 45#endif /* not lint */
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/queue.h> 48#include <sys/queue.h>
49#include <sys/stat.h> 49#include <sys/stat.h>
50#include <sys/utsname.h> 50#include <sys/utsname.h>
51 51
52#include <ctype.h> 52#include <ctype.h>
53#include <err.h> 53#include <err.h>
54#include <errno.h> 54#include <errno.h>
55#include <fcntl.h> 55#include <fcntl.h>
56#include <fnmatch.h> 56#include <fnmatch.h>
@@ -112,28 +112,26 @@ struct manstate { @@ -112,28 +112,26 @@ struct manstate {
112static void build_page(char *, char **, struct manstate *); 112static void build_page(char *, char **, struct manstate *);
113static void cat(char *); 113static void cat(char *);
114static const char *check_pager(const char *); 114static const char *check_pager(const char *);
115static int cleanup(void); 115static int cleanup(void);
116static void how(char *); 116static void how(char *);
117static void jump(char **, const char *, const char *); 117static void jump(char **, const char *, const char *);
118static int manual(char *, struct manstate *, glob_t *); 118static int manual(char *, struct manstate *, glob_t *);
119static void onsig(int); 119static void onsig(int);
120static void usage(void) __attribute__((__noreturn__)); 120static void usage(void) __attribute__((__noreturn__));
121static void addpath(struct manstate *, const char *, size_t, const char *); 121static void addpath(struct manstate *, const char *, size_t, const char *);
122static const char *getclass(const char *); 122static const char *getclass(const char *);
123static void printmanpath(struct manstate *); 123static void printmanpath(struct manstate *);
124 124
125static char EMPTY[1]; 
126 
127/* 125/*
128 * main function 126 * main function
129 */ 127 */
130int 128int
131main(int argc, char **argv) 129main(int argc, char **argv)
132{ 130{
133 static struct manstate m; 131 static struct manstate m;
134 int ch, abs_section, found; 132 int ch, abs_section, found;
135 ENTRY *esubd, *epath; 133 ENTRY *esubd, *epath;
136 char *p, **ap, *cmd; 134 char *p, **ap, *cmd;
137 size_t len; 135 size_t len;
138 glob_t pg; 136 glob_t pg;
139 137
@@ -577,34 +575,34 @@ manual(char *page, struct manstate *mp,  @@ -577,34 +575,34 @@ manual(char *page, struct manstate *mp,
577 p[0] = '\0'; 575 p[0] = '\0';
578 576
579 found = 0; 577 found = 0;
580 for (cnt = pg->gl_pathc - pg->gl_matchc; 578 for (cnt = pg->gl_pathc - pg->gl_matchc;
581 cnt < pg->gl_pathc; ++cnt) 579 cnt < pg->gl_pathc; ++cnt)
582 { 580 {
583 found = manual_find_buildkeyword(escpage, "%s%s", 581 found = manual_find_buildkeyword(escpage, "%s%s",
584 mp, pg, cnt); 582 mp, pg, cnt);
585 if (found) { 583 if (found) {
586 anyfound = 1; 584 anyfound = 1;
587 if (!mp->all) { 585 if (!mp->all) {
588 /* Delete any other matches. */ 586 /* Delete any other matches. */
589 while (++cnt< pg->gl_pathc) 587 while (++cnt< pg->gl_pathc)
590 pg->gl_pathv[cnt] = EMPTY; 588 *pg->gl_pathv[cnt] = '\0';
591 break; 589 break;
592 } 590 }
593 continue; 591 continue;
594 } 592 }
595 593
596 /* It's not a man page, forget about it. */ 594 /* It's not a man page, forget about it. */
597 pg->gl_pathv[cnt] = EMPTY; 595 *pg->gl_pathv[cnt] = '\0';
598 } 596 }
599 597
600 notfound: 598 notfound:
601 if (!anyfound) { 599 if (!anyfound) {
602 if (addentry(mp->missinglist, page, 0) < 0) { 600 if (addentry(mp->missinglist, page, 0) < 0) {
603 warn("malloc"); 601 warn("malloc");
604 (void)cleanup(); 602 (void)cleanup();
605 exit(EXIT_FAILURE); 603 exit(EXIT_FAILURE);
606 } 604 }
607 } 605 }
608 free(escpage); 606 free(escpage);
609 return anyfound; 607 return anyfound;
610 } 608 }
@@ -633,27 +631,27 @@ manual(char *page, struct manstate *mp,  @@ -633,27 +631,27 @@ manual(char *page, struct manstate *mp,
633 /* 631 /*
634 * start going through the matches glob(3) just found and  632 * start going through the matches glob(3) just found and
635 * use m.pathsearch (if present) to filter out pages we  633 * use m.pathsearch (if present) to filter out pages we
636 * don't want. then verify the suffix is valid, and build 634 * don't want. then verify the suffix is valid, and build
637 * the page if we have a _build suffix. 635 * the page if we have a _build suffix.
638 */ 636 */
639 for (cnt = pg->gl_pathc - pg->gl_matchc; 637 for (cnt = pg->gl_pathc - pg->gl_matchc;
640 cnt < pg->gl_pathc; ++cnt) { 638 cnt < pg->gl_pathc; ++cnt) {
641 639
642 /* filter on directory path name */ 640 /* filter on directory path name */
643 if (mp->pathsearch) { 641 if (mp->pathsearch) {
644 p = strstr(pg->gl_pathv[cnt], mp->pathsearch); 642 p = strstr(pg->gl_pathv[cnt], mp->pathsearch);
645 if (!p || strchr(p, '/') == NULL) { 643 if (!p || strchr(p, '/') == NULL) {
646 pg->gl_pathv[cnt] = EMPTY; /* zap! */ 644 *pg->gl_pathv[cnt] = '\0'; /* zap! */
647 continue; 645 continue;
648 } 646 }
649 } 647 }
650 648
651 /* 649 /*
652 * Try the _suffix key words first. 650 * Try the _suffix key words first.
653 * 651 *
654 * XXX 652 * XXX
655 * Older versions of man.conf didn't have the suffix 653 * Older versions of man.conf didn't have the suffix
656 * key words, it was assumed that everything was a .0. 654 * key words, it was assumed that everything was a .0.
657 * We just test for .0 first, it's fast and probably 655 * We just test for .0 first, it's fast and probably
658 * going to hit. 656 * going to hit.
659 */ 657 */
@@ -672,34 +670,34 @@ manual(char *page, struct manstate *mp,  @@ -672,34 +670,34 @@ manual(char *page, struct manstate *mp,
672 } 670 }
673 } 671 }
674 if (found) 672 if (found)
675 goto next; 673 goto next;
676 674
677 /* Try the _build key words next. */ 675 /* Try the _build key words next. */
678 found = manual_find_buildkeyword(escpage, "*/%s%s", 676 found = manual_find_buildkeyword(escpage, "*/%s%s",
679 mp, pg, cnt); 677 mp, pg, cnt);
680 if (found) { 678 if (found) {
681next: anyfound = 1; 679next: anyfound = 1;
682 if (!mp->all) { 680 if (!mp->all) {
683 /* Delete any other matches. */ 681 /* Delete any other matches. */
684 while (++cnt< pg->gl_pathc) 682 while (++cnt< pg->gl_pathc)
685 pg->gl_pathv[cnt] = EMPTY; 683 *pg->gl_pathv[cnt] = '\0';
686 break; 684 break;
687 } 685 }
688 continue; 686 continue;
689 } 687 }
690 688
691 /* It's not a man page, forget about it. */ 689 /* It's not a man page, forget about it. */
692 pg->gl_pathv[cnt] = EMPTY; 690 *pg->gl_pathv[cnt] = '\0';
693 } 691 }
694 692
695 if (anyfound && !mp->all) 693 if (anyfound && !mp->all)
696 break; 694 break;
697 } 695 }
698 696
699 /* If not found, enter onto the missing list. */ 697 /* If not found, enter onto the missing list. */
700 if (!anyfound) { 698 if (!anyfound) {
701 if (addentry(mp->missinglist, page, 0) < 0) { 699 if (addentry(mp->missinglist, page, 0) < 0) {
702 warn("malloc"); 700 warn("malloc");
703 (void)cleanup(); 701 (void)cleanup();
704 exit(EXIT_FAILURE); 702 exit(EXIT_FAILURE);
705 } 703 }