diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index c171a1b8..36b29af2 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -138,16 +138,6 @@ set_io_flags(int argc, char *argv[]) flags = O_RDONLY; } -void -checkdir(const char *path) -{ - if (opendir(path) != NULL) - err(set_err(EISDIR), "%s", path); - if (errno == ENOTDIR) - errno = 0; - err_if(errno); -} - void openFiles(void) { @@ -171,6 +161,18 @@ openFiles(void) } } +void +checkdir(const char *path) +{ + struct stat st; + err_if (stat(path, &st) == -1); + if (S_ISDIR(st.st_mode)) + err(set_err(EISDIR), "%s", path); + if (errno == ENOTDIR) + errno = 0; + err_if(errno); +} + void xopen(int *f, const char *l, int p, struct stat *st) {