diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-03 04:11:29 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-03 04:11:29 +0000 |
| commit | 1c10eb524fefdc0afdd2501ca6f0df9e8a775882 (patch) | |
| tree | 188f9c38b392f0b4fc830652be915a7a7bae8499 | |
| parent | b8e05131237575356cff751c638f96bc3b844d07 (diff) | |
util/nvmutil: cleaner directory checking
opendir allocates resources and causes a bunch of other
error conditions which we need to catch.
use of stat is more efficient here.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 22 |
1 files changed, 12 insertions, 10 deletions
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 @@ -139,16 +139,6 @@ set_io_flags(int argc, char *argv[]) } 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) { struct stat st; @@ -172,6 +162,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) { if ((*f = open(l, p)) == -1) |
