diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-19 07:32:46 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-19 07:37:53 +0000 |
| commit | 846cb235853c553e7196c131dd0dd6a688116de3 (patch) | |
| tree | aebff297bc5e739130ffdae354e136f295fa557e /util/nvmutil/lib/file.c | |
| parent | f1fda8b43eb03be951846c6df9d0be81be84808e (diff) | |
nvmutil: remove memcmp/memcpy/strrchr/rename
i had this idea in my head of later porting this
to k&r c for fun. but screw it.
compiling on everything since 1989 is enough
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/lib/file.c')
| -rw-r--r-- | util/nvmutil/lib/file.c | 72 |
1 files changed, 8 insertions, 64 deletions
diff --git a/util/nvmutil/lib/file.c b/util/nvmutil/lib/file.c index 7b166744..63ac7d0d 100644 --- a/util/nvmutil/lib/file.c +++ b/util/nvmutil/lib/file.c @@ -5,6 +5,7 @@ * Safe file handling. */ +#include <sys/types.h> #include <sys/stat.h> #include <errno.h> @@ -66,7 +67,7 @@ xopen(int *fd_ptr, const char *path, int flags, struct stat *st) err(errno, "%s: file not seekable", path); } -/* Ensure x_i_rename() is durable by syncing the +/* Ensure rename() is durable by syncing the * directory containing the target file. */ @@ -112,8 +113,8 @@ fsync_dir(const char *path) if (dirbuf == NULL) goto err_fsync_dir; - x_v_memcpy(dirbuf, path, pathlen + 1); - slash = x_c_strrchr(dirbuf, '/'); + memcpy(dirbuf, path, pathlen + 1); + slash = strrchr(dirbuf, '/'); if (slash != NULL) { *slash = '\0'; @@ -294,17 +295,17 @@ new_tmpfile(int *fd, int local, const char *path) *dest = '.'; /* hidden file */ - x_v_memcpy(dest + (unsigned long)1, tmpname, tmpname_len); + memcpy(dest + (unsigned long)1, tmpname, tmpname_len); - x_v_memcpy(dest + (unsigned long)1 + tmpname_len, + memcpy(dest + (unsigned long)1 + tmpname_len, default_tmpname, tmpdir_len); } else { - x_v_memcpy(dest, base, tmpdir_len); + memcpy(dest, base, tmpdir_len); dest[tmpdir_len] = '/'; - x_v_memcpy(dest + tmpdir_len + 1, tmpname, tmpname_len); + memcpy(dest + tmpdir_len + 1, tmpname, tmpname_len); } dest[tmppath_len] = '\0'; @@ -906,63 +907,6 @@ try_err(int loop_err, int errval) return -1; } -/* portable rename(). WARNING: - * not powercut-safe. do this to - * use system rename: - * #define SYS_RENAME 1 - * - * written academically, but in reality, - * nearly all unix systems have rename() - */ - -int -x_i_rename(const char *src, const char *dst) -{ -#if defined(SYS_RENAME) &&\ - SYS_RENAME > 0 - return rename(src, dst); -#else - int sfd, dirfd; - ssize_t r; - char buf[8192]; - - sfd = open(src, O_RDONLY); - if (sfd < 0) - return -1; - - dirfd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0600); - if (dirfd < 0) { - x_i_close(sfd); - return -1; - } - - while ((r = read(sfd, buf, sizeof(buf))) > 0) { - ssize_t w = write(dirfd, buf, r); - if (w != r) { - x_i_close(sfd); - x_i_close(dirfd); - return -1; - } - } - - if (r < 0) { - x_i_close(sfd); - x_i_close(dirfd); - return -1; - } - - x_i_fsync(dirfd); - - x_i_close(sfd); - x_i_close(dirfd); - - if (unlink(src) < 0) - return -1; - - return 0; -#endif -} - int x_i_close(int fd) { |
