9a4bfeab44e7c3575ae10059fc069192c1165126 markd Fri Nov 18 15:57:26 2022 -0800 improve error message by when bedToBigBed is given magic name stdin diff --git src/lib/osunix.c src/lib/osunix.c index 7594fa5..ce81386 100644 --- src/lib/osunix.c +++ src/lib/osunix.c @@ -744,39 +744,40 @@ boolean isRegularFile(char *fileName) /* Return TRUE if fileName is a regular file. */ { struct stat st; if (stat(fileName, &st) < 0) return FALSE; if (S_ISREG(st.st_mode)) return TRUE; return FALSE; } void mustBeReadableAndRegularFile(char *fileName) /* errAbort if fileName is a regular file and readable. */ { -int fd = open(fileName, O_RDONLY); - -if (fd < 0) - errAbort("Cannot open file (%s). It doesn't exist or is not readable.", fileName); - -close(fd); +// check if file exists and is readable, including the +// magic "stdin" name. +FILE *fh = mustOpen(fileName, "r"); +struct stat st; +if (fstat(fileno(fh), &st) < 0) + errnoAbort("stat failed on: %s", fileName); // should never happen +carefulClose(&fh); -if (!isRegularFile(fileName)) - errAbort("input file (%s) must be a regular file. Pipes or other special devices can't be used.", fileName); +if (!S_ISREG(st.st_mode)) + errAbort("input file (%s) must be a regular file. Pipes or other special devices can't be used here.", fileName); } char *mustReadSymlinkExt(char *path, struct stat *sb) /* Read symlink or abort. FreeMem the returned value. */ { ssize_t nbytes, bufsiz; // determine whether the buffer returned was truncated. bufsiz = sb->st_size + 1; char *symPath = needMem(bufsiz); nbytes = readlink(path, symPath, bufsiz); if (nbytes == -1) errnoAbort("readlink failure on symlink %s", path); if (nbytes == bufsiz) errAbort("readlink returned buffer truncated\n"); return symPath;