diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:52:28 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-16 16:52:28 +0000 |
| commit | 849a73012eea818e05d6b03ecf427dcdcf8a5867 (patch) | |
| tree | a236943da60862eab98c3fdfdcce33fdad3cf566 /util | |
| parent | fb4f2630056bf4c61c82785c9cc94946b4696d5f (diff) | |
util/nvmutil: portable fchmod
and with that, now the code compiles on gcc
with -std=c90 -pedantic
with -Werror and -Wall -Wextra
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 3cea175d..7731d31f 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -491,6 +491,7 @@ static void *x_v_memcpy(void *dst, const void *src, unsigned long n); static int x_i_memcmp(const void *a, const void *b, unsigned long n); +static int x_i_fchmod(int fd, mode_t mode); /* * Sizes in bytes: @@ -2954,7 +2955,7 @@ new_tmpfile(int *fd, int local, const char *path) if (fd_tmp == -1) goto err_new_tmpfile; - if (fchmod(fd_tmp, 0600) == -1) + if (x_i_fchmod(fd_tmp, 0600) == -1) goto err_new_tmpfile; if (lock_file(fd_tmp) == -1) @@ -3175,3 +3176,42 @@ x_i_memcmp(const void *a, const void *b, unsigned long n) return 0; } + +static int +x_i_fchmod(int fd, mode_t mode) +{ + char path[32]; + char tmp[16]; + int i = 0; + int j = 0; + int n; + + /* build "/dev/fd/" */ + path[i++] = '/'; + path[i++] = 'd'; + path[i++] = 'e'; + path[i++] = 'v'; + path[i++] = '/'; + path[i++] = 'f'; + path[i++] = 'd'; + path[i++] = '/'; + + /* convert fd to decimal */ + n = fd; + + if (n == 0) { + path[i++] = '0'; + } else { + while (n > 0) { + tmp[j++] = (char)('0' + (n % 10)); + n /= 10; + } + + while (j > 0) + path[i++] = tmp[--j]; + } + + path[i] = '\0'; + + return chmod(path, mode); +} |
