diff options
Diffstat (limited to 'util/libreboot-utils/include/common.h')
| -rw-r--r-- | util/libreboot-utils/include/common.h | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index 12c6c486..48831ea3 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -26,6 +26,24 @@ #include <unistd.h> #endif +/* dangerously cool macros: + */ + +#define SUCCESS(x) ((x) >= 0) + +/* syscalls can set errno even on success; this + * is rare, but permitted. in various functions, we + * reset errno on success, to what the caller had, + * but we must still honour what was returned. + * + * lib/file.c is littered with examples + */ +#define reset_caller_errno(return_value) \ + do { \ + if (SUCCESS(return_value) && (!errno)) \ + errno = saved_errno; \ + } while (0) + #define items(x) (sizeof((x)) / sizeof((x)[0])) /* system prototypes @@ -88,17 +106,6 @@ int fchmod(int fd, mode_t mode); #define MAX_ZERO_RW_RETRY 5 #endif -#ifndef REAL_POS_IO -#define REAL_POS_IO 1 -#endif - -#ifndef LOOP_EAGAIN -#define LOOP_EAGAIN 1 -#endif -#ifndef LOOP_EINTR -#define LOOP_EINTR 1 -#endif - #ifndef _FILE_OFFSET_BITS #define _FILE_OFFSET_BITS 64 #endif @@ -179,9 +186,6 @@ int fchmod(int fd, mode_t mode); #define ARGC_3 3 #define ARGC_4 4 -#define NO_LOOP_EAGAIN 0 -#define NO_LOOP_EINTR 0 - /* For checking if an fd is a normal file. * Portable for old Unix e.g. v7 (S_IFREG), * 4.2BSD (S_IFMT), POSIX (S_ISREG). @@ -477,18 +481,15 @@ ssize_t rw_gbe_file_exact(int fd, unsigned char *mem, size_t nrw, int fsync_dir(const char *path); ssize_t rw_file_exact(int fd, unsigned char *mem, size_t len, - off_t off, int rw_type, int loop_eagain, int loop_eintr, - size_t max_retries, int off_reset); -ssize_t prw(int fd, void *mem, size_t nrw, - off_t off, int rw_type, int loop_eagain, int loop_eintr, - int off_reset); + off_t off, int rw_type, size_t max_retries, int off_reset); +ssize_t rw(int fd, void *mem, size_t nrw, + off_t off, int rw_type); int io_args(int fd, void *mem, size_t nrw, off_t off, int rw_type); int check_file(int fd, struct stat *st); ssize_t rw_over_nrw(ssize_t r, size_t nrw); off_t lseek_on_eintr(int fd, off_t off, int whence, int loop_eagain, int loop_eintr); -int try_err(int loop_err, int errval); ssize_t read_on_eintr(int fd, void *buf, size_t count); ssize_t write_on_eintr(int fd, @@ -497,12 +498,16 @@ ssize_t pread_on_eintr(int fd, void *buf, size_t count, off_t off); ssize_t pwrite_on_eintr(int fd, void *buf, size_t count, off_t off); +int off_retry(int saved_errno, off_t rval); +int sys_retry(int saved_errno, long rval); +int fs_retry(int saved_errno, int rval); +int rw_retry(int saved_errno, ssize_t rval); /* Error handling and cleanup */ void usage(void); -int set_errno(int saved_errno, int fallback); +int with_fallback_errno(int fallback); void err_exit(int nvm_errval, const char *msg, ...); func_t errhook(func_t ptr); /* hook function for cleanup on err */ const char *lbgetprogname(void); @@ -519,7 +524,7 @@ int new_tmpdir(int *fd, char **path, char *tmpdir, int new_tmp_common(int *fd, char **path, int type, char *tmpdir, const char *template); int mkhtemp_try_create(int dirfd, - struct stat *st_dir_initial, + struct stat *st_dir_first, char *fname_copy, char *p, size_t xc, @@ -528,7 +533,7 @@ int mkhtemp_try_create(int dirfd, int type); int mkhtemp_tmpfile_linux(int dirfd, - struct stat *st_dir_initial, + struct stat *st_dir_first, char *fname_copy, char *p, size_t xc, @@ -536,7 +541,7 @@ mkhtemp_tmpfile_linux(int dirfd, struct stat *st); int mkhtemp(int *fd, struct stat *st, char *template, int dirfd, const char *fname, - struct stat *st_dir_initial, int type); + struct stat *st_dir_first, int type); int world_writeable_and_sticky(const char *s, int sticky_allowed, int always_sticky); int same_dir(const char *a, const char *b); @@ -557,7 +562,7 @@ int fs_rename_at(int olddirfd, const char *old, int newdirfd, const char *new); int fs_open(const char *path, int flags); void free_and_set_null(char **buf); -void open_on_eintr(const char *path, int *fd, int flags, mode_t mode, +void open_file_on_eintr(const char *path, int *fd, int flags, mode_t mode, struct stat *st); struct filesystem *rootfs(void); int fs_resolve_at(int dirfd, const char *path, int flags); @@ -567,7 +572,7 @@ int fs_open_component(int dirfd, const char *name, int flags, int is_last); int fs_dirname_basename(const char *path, char **dir, char **base, int allow_relative); -int openat2p(int dirfd, const char *path, +int openat_on_eintr(int dirfd, const char *path, int flags, mode_t mode); int mkdirat_on_eintr(int dirfd, const char *pathname, mode_t mode); @@ -631,10 +636,6 @@ typedef char bool_skip_checksum_read[(SKIP_CHECKSUM_READ==0)?1:-1]; typedef char bool_checksum_read[(CHECKSUM_READ==1)?1:-1]; typedef char bool_skip_checksum_write[(SKIP_CHECKSUM_WRITE==0)?1:-1]; typedef char bool_checksum_write[(CHECKSUM_WRITE==1)?1:-1]; -typedef char bool_loop_eintr[(LOOP_EINTR==1||LOOP_EINTR==0)?1:-1]; -typedef char bool_loop_eagain[(LOOP_EAGAIN==1||LOOP_EAGAIN==0)?1:-1]; -typedef char bool_no_loop_eintr[(NO_LOOP_EINTR==0)?1:-1]; -typedef char bool_no_loop_eagain[(NO_LOOP_EAGAIN==0)?1:-1]; typedef char bool_off_err[(OFF_ERR==0)?1:-1]; typedef char bool_off_reset[(OFF_RESET==0||OFF_RESET==1)?1:-1]; |
