diff options
author | Dan McGee <dan@archlinux.org> | 2011-10-27 22:47:18 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-11-01 16:27:31 +0100 |
commit | ba7a056d586f78954ac874a3bebc6325f7e6eeb1 (patch) | |
tree | 03172fa34a61ab78d24c0b46747aaff9ca4c4875 /lib/libalpm/util.h | |
parent | a4ce3edf95f148bc6eac16b6edd9bc281c7745af (diff) | |
download | pacman-ba7a056d586f78954ac874a3bebc6325f7e6eeb1.tar.gz pacman-ba7a056d586f78954ac874a3bebc6325f7e6eeb1.tar.xz |
Add OPEN() and CLOSE() util macros
These wrap the normal open() and close() low-level I/O calls and ensure
EINTR is handled correctly.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.h')
-rw-r--r-- | lib/libalpm/util.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 8d20a281..36e4960f 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -35,10 +35,13 @@ #include <string.h> #include <stdarg.h> #include <stddef.h> /* size_t */ +#include <sys/types.h> #include <sys/stat.h> /* struct stat */ -#include <archive.h> /* struct archive */ #include <math.h> /* fabs */ #include <float.h> /* DBL_EPSILON */ +#include <fcntl.h> /* open, close */ + +#include <archive.h> /* struct archive */ #ifdef ENABLE_NLS #include <libintl.h> /* here so it doesn't need to be included elsewhere */ @@ -81,6 +84,13 @@ #define ALPM_BUFFER_SIZE 8192 #endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#define OPEN(fd, path, flags) do { fd = open(path, flags | O_BINARY); } while(fd == -1 && errno == EINTR) +#define CLOSE(fd) do { int ret; do { ret = close(fd); } while(ret == -1 && errno == EINTR); } while(0) + /** * Used as a buffer/state holder for _alpm_archive_fgets(). */ |