13531feb863db3591e2c7e61cf45289d3770bc7c braney Mon Oct 31 11:49:46 2022 -0700 for bigWig and bigBed build utilities, check to make sure the file isn't a pipe diff --git src/lib/osunix.c src/lib/osunix.c index 9bb3f9f..7594fa5 100644 --- src/lib/osunix.c +++ src/lib/osunix.c @@ -741,30 +741,44 @@ return FALSE; } 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); + +if (!isRegularFile(fileName)) + errAbort("input file (%s) must be a regular file. Pipes or other special devices can't be used.", 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; }