mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-16 23:08:49 +02:00
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>
This commit is contained in:
+12
-10
@@ -138,16 +138,6 @@ set_io_flags(int argc, char *argv[])
|
|||||||
flags = O_RDONLY;
|
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
|
void
|
||||||
openFiles(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
|
void
|
||||||
xopen(int *f, const char *l, int p, struct stat *st)
|
xopen(int *f, const char *l, int p, struct stat *st)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user