From ba7a056d586f78954ac874a3bebc6325f7e6eeb1 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 27 Oct 2011 15:47:18 -0500 Subject: 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 --- lib/libalpm/util.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/util.h') 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 #include #include /* size_t */ +#include #include /* struct stat */ -#include /* struct archive */ #include /* fabs */ #include /* DBL_EPSILON */ +#include /* open, close */ + +#include /* struct archive */ #ifdef ENABLE_NLS #include /* 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(). */ -- cgit v1.2.3-24-g4f1b