summaryrefslogtreecommitdiffstats
path: root/xpa/xport.h
blob: 731abe5bee2cdc669b5cab6d41da1f631b0c8e80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 *	Copyright (c) 1999-2004 Smithsonian Astrophysical Observatory
 */

/*
 *
 * xport.h - include file for platform-dependent system calls
 *
 */
#ifndef	__xport_h
#define	__xport_h

#if HAVE_CONFIG_H
#include <conf.h>
#endif

#if HAVE_MINGW32

#define FD_SETSIZE 8192
#include <winsock2.h>
#include <process.h>
#include <io.h>

#ifdef	EINPROGRESS
#undef  EINPROGRESS
#endif
#define EINPROGRESS	WSAEINPROGRESS
#ifdef	EINTR
#undef  EINTR	
#endif
#define EINTR		WSAEINTR
#ifdef ETIMEDOUT
#undef  ETIMEDOUT
#endif
#define ETIMEDOUT	WSAETIMEDOUT
#ifdef ECONNREFUSED
#undef  ECONNREFUSED
#endif
#define ECONNREFUSED	WSAECONNREFUSED
#ifdef EWOULDBLOCK
#undef  EWOULDBLOCK
#endif
#define EWOULDBLOCK	WSAEWOULDBLOCK
#ifdef EAGAIN
#undef  EAGAIN	
#endif
#define EAGAIN		WSAEWOULDBLOCK

#else

#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>                                                  
#include <netinet/in.h>         /* struct in_addr, struct sockaddr_in */
#include <netdb.h>              /* gethostbyname() */
#include <arpa/inet.h>		/* inet_addr() */
#if HAVE_SYS_UN_H
#include <sys/un.h>
#endif
#if HAVE_CYGWIN
#include <process.h>
#endif

#endif

/* common definitions (i.e. not yet requiring platform differentiation) */

#define xsocket(a,b,c)		socket(a,b,c)
#define xbind(a,b,c)		bind(a,b,c)
#define xaccept(a,b,c)		accept(a,b,c)
#define xselect(a,b,c,d,e)	select(a,b,c,d,e)

/* UNIX */
#if HAVE_MINGW32==0

#define xclose(a)		close(a)

#define xfcntl(a,b,c)		fcntl(a,b,c)

#define xfcntl_nonblock(a,b)				  \
				b = fcntl(a, F_GETFL, 0); \
				fcntl(a, F_SETFL, b|O_NONBLOCK)

#define xfcntl_restore(a,b)	fcntl(a, F_SETFL, b)

#define xsocketstartup()

#define xsocketcleanup()

#define xfd_set_stdin(a,b)	FD_SET(a,b)	
#define xfd_isset_stdin(a,b)	(a >= 0) && FD_ISSET(a,b)	
#define xfd_clr_stdin(a,b)	FD_CLR(a,b)	

#define xsignal_sigpipe()	signal(SIGPIPE, SIG_IGN)

#define xerrno			errno

#define xmkdir(a,b)		mkdir(a,b)
#define xchmod(a,b)		chmod(a,b)

/* WINDOWS */
#else

#define xclose(a)		closesocket(a)

#define xfcntl(a,b,c)

#define xfcntl_nonblock(a,b)						\
	{								\
		int iomode=1;						\
		ioctlsocket(a, FIONBIO, (u_long FAR *) &iomode);	\
	}

#define xfcntl_restore(a,b)						\
	{								\
		int iomode=0;						\
		ioctlsocket(a, FIONBIO, (u_long FAR *) &iomode);	\
	}

#define xsocketstartup()					\
	{							\
		WSADATA wsaData;				\
		WSAStartup(MAKEWORD(2,0), &wsaData);		\
	}

#define xsocketcleanup()	WSACleanup()

#define xfd_set_stdin(a,b)	setmode(a, O_BINARY)

#define xfd_isset_stdin(a,b)	(a >= 0)
#define xfd_clr_stdin(a,b)

#define xsignal_sigpipe()

#define xerrno			WSAGetLastError()

#define xmkdir(a,b)		mkdir(a)
#define xchmod(a,b)		chmod(a,b)

#endif

#endif /* __xport.h */