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