summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lib/file.c
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-28 09:03:18 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-28 09:03:18 +0000
commit6643d9c1fa4d62e648d93ffc2841465d6422da22 (patch)
tree197ca3e8add5b89609618d9938b0fc4cfe2f4ab5 /util/libreboot-utils/lib/file.c
parent4ecdadb7a601b0613e65bf8547d17b39ed87153f (diff)
lbutils: unify xopen and open_on_eintr
use open_on_eintr for gbe files Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/lib/file.c')
-rw-r--r--util/libreboot-utils/lib/file.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/util/libreboot-utils/lib/file.c b/util/libreboot-utils/lib/file.c
index 96654640..4623748c 100644
--- a/util/libreboot-utils/lib/file.c
+++ b/util/libreboot-utils/lib/file.c
@@ -65,22 +65,6 @@ err_same_file:
return set_errno(saved_errno, ESTALE);
}
-void
-xopen(int *fd_ptr, const char *path, int flags, struct stat *st)
-{
- if ((*fd_ptr = open(path, flags)) < 0)
- err_exit(errno, "%s", path);
-
- if (fstat(*fd_ptr, st) < 0)
- err_exit(errno, "%s: stat", path);
-
- if (!S_ISREG(st->st_mode))
- err_exit(errno, "%s: not a regular file", path);
-
- if (lseek_on_eintr(*fd_ptr, 0, SEEK_CUR, 1, 1) == (off_t)-1)
- err_exit(errno, "%s: file not seekable", path);
-}
-
int
fsync_dir(const char *path)
{
@@ -568,8 +552,9 @@ free_and_set_null(char **buf)
}
void
-open_on_eintr(char *path,
- int *fd, int flags, mode_t mode)
+open_on_eintr(const char *path,
+ int *fd, int flags, mode_t mode,
+ struct stat *st)
{
int r = -1;
int saved_errno = errno;
@@ -594,6 +579,17 @@ open_on_eintr(char *path,
*fd = r;
+ if (st != NULL) {
+ if (fstat(*fd, st) < 0)
+ err_exit(errno, "%s: stat", path);
+
+ if (!S_ISREG(st->st_mode))
+ err_exit(errno, "%s: not a regular file", path);
+ }
+
+ if (lseek_on_eintr(*fd, 0, SEEK_CUR, 1, 1) == (off_t)-1)
+ err_exit(errno, "%s: file not seekable", path);
+
errno = saved_errno;
}
@@ -683,7 +679,7 @@ rootfs(void)
global_fs.rootfd = -1;
open_on_eintr("/", &global_fs.rootfd,
- O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0400);
+ O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0400, NULL);
if (global_fs.rootfd < 0)
return NULL;