--- src/globbing.c +++ src/globbing.c 2007-09-19 13:35:04.128822519 +0200 @@ -28,7 +28,9 @@ #endif /* HAVE_CONFIG_H */ /* Need _GNU_SOURCE for FNM_CASEFOLD. */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include @@ -340,13 +342,22 @@ char **look_for_file (const char *unesc_ /* allow lookups like "3x foo" to match "../man3/foo.3x" */ if ((layout & LAYOUT_GNU) && CTYPE (isdigit, *sec) && sec[1] != '\0') { - path = strappend (path, hier, cat ? "/cat" : "/man", "\t", - NULL); - *strrchr (path, '\t') = *sec; - pattern = end_pattern (strappend (pattern, name, NULL), sec); + off_t nptr, nsec; - status = match_in_directory (path, pattern, !match_case, - &gbuf); + path = strappend (path, hier, cat ? "/cat" : "/man", NULL); + nptr = strlen(path); + path = strappend (path, sec, NULL); + nsec = nptr + strlen(sec); + + while (nsec > nptr) { + *(path + nsec--) = '\0'; + if (pattern) + *pattern = '\0'; + pattern = end_pattern (strappend (pattern, name, NULL), sec); + status = match_in_directory (path, pattern, !match_case, &gbuf); + if ((status == 0) && (gbuf.gl_pathc != 0)) + break; + } } /* AIX glob.h doesn't define GLOB_NOMATCH and the manpage is vague