comparison lib/sys_time.in.h @ 15613:e819b881a9e2

sys_time: Support for MSVC. * m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Invoke gl_PREREQ_SYS_H_WINSOCK2. When testing for 'struct timeval', also include <winsock2.h>. * lib/sys_time.in.h: On MSVC, include <winsock2.h> and hide its function declarations that collide with POSIX. * modules/sys_time (Files): Add m4/sys_socket_h.m4. (Makefile.am): Substitute HAVE_WINSOCK2_H.
author Bruno Haible <bruno@clisp.org>
date Wed, 14 Sep 2011 02:08:36 +0200
parents 5f709022a256
children 8250f2777afc
comparison
equal deleted inserted replaced
15612:7bff02eb5553 15613:e819b881a9e2
36 36
37 # if @HAVE_SYS_TIME_H@ 37 # if @HAVE_SYS_TIME_H@
38 # @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ 38 # @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
39 # else 39 # else
40 # include <time.h> 40 # include <time.h>
41 # endif
42
43 /* On native Windows with MSVC:
44 Get the 'struct timeval' type. */
45 # if defined _MSC_VER && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
46 # define _GL_INCLUDING_WINSOCK2_H
47 # include <winsock2.h>
48 # undef _GL_INCLUDING_WINSOCK2_H
41 # endif 49 # endif
42 50
43 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 51 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
44 52
45 /* The definition of _GL_ARG_NONNULL is copied here. */ 53 /* The definition of _GL_ARG_NONNULL is copied here. */
96 _GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - " 104 _GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
97 "use gnulib module gettimeofday for portability"); 105 "use gnulib module gettimeofday for portability");
98 # endif 106 # endif
99 # endif 107 # endif
100 108
109 /* Hide some function declarations from <winsock2.h>. */
110
111 # if defined _MSC_VER && @HAVE_WINSOCK2_H@
112 # if !defined _@GUARD_PREFIX@_UNISTD_H
113 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
114 # undef close
115 # define close close_used_without_including_unistd_h
116 # else
117 _GL_WARN_ON_USE (close,
118 "close() used without including <unistd.h>");
119 # endif
120 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121 # undef gethostname
122 # define gethostname gethostname_used_without_including_unistd_h
123 # else
124 _GL_WARN_ON_USE (gethostname,
125 "gethostname() used without including <unistd.h>");
126 # endif
127 # endif
128 # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
129 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
130 # undef socket
131 # define socket socket_used_without_including_sys_socket_h
132 # undef connect
133 # define connect connect_used_without_including_sys_socket_h
134 # undef accept
135 # define accept accept_used_without_including_sys_socket_h
136 # undef bind
137 # define bind bind_used_without_including_sys_socket_h
138 # undef getpeername
139 # define getpeername getpeername_used_without_including_sys_socket_h
140 # undef getsockname
141 # define getsockname getsockname_used_without_including_sys_socket_h
142 # undef getsockopt
143 # define getsockopt getsockopt_used_without_including_sys_socket_h
144 # undef listen
145 # define listen listen_used_without_including_sys_socket_h
146 # undef recv
147 # define recv recv_used_without_including_sys_socket_h
148 # undef send
149 # define send send_used_without_including_sys_socket_h
150 # undef recvfrom
151 # define recvfrom recvfrom_used_without_including_sys_socket_h
152 # undef sendto
153 # define sendto sendto_used_without_including_sys_socket_h
154 # undef setsockopt
155 # define setsockopt setsockopt_used_without_including_sys_socket_h
156 # undef shutdown
157 # define shutdown shutdown_used_without_including_sys_socket_h
158 # else
159 _GL_WARN_ON_USE (socket,
160 "socket() used without including <sys/socket.h>");
161 _GL_WARN_ON_USE (connect,
162 "connect() used without including <sys/socket.h>");
163 _GL_WARN_ON_USE (accept,
164 "accept() used without including <sys/socket.h>");
165 _GL_WARN_ON_USE (bind,
166 "bind() used without including <sys/socket.h>");
167 _GL_WARN_ON_USE (getpeername,
168 "getpeername() used without including <sys/socket.h>");
169 _GL_WARN_ON_USE (getsockname,
170 "getsockname() used without including <sys/socket.h>");
171 _GL_WARN_ON_USE (getsockopt,
172 "getsockopt() used without including <sys/socket.h>");
173 _GL_WARN_ON_USE (listen,
174 "listen() used without including <sys/socket.h>");
175 _GL_WARN_ON_USE (recv,
176 "recv() used without including <sys/socket.h>");
177 _GL_WARN_ON_USE (send,
178 "send() used without including <sys/socket.h>");
179 _GL_WARN_ON_USE (recvfrom,
180 "recvfrom() used without including <sys/socket.h>");
181 _GL_WARN_ON_USE (sendto,
182 "sendto() used without including <sys/socket.h>");
183 _GL_WARN_ON_USE (setsockopt,
184 "setsockopt() used without including <sys/socket.h>");
185 _GL_WARN_ON_USE (shutdown,
186 "shutdown() used without including <sys/socket.h>");
187 # endif
188 # endif
189 # if !defined _@GUARD_PREFIX@_SYS_SELECT_H
190 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
191 # undef select
192 # define select select_used_without_including_sys_select_h
193 # else
194 _GL_WARN_ON_USE (select,
195 "select() used without including <sys/select.h>");
196 # endif
197 # endif
198 # endif
199
101 #endif /* _@GUARD_PREFIX@_SYS_TIME_H */ 200 #endif /* _@GUARD_PREFIX@_SYS_TIME_H */