diff --git a/usr.bin/catman/catman.c b/usr.bin/catman/catman.c index b22111118314..a86b50b09e13 100644 --- a/usr.bin/catman/catman.c +++ b/usr.bin/catman/catman.c @@ -34,9 +34,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include +#include #include #include #include @@ -267,7 +269,8 @@ get_cat_section(char *section) char *cat_section; cat_section = strdup(section); - strncpy(cat_section, "cat", 3); + assert(strlen(section) > 3 && strncmp(section, "man", 3) == 0); + memcpy(cat_section, "cat", 3); return cat_section; } @@ -420,7 +423,8 @@ process_page(char *mandir, char *src, char *cat, enum Ziptype zipped) verbose ? "\t" : "", cat, link_name); } if (!pretend) - link(link_name, cat); + if (link(link_name, cat) < 0 && errno != EEXIST) + warn("%s %s: link", link_name, cat); return; } insert_hashtable(links, src_ino, src_dev, strdup(cat)); @@ -608,7 +612,8 @@ select_sections(const struct dirent *entry) static void process_mandir(char *dir_name, char *section) { - fchdir(starting_dir); + if (fchdir(starting_dir) < 0) + warn("fchdir"); if (already_visited(NULL, dir_name, section == NULL)) return; check_writable(dir_name);