00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __XrdWin32_h__
00027 #define __XrdWin32_h__
00028
00029 #include <errno.h>
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <io.h>
00033 #include <time.h>
00034 #include <direct.h>
00035 #include <sys/types.h>
00036 #include <Winsock2.h>
00037
00038 #ifndef POLLIN
00039 #define POLLIN 0x0001
00040 #define POLLPRI 0x0002
00041 #define POLLOUT 0x0004
00042 #define POLLERR 0x0008
00043 #define POLLHUP 0x0010
00044 #define POLLNVAL 0x0020
00045 #define POLLRDNORM 0x0001
00046 #define POLLWRNORM 0x0002
00047 #define POLLRDBAND 0x0000
00048
00049 struct pollfd {
00050 unsigned int fd;
00051 short events;
00052 short revents;
00053 };
00054 #endif
00055
00056 #define EMSGSIZE WSAEMSGSIZE
00057 #define EAFNOSUPPORT WSAEAFNOSUPPORT
00058 #define EWOULDBLOCK WSAEWOULDBLOCK
00059 #define ECONNRESET WSAECONNRESET
00060 #define EINPROGRESS WSAEINPROGRESS
00061 #define ENOBUFS WSAENOBUFS
00062 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
00063 #define ECONNREFUSED WSAECONNREFUSED
00064 #define EBADFD WSAENOTSOCK
00065 #define EOPNOTSUPP WSAEOPNOTSUPP
00066 #define ENETUNREACH WSAENETUNREACH
00067 #define EHOSTUNREACH WSAEHOSTUNREACH
00068 #define EHOSTDOWN WSAEHOSTDOWN
00069 #define EISCONN WSAEISCONN
00070 #define ECONNRESET WSAECONNRESET
00071 #define ECONNABORTED WSAECONNABORTED
00072 #define ESHUTDOWN WSAESHUTDOWN
00073 #ifndef ETIMEDOUT
00074 #define ETIMEDOUT WSAETIMEDOUT
00075 #endif
00076 #define ETXTBSY 26
00077
00078 #define WEXITSTATUS(w) (((w) >> 8) & 0xff)
00079 #define WIFEXITED(w) (((w) & 0xff) == 0)
00080 #define WTERMSIG(w) ((w) & 0x7f)
00081 #define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
00082
00083 #ifndef S_ISDIR
00084 #define S_ISDIR(m) (((m)&(S_IFMT)) == (S_IFDIR))
00085 #endif
00086 #ifndef S_ISREG
00087 #define S_ISREG(m) (((m)&(S_IFMT)) == (S_IFREG))
00088 #endif
00089 #ifndef S_IXUSR
00090 #define S_IXUSR 00100
00091 #endif
00092 #ifndef S_IRGRP
00093 #define S_IRGRP 00040
00094 #endif
00095 #ifndef S_IXGRP
00096 #define S_IXGRP 00010
00097 #endif
00098 #ifndef S_IROTH
00099 #define S_IROTH 00004
00100 #endif
00101 #ifndef S_IXOTH
00102 #define S_IXOTH 00001
00103 #endif
00104 #ifndef S_IRUSR
00105 #define S_IRUSR S_IREAD
00106 #endif
00107 #ifndef S_IWUSR
00108 #define S_IWUSR S_IWRITE
00109 #endif
00110 #ifndef S_IWGRP
00111 #define S_IWGRP 000020
00112 #endif
00113 #ifndef S_IWOTH
00114 #define S_IWOTH 000002
00115 #endif
00116 #ifndef S_IRWXU
00117 #define S_IRWXU 0000700
00118 #endif
00119 #ifndef S_IRWXG
00120 #define S_IRWXG 0000070
00121 #endif
00122
00123 #ifndef S_ISFIFO
00124 # ifndef S_IFIFO
00125 # define S_IFIFO 0010000
00126 # endif
00127 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
00128 #endif
00129
00130 #ifndef S_IFSOCK
00131 #define S_IFSOCK 0140000
00132 #endif
00133
00134 #define _SC_PAGESIZE 1
00135
00136 #define F_GETFL 1
00137 #define F_SETFL 2
00138 #define F_GETFD 4
00139 #define F_SETFD 8
00140
00141 #define FD_CLOEXEC 1
00142 #define O_NDELAY 2
00143 #define O_NONBLOCK 4
00144
00145 #define X_OK 1
00146 #define W_OK 2
00147 #define R_OK 4
00148
00149 #define RTLD_NOW 0x0001
00150
00151 #ifndef STDIN_FILENO
00152 #define STDIN_FILENO 0
00153 #define STDOUT_FILENO 1
00154 #define STDERR_FILENO 2
00155 #endif
00156
00157 #ifndef fsync
00158 #define fsync(a) _commit(a)
00159 #endif
00160
00161 #ifndef socklen_t
00162 #define socklen_t int
00163 #endif
00164
00165 #ifndef SOCKLEN_t
00166 #define SOCKLEN_t int
00167 #endif
00168
00169 #ifndef snprintf
00170 #define snprintf _snprintf
00171 #endif
00172
00173 #ifndef caddr_t
00174 typedef char* caddr_t;
00175 #endif
00176
00177 #ifndef pid_t
00178 typedef int pid_t;
00179 #endif
00180
00181 #ifndef mode_t
00182 typedef unsigned int mode_t;
00183 #endif
00184
00185 #ifndef uint16_t
00186 typedef unsigned short uint16_t;
00187 #endif
00188
00189 struct timezone {
00190 int tz_minuteswest;
00191 int tz_dsttime;
00192 };
00193
00194 inline int poll(struct pollfd *fds, unsigned int nfds, int timeout)
00195 {
00196 unsigned int max_fd = 0;
00197 unsigned int i;
00198
00199 fd_set *open_fds, *read_fds, *write_fds, *except_fds;
00200 struct timeval tv = { timeout / 1000, (timeout % 1000) * 1000 };
00201
00202 for (i = 0; i < nfds; ++i) {
00203 if (fds[i].fd > max_fd) {
00204 max_fd = fds[i].fd;
00205 }
00206 }
00207
00208 size_t fds_size = (max_fd + 1) * sizeof (fd_set);
00209
00210 open_fds = (fd_set *) malloc (fds_size);
00211 read_fds = (fd_set *) malloc (fds_size);
00212 write_fds = (fd_set *) malloc (fds_size);
00213 except_fds = (fd_set *) malloc (fds_size);
00214
00215 if (!open_fds || !read_fds || !write_fds || !except_fds) {
00216 return -1;
00217 }
00218
00219 FD_ZERO(open_fds) ;
00220 FD_ZERO(read_fds) ;
00221 FD_ZERO(write_fds) ;
00222 FD_ZERO(except_fds) ;
00223
00224 for ( i = 0; i < nfds; ++i) {
00225 FD_SET (fds[i].fd, open_fds);
00226 if (fds[i].events & POLLIN)
00227 FD_SET (fds[i].fd, read_fds);
00228 if (fds[i].events & POLLOUT)
00229 FD_SET (fds[i].fd, write_fds);
00230 if (fds[i].events & POLLPRI)
00231 FD_SET (fds[i].fd, except_fds);
00232 }
00233
00234
00235 int ret = select(max_fd + 1, read_fds, write_fds, except_fds, timeout < 0 ? NULL : &tv);
00236
00237 for (i = 0; i < nfds; ++i) {
00238 if (!FD_ISSET (fds[i].fd, open_fds))
00239 fds[i].revents = POLLNVAL;
00240 else if (ret < 0)
00241 fds[i].revents = POLLERR;
00242 else {
00243 fds[i].revents = 0;
00244 if (FD_ISSET (fds[i].fd, read_fds))
00245 fds[i].revents |= POLLIN;
00246 if (FD_ISSET (fds[i].fd, write_fds))
00247 fds[i].revents |= POLLOUT;
00248 if (FD_ISSET (fds[i].fd, except_fds))
00249 fds[i].revents |= POLLPRI;
00250 }
00251 }
00252
00253 free(open_fds);
00254 free(read_fds);
00255 free(write_fds);
00256 free(except_fds);
00257
00258 return ret;
00259 }
00260
00261 struct iovec {
00262 u_long iov_len;
00263 char FAR *iov_base;
00264 };
00265
00266 inline int lrint(double n) { return (int)n; };
00267
00268 extern void gethostbyname_r(const char *inetName, struct hostent *hent, char *buff,
00269 int buffsize, struct hostent **hp, int *rc);
00270 extern void gethostbyaddr_r(char *addr, size_t len, int type, struct hostent *hent, char *buff,
00271 size_t buffsize, struct hostent **hp, int *rc);
00272 extern int getservbyname_r(const char *servname, const char *servtype, struct servent *sent,
00273 char *buff, size_t buffsize, struct servent **sp);
00274 extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
00275 extern void *dlopen(const char *libPath, int opt);
00276 extern BOOL dlclose(void *lib);
00277 extern void *dlsym(void *libHandle, const char *pname);
00278 extern char *dlerror();
00279 extern pid_t fork();
00280 extern const char *inet_ntop(int af, const void *src, char *dst, size_t size);
00281 extern int sysconf(int what);
00282 extern int fcntl(int fd, int cmd, long arg);
00283 extern int close(int fd);
00284 extern int writev(int sock, const struct iovec iov[], int nvecs);
00285 extern int posix_memalign (void **memptr, size_t alignment, size_t size);
00286 extern char *index(const char *str, int c);
00287 extern char *cuserid(char * s);
00288
00289 #ifndef localtime_r
00290 #define localtime_r( _clock, _result ) \
00291 ( *(_result) = *localtime( (_clock) ), \
00292 (_result) )
00293 #endif
00294
00295 #define pipe(a) _pipe(a, 256, O_BINARY)
00296 #define rindex strrchr
00297 #define sleep(s) Sleep(s*1000)
00298
00299 #define strtoll(a, b, c) _strtoi64(a, b, c)
00300 #define ntohll(x) (((_int64)(ntohl((int)((x << 32) >> 32))) << 32) | (unsigned int)ntohl(((int)(x >> 32))))
00301 #define htonll(x) ntohll(x)
00302 #define random() rand()
00303
00304 #define usleep(x) Sleep(x / 1000)
00305 #define lstat(a, b) stat(a, b)
00306 #define memalign(a, b) _aligned_malloc(b, a)
00307 struct sockaddr_un { unsigned short sun_family; char sun_path[128]; };
00308 #define setpgid(x,y)
00309 #define fsync(a) _commit(a)
00310 #define ssize_t SSIZE_T
00311
00312 #endif // __XrdWin32_h__
00313