src/wrappers.h
changeset 130 507895068f83
parent 125 5119178815d8
child 1513 e7f7e42385b5
     1.1 --- a/src/wrappers.h	Wed Mar 25 15:35:08 2015 +0100
     1.2 +++ b/src/wrappers.h	Thu Mar 26 15:30:21 2015 +0100
     1.3 @@ -1,13 +1,11 @@
     1.4  #pragma once
     1.5  
     1.6 +#include "platform.h"
     1.7 +
     1.8  #include <errno.h>
     1.9  #include <stdarg.h>
    1.10 -
    1.11 -#ifdef WIN32
    1.12 -#include "platform_windows.h"
    1.13 -#endif
    1.14 -
    1.15 -#ifdef EOF // stdio.h
    1.16 +#include <stdio.h>
    1.17 +#include <fcntl.h>
    1.18  
    1.19  static inline FILE * Fopen(const char *filename, const char *mode)
    1.20  {
    1.21 @@ -19,7 +17,6 @@
    1.22  
    1.23      return f;
    1.24  }
    1.25 -#define fopen >@<
    1.26  
    1.27  static inline FILE * Fdopen(int fildes, const char *mode)
    1.28  {
    1.29 @@ -31,7 +28,6 @@
    1.30  
    1.31      return f;
    1.32  }
    1.33 -#define fdopen >@<
    1.34  
    1.35  static inline char *Fgets(char * str, int size, FILE * stream)
    1.36  {
    1.37 @@ -43,7 +39,6 @@
    1.38  
    1.39      return s;
    1.40  }
    1.41 -#define fgets >@<
    1.42  
    1.43  static inline int Fputs(const char *str, FILE * stream)
    1.44  {
    1.45 @@ -55,7 +50,6 @@
    1.46  
    1.47      return r;
    1.48  }
    1.49 -#define fputs >@<
    1.50  
    1.51  static inline int Fclose(FILE *stream)
    1.52  {
    1.53 @@ -67,7 +61,6 @@
    1.54  
    1.55      return r;
    1.56  }
    1.57 -#define fclose >@<
    1.58  
    1.59  static inline FILE * Freopen(
    1.60          const char *filename,
    1.61 @@ -83,7 +76,6 @@
    1.62  
    1.63      return f;
    1.64  }
    1.65 -#define freopen >@<
    1.66  
    1.67  static inline int Fprintf(FILE * stream, const char * format, ...)
    1.68  {
    1.69 @@ -100,7 +92,6 @@
    1.70  
    1.71      return n;
    1.72  }
    1.73 -#define fprintf >@<
    1.74  
    1.75  static inline size_t Fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
    1.76  {
    1.77 @@ -115,7 +106,6 @@
    1.78  
    1.79      return r;
    1.80  }
    1.81 -#define fwrite >@<
    1.82  
    1.83  static inline size_t Fread(void *ptr, size_t size, size_t nitems, FILE *stream)
    1.84  {
    1.85 @@ -130,7 +120,6 @@
    1.86  
    1.87      return r;
    1.88  }
    1.89 -#define fread >@<
    1.90  
    1.91  static inline int Fflush(FILE *stream)
    1.92  {
    1.93 @@ -142,11 +131,6 @@
    1.94  
    1.95      return r;
    1.96  }
    1.97 -#define fflush >@<
    1.98 -
    1.99 -#endif // stdio.h
   1.100 -
   1.101 -#ifdef F_OK // unistd.h
   1.102  
   1.103  static inline int Mkstemp(char *template)
   1.104  {
   1.105 @@ -158,7 +142,6 @@
   1.106  
   1.107      return fd;
   1.108  }
   1.109 -#define mkstemp >@<
   1.110  
   1.111  static inline int Close(int fildes)
   1.112  {
   1.113 @@ -170,161 +153,3 @@
   1.114  
   1.115      return r;
   1.116  }
   1.117 -#define close >@<
   1.118 -
   1.119 -static inline ssize_t Write(int fildes, const void *buf, size_t nbyte)
   1.120 -{
   1.121 -    ssize_t r;
   1.122 -
   1.123 -    do {
   1.124 -        r = write(fildes, buf, nbyte);
   1.125 -    } while (r == -1 && errno == EINTR);
   1.126 -
   1.127 -    return r;
   1.128 -}
   1.129 -#define write >@<
   1.130 -
   1.131 -static inline ssize_t Read(int fildes, void *buf, size_t nbyte)
   1.132 -{
   1.133 -    ssize_t r;
   1.134 -
   1.135 -    do {
   1.136 -        r = read(fildes, buf, nbyte);
   1.137 -    } while (r == -1 && errno == EINTR);
   1.138 -
   1.139 -    return r;
   1.140 -}
   1.141 -#define read >@<
   1.142 -
   1.143 -static inline int Ftruncate(int fildes, off_t length)
   1.144 -{
   1.145 -    int r;
   1.146 -
   1.147 -    do {
   1.148 -        r = ftruncate(fildes, length);
   1.149 -    } while (r == -1 && errno == EINTR);
   1.150 -
   1.151 -    return r;
   1.152 -}
   1.153 -#define ftruncate >@<
   1.154 -
   1.155 -static inline int Dup2(int fildes, int fildes2)
   1.156 -{
   1.157 -    int fd;
   1.158 -
   1.159 -    do {
   1.160 -        fd = dup2(fildes, fildes2);
   1.161 -    } while (fd == -1 && errno == EINTR);
   1.162 -
   1.163 -    return fd;
   1.164 -}
   1.165 -#define dup2 >@<
   1.166 -
   1.167 -#endif
   1.168 -
   1.169 -#ifdef FD_CLR // select.h
   1.170 -
   1.171 -static inline int Select(
   1.172 -        int nfds,
   1.173 -        fd_set *readfds,
   1.174 -        fd_set *writefds,
   1.175 -        fd_set *errorfds,
   1.176 -        struct timeval *timeout
   1.177 -    )
   1.178 -{
   1.179 -    int r;
   1.180 -
   1.181 -    do {
   1.182 -        r = select(nfds, readfds, writefds, errorfds, timeout);
   1.183 -    } while (r == -1 && errno == EINTR);
   1.184 -
   1.185 -    return r;
   1.186 -}
   1.187 -#define select >@<
   1.188 -
   1.189 -#endif // select.h
   1.190 -
   1.191 -#ifdef F_SETLKW // fcntl.h
   1.192 -
   1.193 -static inline int Fcntl(int fildes, int cmd, void *structure)
   1.194 -{
   1.195 -    int r;
   1.196 -
   1.197 -    do {
   1.198 -        r = fcntl(fildes, cmd, structure);
   1.199 -    } while (r == -1 && errno == EINTR);
   1.200 -
   1.201 -    return r;
   1.202 -}
   1.203 -// fnctl does only risk EINTR if cmd == F_SETLKW
   1.204 -
   1.205 -static inline int Open(const char *path, int oflag, ...)
   1.206 -{
   1.207 -    int fd;
   1.208 -
   1.209 -    do {
   1.210 -        fd = open(path, oflag, 0);
   1.211 -    } while (fd == -1 && errno == EINTR);
   1.212 -
   1.213 -    return fd;
   1.214 -}
   1.215 -#define open >@<
   1.216 -
   1.217 -static inline int Creat(const char *path, mode_t mode)
   1.218 -{
   1.219 -    int fd;
   1.220 -
   1.221 -    do {
   1.222 -        fd = creat(path, mode);
   1.223 -    } while (fd == -1 && errno == EINTR);
   1.224 -
   1.225 -    return fd;
   1.226 -}
   1.227 -#define creat >@<
   1.228 -
   1.229 -#endif // fcntl.h
   1.230 -
   1.231 -#ifdef MSG_PEEK // socket.h
   1.232 -
   1.233 -static inline ssize_t Recv(int socket, void *buffer, size_t length, int flags)
   1.234 -{
   1.235 -    ssize_t r;
   1.236 -
   1.237 -    do {
   1.238 -        r = recv(socket, buffer, length, flags);
   1.239 -    } while (r == -1 && errno == EINTR);
   1.240 -
   1.241 -    return r;
   1.242 -}
   1.243 -#define recv >@<
   1.244 -
   1.245 -static inline ssize_t Send(int socket, const void *buffer, size_t length, int flags)
   1.246 -{
   1.247 -    ssize_t r;
   1.248 -
   1.249 -    do {
   1.250 -        r = send(socket, buffer, length, flags);
   1.251 -    } while (r == -1 && errno == EINTR);
   1.252 -
   1.253 -    return r;
   1.254 -}
   1.255 -#define send >@<
   1.256 -
   1.257 -#endif // socket.h
   1.258 -
   1.259 -#ifdef WNOHANG // wait.h
   1.260 -
   1.261 -static inline pid_t Waitpid(pid_t pid, int *stat_loc, int options)
   1.262 -{
   1.263 -    pid_t r;
   1.264 -
   1.265 -    do {
   1.266 -        r = waitpid(pid, stat_loc, options);
   1.267 -    } while (r == -1 && errno == EINTR);
   1.268 -
   1.269 -    return r;
   1.270 -}
   1.271 -#define waitpid >@<
   1.272 -
   1.273 -#endif
   1.274 -