sys_time.in.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* Provide a more complete sys/time.h.
  2. Copyright (C) 2007-2023 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. /* Written by Paul Eggert. */
  14. #ifndef _@GUARD_PREFIX@_SYS_TIME_H
  15. #if __GNUC__ >= 3
  16. @PRAGMA_SYSTEM_HEADER@
  17. #endif
  18. @PRAGMA_COLUMNS@
  19. /* On Cygwin and on many BSDish systems, <sys/time.h> includes itself
  20. recursively via <sys/select.h>.
  21. Simply delegate to the system's header in this case; it is a no-op.
  22. Without this extra ifdef, the C++ gettimeofday declaration below
  23. would be a forward declaration in gnulib's nested <sys/time.h>. */
  24. #if defined _CYGWIN_SYS_TIME_H || defined _SYS_TIME_H || defined _SYS_TIME_H_
  25. # @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
  26. #else
  27. /* The include_next requires a split double-inclusion guard. */
  28. #if @HAVE_SYS_TIME_H@
  29. # @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
  30. #endif
  31. #ifndef _@GUARD_PREFIX@_SYS_TIME_H
  32. #define _@GUARD_PREFIX@_SYS_TIME_H
  33. #if ! @HAVE_SYS_TIME_H@
  34. # include <time.h>
  35. #endif
  36. /* On native Windows with MSVC, get the 'struct timeval' type.
  37. Also, on native Windows with a 64-bit time_t, where we are overriding the
  38. 'struct timeval' type, get all declarations of system functions whose
  39. signature contains 'struct timeval'. */
  40. #if (defined _MSC_VER || @REPLACE_STRUCT_TIMEVAL@) && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
  41. # define _GL_INCLUDING_WINSOCK2_H
  42. # include <winsock2.h>
  43. # undef _GL_INCLUDING_WINSOCK2_H
  44. #endif
  45. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  46. /* The definition of _GL_ARG_NONNULL is copied here. */
  47. /* The definition of _GL_WARN_ON_USE is copied here. */
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. #if !@HAVE_STRUCT_TIMEVAL@ || @REPLACE_STRUCT_TIMEVAL@
  52. # if @REPLACE_STRUCT_TIMEVAL@
  53. # define timeval rpl_timeval
  54. # endif
  55. # if !GNULIB_defined_struct_timeval
  56. struct timeval
  57. {
  58. time_t tv_sec;
  59. long int tv_usec;
  60. };
  61. # define GNULIB_defined_struct_timeval 1
  62. # endif
  63. #endif
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #if @GNULIB_GETTIMEOFDAY@
  68. # if @REPLACE_GETTIMEOFDAY@
  69. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  70. # undef gettimeofday
  71. # define gettimeofday rpl_gettimeofday
  72. # endif
  73. _GL_FUNCDECL_RPL (gettimeofday, int,
  74. (struct timeval *restrict, void *restrict)
  75. _GL_ARG_NONNULL ((1)));
  76. _GL_CXXALIAS_RPL (gettimeofday, int,
  77. (struct timeval *restrict, void *restrict));
  78. # else
  79. # if !@HAVE_GETTIMEOFDAY@
  80. _GL_FUNCDECL_SYS (gettimeofday, int,
  81. (struct timeval *restrict, void *restrict)
  82. _GL_ARG_NONNULL ((1)));
  83. # endif
  84. /* Need to cast, because on glibc systems, by default, the second argument is
  85. struct timezone *. */
  86. _GL_CXXALIAS_SYS_CAST (gettimeofday, int,
  87. (struct timeval *restrict, void *restrict));
  88. # endif
  89. _GL_CXXALIASWARN (gettimeofday);
  90. # if defined __cplusplus && defined GNULIB_NAMESPACE
  91. namespace GNULIB_NAMESPACE {
  92. typedef ::timeval
  93. # undef timeval
  94. timeval;
  95. # if @REPLACE_STRUCT_TIMEVAL@
  96. # define timeval rpl_timeval
  97. typedef ::timeval timeval;
  98. # endif
  99. }
  100. # endif
  101. #elif defined GNULIB_POSIXCHECK
  102. # undef gettimeofday
  103. # if HAVE_RAW_DECL_GETTIMEOFDAY
  104. _GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
  105. "use gnulib module gettimeofday for portability");
  106. # endif
  107. #endif
  108. /* Hide some function declarations from <winsock2.h>. */
  109. #if defined _MSC_VER && @HAVE_WINSOCK2_H@
  110. # if !defined _@GUARD_PREFIX@_UNISTD_H
  111. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  112. # undef close
  113. # define close close_used_without_including_unistd_h
  114. # elif !defined __clang__
  115. _GL_WARN_ON_USE (close,
  116. "close() used without including <unistd.h>");
  117. # endif
  118. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  119. # undef gethostname
  120. # define gethostname gethostname_used_without_including_unistd_h
  121. # else
  122. _GL_WARN_ON_USE (gethostname,
  123. "gethostname() used without including <unistd.h>");
  124. # endif
  125. # endif
  126. # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
  127. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  128. # undef socket
  129. # define socket socket_used_without_including_sys_socket_h
  130. # undef connect
  131. # define connect connect_used_without_including_sys_socket_h
  132. # undef accept
  133. # define accept accept_used_without_including_sys_socket_h
  134. # undef bind
  135. # define bind bind_used_without_including_sys_socket_h
  136. # undef getpeername
  137. # define getpeername getpeername_used_without_including_sys_socket_h
  138. # undef getsockname
  139. # define getsockname getsockname_used_without_including_sys_socket_h
  140. # undef getsockopt
  141. # define getsockopt getsockopt_used_without_including_sys_socket_h
  142. # undef listen
  143. # define listen listen_used_without_including_sys_socket_h
  144. # undef recv
  145. # define recv recv_used_without_including_sys_socket_h
  146. # undef send
  147. # define send send_used_without_including_sys_socket_h
  148. # undef recvfrom
  149. # define recvfrom recvfrom_used_without_including_sys_socket_h
  150. # undef sendto
  151. # define sendto sendto_used_without_including_sys_socket_h
  152. # undef setsockopt
  153. # define setsockopt setsockopt_used_without_including_sys_socket_h
  154. # undef shutdown
  155. # define shutdown shutdown_used_without_including_sys_socket_h
  156. # else
  157. _GL_WARN_ON_USE (socket,
  158. "socket() used without including <sys/socket.h>");
  159. _GL_WARN_ON_USE (connect,
  160. "connect() used without including <sys/socket.h>");
  161. _GL_WARN_ON_USE (accept,
  162. "accept() used without including <sys/socket.h>");
  163. _GL_WARN_ON_USE (bind,
  164. "bind() used without including <sys/socket.h>");
  165. _GL_WARN_ON_USE (getpeername,
  166. "getpeername() used without including <sys/socket.h>");
  167. _GL_WARN_ON_USE (getsockname,
  168. "getsockname() used without including <sys/socket.h>");
  169. _GL_WARN_ON_USE (getsockopt,
  170. "getsockopt() used without including <sys/socket.h>");
  171. _GL_WARN_ON_USE (listen,
  172. "listen() used without including <sys/socket.h>");
  173. _GL_WARN_ON_USE (recv,
  174. "recv() used without including <sys/socket.h>");
  175. _GL_WARN_ON_USE (send,
  176. "send() used without including <sys/socket.h>");
  177. _GL_WARN_ON_USE (recvfrom,
  178. "recvfrom() used without including <sys/socket.h>");
  179. _GL_WARN_ON_USE (sendto,
  180. "sendto() used without including <sys/socket.h>");
  181. _GL_WARN_ON_USE (setsockopt,
  182. "setsockopt() used without including <sys/socket.h>");
  183. _GL_WARN_ON_USE (shutdown,
  184. "shutdown() used without including <sys/socket.h>");
  185. # endif
  186. # endif
  187. # if !defined _@GUARD_PREFIX@_SYS_SELECT_H
  188. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  189. # undef select
  190. # define select select_used_without_including_sys_select_h
  191. # else
  192. _GL_WARN_ON_USE (select,
  193. "select() used without including <sys/select.h>");
  194. # endif
  195. # endif
  196. #endif
  197. #endif /* _@GUARD_PREFIX@_SYS_TIME_H */
  198. #endif /* _CYGWIN_SYS_TIME_H */
  199. #endif /* _@GUARD_PREFIX@_SYS_TIME_H */