Changeset View
Changeset View
Standalone View
Standalone View
contrib/mandoc/read.c
| Show First 20 Lines • Show All 622 Lines • ▼ Show 20 Lines | mparse_readfd(struct mparse *curp, int fd, const char *filename) | ||||
| curp->line = save_lineno; | curp->line = save_lineno; | ||||
| if (save_filename != NULL) | if (save_filename != NULL) | ||||
| mandoc_msg_setinfilename(save_filename); | mandoc_msg_setinfilename(save_filename); | ||||
| } | } | ||||
| int | int | ||||
| mparse_open(struct mparse *curp, const char *file) | mparse_open(struct mparse *curp, const char *file) | ||||
| { | { | ||||
| char *cp; | const char *cp; | ||||
| int fd, save_errno; | int fd, save_errno; | ||||
| cp = strrchr(file, '.'); | cp = strrchr(file, '.'); | ||||
| curp->gzip = (cp != NULL && ! strcmp(cp + 1, "gz")); | curp->gzip = (cp != NULL && ! strcmp(cp + 1, "gz")); | ||||
| /* First try to use the filename as it is. */ | /* First try to use the filename as it is. */ | ||||
| if ((fd = open(file, O_RDONLY)) != -1) | if ((fd = open(file, O_RDONLY)) != -1) | ||||
| return fd; | return fd; | ||||
| /* | /* | ||||
| * If that doesn't work and the filename doesn't | * If that doesn't work and the filename doesn't | ||||
| * already end in .gz, try appending .gz. | * already end in .gz, try appending .gz. | ||||
| */ | */ | ||||
| if ( ! curp->gzip) { | if ( ! curp->gzip) { | ||||
| char *fn; | |||||
| save_errno = errno; | save_errno = errno; | ||||
| mandoc_asprintf(&cp, "%s.gz", file); | mandoc_asprintf(&fn, "%s.gz", file); | ||||
| fd = open(cp, O_RDONLY); | fd = open(fn, O_RDONLY); | ||||
| free(cp); | free(fn); | ||||
| errno = save_errno; | errno = save_errno; | ||||
| if (fd != -1) { | if (fd != -1) { | ||||
| curp->gzip = 1; | curp->gzip = 1; | ||||
| return fd; | return fd; | ||||
| } | } | ||||
| } | } | ||||
| /* Neither worked, give up. */ | /* Neither worked, give up. */ | ||||
| ▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines | |||||