aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
index 1788d7141..bc16905ea 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -21,7 +21,13 @@
#include "../config.h"
+#include <unistd.h>
+#include <stdlib.h>
#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
char *myFgets(char *buffer, int bufferSize, FILE * fp);
@@ -37,4 +43,39 @@ char *appendToString(char *dest, const char *src);
unsigned long readLEuint32(const unsigned char *p);
+/* trivial functions, keep them inlined */
+static inline int xopen(const char *path, int flags, mode_t mode)
+{
+ int fd;
+ while(0>(fd = open(path,flags,mode)) && errno == EINTR);
+ return fd;
+}
+
+static inline void xclose(int fd)
+{
+ while (close(fd) && errno == EINTR);
+}
+
+static inline ssize_t xread(int fd, void *buf, size_t len)
+{
+ ssize_t nr;
+ while (1) {
+ nr = read(fd, buf, len);
+ if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
+ continue;
+ return nr;
+ }
+}
+
+static inline ssize_t xwrite(int fd, const void *buf, size_t len)
+{
+ ssize_t nr;
+ while (1) {
+ nr = write(fd, buf, len);
+ if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
+ continue;
+ return nr;
+ }
+}
+
#endif