11cb0ef41Sopenharmony_ci/* MIT License 21cb0ef41Sopenharmony_ci * 31cb0ef41Sopenharmony_ci * Copyright (c) 2004 Daniel Stenberg 41cb0ef41Sopenharmony_ci * 51cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 61cb0ef41Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal 71cb0ef41Sopenharmony_ci * in the Software without restriction, including without limitation the rights 81cb0ef41Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 91cb0ef41Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is 101cb0ef41Sopenharmony_ci * furnished to do so, subject to the following conditions: 111cb0ef41Sopenharmony_ci * 121cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice (including the next 131cb0ef41Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 141cb0ef41Sopenharmony_ci * Software. 151cb0ef41Sopenharmony_ci * 161cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 171cb0ef41Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 181cb0ef41Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 191cb0ef41Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 201cb0ef41Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 211cb0ef41Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 221cb0ef41Sopenharmony_ci * SOFTWARE. 231cb0ef41Sopenharmony_ci * 241cb0ef41Sopenharmony_ci * SPDX-License-Identifier: MIT 251cb0ef41Sopenharmony_ci */ 261cb0ef41Sopenharmony_ci#ifndef __SETUP_ONCE_H 271cb0ef41Sopenharmony_ci#define __SETUP_ONCE_H 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci/******************************************************************** 311cb0ef41Sopenharmony_ci * NOTICE * 321cb0ef41Sopenharmony_ci * ======== * 331cb0ef41Sopenharmony_ci * * 341cb0ef41Sopenharmony_ci * Content of header files lib/setup_once.h and ares/setup_once.h * 351cb0ef41Sopenharmony_ci * must be kept in sync. Modify the other one if you change this. * 361cb0ef41Sopenharmony_ci * * 371cb0ef41Sopenharmony_ci ********************************************************************/ 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci/* 411cb0ef41Sopenharmony_ci * Inclusion of common header files. 421cb0ef41Sopenharmony_ci */ 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci#include <stdio.h> 451cb0ef41Sopenharmony_ci#include <stdlib.h> 461cb0ef41Sopenharmony_ci#include <string.h> 471cb0ef41Sopenharmony_ci#include <stdarg.h> 481cb0ef41Sopenharmony_ci#include <ctype.h> 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci#ifdef HAVE_ERRNO_H 511cb0ef41Sopenharmony_ci# include <errno.h> 521cb0ef41Sopenharmony_ci#endif 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci#ifdef HAVE_SYS_TYPES_H 551cb0ef41Sopenharmony_ci# include <sys/types.h> 561cb0ef41Sopenharmony_ci#endif 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci#ifdef NEED_MALLOC_H 591cb0ef41Sopenharmony_ci# include <malloc.h> 601cb0ef41Sopenharmony_ci#endif 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci#ifdef NEED_MEMORY_H 631cb0ef41Sopenharmony_ci# include <memory.h> 641cb0ef41Sopenharmony_ci#endif 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci#ifdef HAVE_SYS_STAT_H 671cb0ef41Sopenharmony_ci# include <sys/stat.h> 681cb0ef41Sopenharmony_ci#endif 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci#ifdef HAVE_SYS_TIME_H 711cb0ef41Sopenharmony_ci# include <sys/time.h> 721cb0ef41Sopenharmony_ci#endif 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci#ifdef HAVE_TIME_H 751cb0ef41Sopenharmony_ci# include <time.h> 761cb0ef41Sopenharmony_ci#endif 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci#ifdef WIN32 791cb0ef41Sopenharmony_ci# include <io.h> 801cb0ef41Sopenharmony_ci# include <fcntl.h> 811cb0ef41Sopenharmony_ci#endif 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci#ifdef HAVE_UNISTD_H 841cb0ef41Sopenharmony_ci# include <unistd.h> 851cb0ef41Sopenharmony_ci#endif 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci#ifdef __hpux 881cb0ef41Sopenharmony_ci# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) 891cb0ef41Sopenharmony_ci# ifdef _APP32_64BIT_OFF_T 901cb0ef41Sopenharmony_ci# define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T 911cb0ef41Sopenharmony_ci# undef _APP32_64BIT_OFF_T 921cb0ef41Sopenharmony_ci# else 931cb0ef41Sopenharmony_ci# undef OLD_APP32_64BIT_OFF_T 941cb0ef41Sopenharmony_ci# endif 951cb0ef41Sopenharmony_ci# endif 961cb0ef41Sopenharmony_ci#endif 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci#ifdef HAVE_SYS_SOCKET_H 991cb0ef41Sopenharmony_ci# include <sys/socket.h> 1001cb0ef41Sopenharmony_ci#endif 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci#ifdef __hpux 1031cb0ef41Sopenharmony_ci# if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) 1041cb0ef41Sopenharmony_ci# ifdef OLD_APP32_64BIT_OFF_T 1051cb0ef41Sopenharmony_ci# define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T 1061cb0ef41Sopenharmony_ci# undef OLD_APP32_64BIT_OFF_T 1071cb0ef41Sopenharmony_ci# endif 1081cb0ef41Sopenharmony_ci# endif 1091cb0ef41Sopenharmony_ci#endif 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci/* 1131cb0ef41Sopenharmony_ci * Definition of timeval struct for platforms that don't have it. 1141cb0ef41Sopenharmony_ci */ 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_ci#ifndef HAVE_STRUCT_TIMEVAL 1171cb0ef41Sopenharmony_cistruct timeval { 1181cb0ef41Sopenharmony_ci long tv_sec; 1191cb0ef41Sopenharmony_ci long tv_usec; 1201cb0ef41Sopenharmony_ci}; 1211cb0ef41Sopenharmony_ci#endif 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci 1241cb0ef41Sopenharmony_ci/* 1251cb0ef41Sopenharmony_ci * If we have the MSG_NOSIGNAL define, make sure we use 1261cb0ef41Sopenharmony_ci * it as the fourth argument of function send() 1271cb0ef41Sopenharmony_ci */ 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci#ifdef HAVE_MSG_NOSIGNAL 1301cb0ef41Sopenharmony_ci# define SEND_4TH_ARG MSG_NOSIGNAL 1311cb0ef41Sopenharmony_ci#else 1321cb0ef41Sopenharmony_ci# define SEND_4TH_ARG 0 1331cb0ef41Sopenharmony_ci#endif 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ci#if defined(__minix) 1371cb0ef41Sopenharmony_ci/* Minix doesn't support recv on TCP sockets */ 1381cb0ef41Sopenharmony_ci# define sread(x, y, z) \ 1391cb0ef41Sopenharmony_ci (ares_ssize_t) \ 1401cb0ef41Sopenharmony_ci read((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), (RECV_TYPE_ARG3)(z)) 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci#elif defined(HAVE_RECV) 1431cb0ef41Sopenharmony_ci/* 1441cb0ef41Sopenharmony_ci * The definitions for the return type and arguments types 1451cb0ef41Sopenharmony_ci * of functions recv() and send() belong and come from the 1461cb0ef41Sopenharmony_ci * configuration file. Do not define them in any other place. 1471cb0ef41Sopenharmony_ci * 1481cb0ef41Sopenharmony_ci * HAVE_RECV is defined if you have a function named recv() 1491cb0ef41Sopenharmony_ci * which is used to read incoming data from sockets. If your 1501cb0ef41Sopenharmony_ci * function has another name then don't define HAVE_RECV. 1511cb0ef41Sopenharmony_ci * 1521cb0ef41Sopenharmony_ci * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2, 1531cb0ef41Sopenharmony_ci * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also 1541cb0ef41Sopenharmony_ci * be defined. 1551cb0ef41Sopenharmony_ci * 1561cb0ef41Sopenharmony_ci * HAVE_SEND is defined if you have a function named send() 1571cb0ef41Sopenharmony_ci * which is used to write outgoing data on a connected socket. 1581cb0ef41Sopenharmony_ci * If yours has another name then don't define HAVE_SEND. 1591cb0ef41Sopenharmony_ci * 1601cb0ef41Sopenharmony_ci * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_QUAL_ARG2, 1611cb0ef41Sopenharmony_ci * SEND_TYPE_ARG2, SEND_TYPE_ARG3, SEND_TYPE_ARG4 and 1621cb0ef41Sopenharmony_ci * SEND_TYPE_RETV must also be defined. 1631cb0ef41Sopenharmony_ci */ 1641cb0ef41Sopenharmony_ci 1651cb0ef41Sopenharmony_ci# if !defined(RECV_TYPE_ARG1) || !defined(RECV_TYPE_ARG2) || \ 1661cb0ef41Sopenharmony_ci !defined(RECV_TYPE_ARG3) || !defined(RECV_TYPE_ARG4) || \ 1671cb0ef41Sopenharmony_ci !defined(RECV_TYPE_RETV) 1681cb0ef41Sopenharmony_ci/* */ 1691cb0ef41Sopenharmony_ciError Missing_definition_of_return_and_arguments_types_of_recv 1701cb0ef41Sopenharmony_ci/* */ 1711cb0ef41Sopenharmony_ci# else 1721cb0ef41Sopenharmony_ci# define sread(x, y, z) \ 1731cb0ef41Sopenharmony_ci (ares_ssize_t) recv((RECV_TYPE_ARG1)(x), (RECV_TYPE_ARG2)(y), \ 1741cb0ef41Sopenharmony_ci (RECV_TYPE_ARG3)(z), (RECV_TYPE_ARG4)(0)) 1751cb0ef41Sopenharmony_ci# endif 1761cb0ef41Sopenharmony_ci#else /* HAVE_RECV */ 1771cb0ef41Sopenharmony_ci# ifndef sread 1781cb0ef41Sopenharmony_ci/* */ 1791cb0ef41Sopenharmony_ciError Missing_definition_of_macro_sread 1801cb0ef41Sopenharmony_ci/* */ 1811cb0ef41Sopenharmony_ci# endif 1821cb0ef41Sopenharmony_ci#endif /* HAVE_RECV */ 1831cb0ef41Sopenharmony_ci 1841cb0ef41Sopenharmony_ci 1851cb0ef41Sopenharmony_ci#if defined(__minix) 1861cb0ef41Sopenharmony_ci/* Minix doesn't support send on TCP sockets */ 1871cb0ef41Sopenharmony_ci# define swrite(x, y, z) \ 1881cb0ef41Sopenharmony_ci (ares_ssize_t) \ 1891cb0ef41Sopenharmony_ci write((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), (SEND_TYPE_ARG3)(z)) 1901cb0ef41Sopenharmony_ci 1911cb0ef41Sopenharmony_ci#elif defined(HAVE_SEND) 1921cb0ef41Sopenharmony_ci# if !defined(SEND_TYPE_ARG1) || !defined(SEND_QUAL_ARG2) || \ 1931cb0ef41Sopenharmony_ci !defined(SEND_TYPE_ARG2) || !defined(SEND_TYPE_ARG3) || \ 1941cb0ef41Sopenharmony_ci !defined(SEND_TYPE_ARG4) || !defined(SEND_TYPE_RETV) 1951cb0ef41Sopenharmony_ci /* */ 1961cb0ef41Sopenharmony_ci Error Missing_definition_of_return_and_arguments_types_of_send 1971cb0ef41Sopenharmony_ci/* */ 1981cb0ef41Sopenharmony_ci# else 1991cb0ef41Sopenharmony_ci# define swrite(x, y, z) \ 2001cb0ef41Sopenharmony_ci (ares_ssize_t) send((SEND_TYPE_ARG1)(x), (SEND_TYPE_ARG2)(y), \ 2011cb0ef41Sopenharmony_ci (SEND_TYPE_ARG3)(z), (SEND_TYPE_ARG4)(SEND_4TH_ARG)) 2021cb0ef41Sopenharmony_ci# endif 2031cb0ef41Sopenharmony_ci#else /* HAVE_SEND */ 2041cb0ef41Sopenharmony_ci# ifndef swrite 2051cb0ef41Sopenharmony_ci /* */ 2061cb0ef41Sopenharmony_ci Error Missing_definition_of_macro_swrite 2071cb0ef41Sopenharmony_ci/* */ 2081cb0ef41Sopenharmony_ci# endif 2091cb0ef41Sopenharmony_ci#endif /* HAVE_SEND */ 2101cb0ef41Sopenharmony_ci 2111cb0ef41Sopenharmony_ci 2121cb0ef41Sopenharmony_ci#if 0 2131cb0ef41Sopenharmony_ci# if defined(HAVE_RECVFROM) 2141cb0ef41Sopenharmony_ci/* 2151cb0ef41Sopenharmony_ci * Currently recvfrom is only used on udp sockets. 2161cb0ef41Sopenharmony_ci */ 2171cb0ef41Sopenharmony_ci# if !defined(RECVFROM_TYPE_ARG1) || !defined(RECVFROM_TYPE_ARG2) || \ 2181cb0ef41Sopenharmony_ci !defined(RECVFROM_TYPE_ARG3) || !defined(RECVFROM_TYPE_ARG4) || \ 2191cb0ef41Sopenharmony_ci !defined(RECVFROM_TYPE_ARG5) || !defined(RECVFROM_TYPE_ARG6) || \ 2201cb0ef41Sopenharmony_ci !defined(RECVFROM_TYPE_RETV) 2211cb0ef41Sopenharmony_ci /* */ 2221cb0ef41Sopenharmony_ci Error Missing_definition_of_return_and_arguments_types_of_recvfrom 2231cb0ef41Sopenharmony_ci /* */ 2241cb0ef41Sopenharmony_ci# else 2251cb0ef41Sopenharmony_ci# define sreadfrom(s, b, bl, f, fl) \ 2261cb0ef41Sopenharmony_ci (ares_ssize_t) \ 2271cb0ef41Sopenharmony_ci recvfrom((RECVFROM_TYPE_ARG1)(s), (RECVFROM_TYPE_ARG2 *)(b), \ 2281cb0ef41Sopenharmony_ci (RECVFROM_TYPE_ARG3)(bl), (RECVFROM_TYPE_ARG4)(0), \ 2291cb0ef41Sopenharmony_ci (RECVFROM_TYPE_ARG5 *)(f), (RECVFROM_TYPE_ARG6 *)(fl)) 2301cb0ef41Sopenharmony_ci# endif 2311cb0ef41Sopenharmony_ci# else /* HAVE_RECVFROM */ 2321cb0ef41Sopenharmony_ci# ifndef sreadfrom 2331cb0ef41Sopenharmony_ci /* */ 2341cb0ef41Sopenharmony_ci Error Missing_definition_of_macro_sreadfrom 2351cb0ef41Sopenharmony_ci /* */ 2361cb0ef41Sopenharmony_ci# endif 2371cb0ef41Sopenharmony_ci# endif /* HAVE_RECVFROM */ 2381cb0ef41Sopenharmony_ci 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci# ifdef RECVFROM_TYPE_ARG6_IS_VOID 2411cb0ef41Sopenharmony_ci# define RECVFROM_ARG6_T int 2421cb0ef41Sopenharmony_ci# else 2431cb0ef41Sopenharmony_ci# define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6 2441cb0ef41Sopenharmony_ci# endif 2451cb0ef41Sopenharmony_ci#endif /* if 0 */ 2461cb0ef41Sopenharmony_ci 2471cb0ef41Sopenharmony_ci 2481cb0ef41Sopenharmony_ci/* 2491cb0ef41Sopenharmony_ci * Function-like macro definition used to close a socket. 2501cb0ef41Sopenharmony_ci */ 2511cb0ef41Sopenharmony_ci 2521cb0ef41Sopenharmony_ci#if defined(HAVE_CLOSESOCKET) 2531cb0ef41Sopenharmony_ci# define sclose(x) closesocket((x)) 2541cb0ef41Sopenharmony_ci#elif defined(HAVE_CLOSESOCKET_CAMEL) 2551cb0ef41Sopenharmony_ci# define sclose(x) CloseSocket((x)) 2561cb0ef41Sopenharmony_ci#elif defined(HAVE_CLOSE_S) 2571cb0ef41Sopenharmony_ci# define sclose(x) close_s((x)) 2581cb0ef41Sopenharmony_ci#else 2591cb0ef41Sopenharmony_ci# define sclose(x) close((x)) 2601cb0ef41Sopenharmony_ci#endif 2611cb0ef41Sopenharmony_ci 2621cb0ef41Sopenharmony_ci 2631cb0ef41Sopenharmony_ci/* 2641cb0ef41Sopenharmony_ci * Uppercase macro versions of ANSI/ISO is*() functions/macros which 2651cb0ef41Sopenharmony_ci * avoid negative number inputs with argument byte codes > 127. 2661cb0ef41Sopenharmony_ci */ 2671cb0ef41Sopenharmony_ci 2681cb0ef41Sopenharmony_ci#define ISSPACE(x) (isspace((int)((unsigned char)x))) 2691cb0ef41Sopenharmony_ci#define ISDIGIT(x) (isdigit((int)((unsigned char)x))) 2701cb0ef41Sopenharmony_ci#define ISALNUM(x) (isalnum((int)((unsigned char)x))) 2711cb0ef41Sopenharmony_ci#define ISXDIGIT(x) (isxdigit((int)((unsigned char)x))) 2721cb0ef41Sopenharmony_ci#define ISGRAPH(x) (isgraph((int)((unsigned char)x))) 2731cb0ef41Sopenharmony_ci#define ISALPHA(x) (isalpha((int)((unsigned char)x))) 2741cb0ef41Sopenharmony_ci#define ISPRINT(x) (isprint((int)((unsigned char)x))) 2751cb0ef41Sopenharmony_ci#define ISUPPER(x) (isupper((int)((unsigned char)x))) 2761cb0ef41Sopenharmony_ci#define ISLOWER(x) (islower((int)((unsigned char)x))) 2771cb0ef41Sopenharmony_ci#define ISASCII(x) (isascii((int)((unsigned char)x))) 2781cb0ef41Sopenharmony_ci 2791cb0ef41Sopenharmony_ci#define ISBLANK(x) \ 2801cb0ef41Sopenharmony_ci (int)((((unsigned char)x) == ' ') || (((unsigned char)x) == '\t')) 2811cb0ef41Sopenharmony_ci 2821cb0ef41Sopenharmony_ci#define TOLOWER(x) (tolower((int)((unsigned char)x))) 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_ci 2851cb0ef41Sopenharmony_ci/* 2861cb0ef41Sopenharmony_ci * Macro WHILE_FALSE may be used to build single-iteration do-while loops, 2871cb0ef41Sopenharmony_ci * avoiding compiler warnings. Mostly intended for other macro definitions. 2881cb0ef41Sopenharmony_ci */ 2891cb0ef41Sopenharmony_ci 2901cb0ef41Sopenharmony_ci#define WHILE_FALSE while (0) 2911cb0ef41Sopenharmony_ci 2921cb0ef41Sopenharmony_ci#if defined(_MSC_VER) && !defined(__POCC__) 2931cb0ef41Sopenharmony_ci# undef WHILE_FALSE 2941cb0ef41Sopenharmony_ci# if (_MSC_VER < 1500) 2951cb0ef41Sopenharmony_ci# define WHILE_FALSE while (1, 0) 2961cb0ef41Sopenharmony_ci# else 2971cb0ef41Sopenharmony_ci# define WHILE_FALSE \ 2981cb0ef41Sopenharmony_ci __pragma(warning(push)) __pragma(warning(disable : 4127)) while (0) \ 2991cb0ef41Sopenharmony_ci __pragma(warning(pop)) 3001cb0ef41Sopenharmony_ci# endif 3011cb0ef41Sopenharmony_ci#endif 3021cb0ef41Sopenharmony_ci 3031cb0ef41Sopenharmony_ci 3041cb0ef41Sopenharmony_ci/* 3051cb0ef41Sopenharmony_ci * Macro used to include code only in debug builds. 3061cb0ef41Sopenharmony_ci */ 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ci#ifdef DEBUGBUILD 3091cb0ef41Sopenharmony_ci# define DEBUGF(x) x 3101cb0ef41Sopenharmony_ci#else 3111cb0ef41Sopenharmony_ci# define DEBUGF(x) \ 3121cb0ef41Sopenharmony_ci do { \ 3131cb0ef41Sopenharmony_ci } \ 3141cb0ef41Sopenharmony_ci WHILE_FALSE 3151cb0ef41Sopenharmony_ci#endif 3161cb0ef41Sopenharmony_ci 3171cb0ef41Sopenharmony_ci 3181cb0ef41Sopenharmony_ci/* 3191cb0ef41Sopenharmony_ci * Macro used to include assertion code only in debug builds. 3201cb0ef41Sopenharmony_ci */ 3211cb0ef41Sopenharmony_ci 3221cb0ef41Sopenharmony_ci#if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H) 3231cb0ef41Sopenharmony_ci# define DEBUGASSERT(x) assert(x) 3241cb0ef41Sopenharmony_ci#else 3251cb0ef41Sopenharmony_ci# define DEBUGASSERT(x) \ 3261cb0ef41Sopenharmony_ci do { \ 3271cb0ef41Sopenharmony_ci } \ 3281cb0ef41Sopenharmony_ci WHILE_FALSE 3291cb0ef41Sopenharmony_ci#endif 3301cb0ef41Sopenharmony_ci 3311cb0ef41Sopenharmony_ci 3321cb0ef41Sopenharmony_ci/* 3331cb0ef41Sopenharmony_ci * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno 3341cb0ef41Sopenharmony_ci * (or equivalent) on this platform to hide platform details to code using it. 3351cb0ef41Sopenharmony_ci */ 3361cb0ef41Sopenharmony_ci 3371cb0ef41Sopenharmony_ci#ifdef USE_WINSOCK 3381cb0ef41Sopenharmony_ci# define SOCKERRNO ((int)WSAGetLastError()) 3391cb0ef41Sopenharmony_ci# define SET_SOCKERRNO(x) (WSASetLastError((int)(x))) 3401cb0ef41Sopenharmony_ci#else 3411cb0ef41Sopenharmony_ci# define SOCKERRNO (errno) 3421cb0ef41Sopenharmony_ci# define SET_SOCKERRNO(x) (errno = (x)) 3431cb0ef41Sopenharmony_ci#endif 3441cb0ef41Sopenharmony_ci 3451cb0ef41Sopenharmony_ci 3461cb0ef41Sopenharmony_ci/* 3471cb0ef41Sopenharmony_ci * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno 3481cb0ef41Sopenharmony_ci * (or equivalent) on this platform to hide platform details to code using it. 3491cb0ef41Sopenharmony_ci */ 3501cb0ef41Sopenharmony_ci 3511cb0ef41Sopenharmony_ci#if defined(WIN32) && !defined(WATT32) 3521cb0ef41Sopenharmony_ci# define ERRNO ((int)GetLastError()) 3531cb0ef41Sopenharmony_ci# define SET_ERRNO(x) (SetLastError((DWORD)(x))) 3541cb0ef41Sopenharmony_ci#else 3551cb0ef41Sopenharmony_ci# define ERRNO (errno) 3561cb0ef41Sopenharmony_ci# define SET_ERRNO(x) (errno = (x)) 3571cb0ef41Sopenharmony_ci#endif 3581cb0ef41Sopenharmony_ci 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci/* 3611cb0ef41Sopenharmony_ci * Portable error number symbolic names defined to Winsock error codes. 3621cb0ef41Sopenharmony_ci */ 3631cb0ef41Sopenharmony_ci 3641cb0ef41Sopenharmony_ci#ifdef USE_WINSOCK 3651cb0ef41Sopenharmony_ci# undef EBADF /* override definition in errno.h */ 3661cb0ef41Sopenharmony_ci# define EBADF WSAEBADF 3671cb0ef41Sopenharmony_ci# undef EINTR /* override definition in errno.h */ 3681cb0ef41Sopenharmony_ci# define EINTR WSAEINTR 3691cb0ef41Sopenharmony_ci# undef EINVAL /* override definition in errno.h */ 3701cb0ef41Sopenharmony_ci# define EINVAL WSAEINVAL 3711cb0ef41Sopenharmony_ci# undef EWOULDBLOCK /* override definition in errno.h */ 3721cb0ef41Sopenharmony_ci# define EWOULDBLOCK WSAEWOULDBLOCK 3731cb0ef41Sopenharmony_ci# undef EINPROGRESS /* override definition in errno.h */ 3741cb0ef41Sopenharmony_ci# define EINPROGRESS WSAEINPROGRESS 3751cb0ef41Sopenharmony_ci# undef EALREADY /* override definition in errno.h */ 3761cb0ef41Sopenharmony_ci# define EALREADY WSAEALREADY 3771cb0ef41Sopenharmony_ci# undef ENOTSOCK /* override definition in errno.h */ 3781cb0ef41Sopenharmony_ci# define ENOTSOCK WSAENOTSOCK 3791cb0ef41Sopenharmony_ci# undef EDESTADDRREQ /* override definition in errno.h */ 3801cb0ef41Sopenharmony_ci# define EDESTADDRREQ WSAEDESTADDRREQ 3811cb0ef41Sopenharmony_ci# undef EMSGSIZE /* override definition in errno.h */ 3821cb0ef41Sopenharmony_ci# define EMSGSIZE WSAEMSGSIZE 3831cb0ef41Sopenharmony_ci# undef EPROTOTYPE /* override definition in errno.h */ 3841cb0ef41Sopenharmony_ci# define EPROTOTYPE WSAEPROTOTYPE 3851cb0ef41Sopenharmony_ci# undef ENOPROTOOPT /* override definition in errno.h */ 3861cb0ef41Sopenharmony_ci# define ENOPROTOOPT WSAENOPROTOOPT 3871cb0ef41Sopenharmony_ci# undef EPROTONOSUPPORT /* override definition in errno.h */ 3881cb0ef41Sopenharmony_ci# define EPROTONOSUPPORT WSAEPROTONOSUPPORT 3891cb0ef41Sopenharmony_ci# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 3901cb0ef41Sopenharmony_ci# undef EOPNOTSUPP /* override definition in errno.h */ 3911cb0ef41Sopenharmony_ci# define EOPNOTSUPP WSAEOPNOTSUPP 3921cb0ef41Sopenharmony_ci# define EPFNOSUPPORT WSAEPFNOSUPPORT 3931cb0ef41Sopenharmony_ci# undef EAFNOSUPPORT /* override definition in errno.h */ 3941cb0ef41Sopenharmony_ci# define EAFNOSUPPORT WSAEAFNOSUPPORT 3951cb0ef41Sopenharmony_ci# undef EADDRINUSE /* override definition in errno.h */ 3961cb0ef41Sopenharmony_ci# define EADDRINUSE WSAEADDRINUSE 3971cb0ef41Sopenharmony_ci# undef EADDRNOTAVAIL /* override definition in errno.h */ 3981cb0ef41Sopenharmony_ci# define EADDRNOTAVAIL WSAEADDRNOTAVAIL 3991cb0ef41Sopenharmony_ci# undef ENETDOWN /* override definition in errno.h */ 4001cb0ef41Sopenharmony_ci# define ENETDOWN WSAENETDOWN 4011cb0ef41Sopenharmony_ci# undef ENETUNREACH /* override definition in errno.h */ 4021cb0ef41Sopenharmony_ci# define ENETUNREACH WSAENETUNREACH 4031cb0ef41Sopenharmony_ci# undef ENETRESET /* override definition in errno.h */ 4041cb0ef41Sopenharmony_ci# define ENETRESET WSAENETRESET 4051cb0ef41Sopenharmony_ci# undef ECONNABORTED /* override definition in errno.h */ 4061cb0ef41Sopenharmony_ci# define ECONNABORTED WSAECONNABORTED 4071cb0ef41Sopenharmony_ci# undef ECONNRESET /* override definition in errno.h */ 4081cb0ef41Sopenharmony_ci# define ECONNRESET WSAECONNRESET 4091cb0ef41Sopenharmony_ci# undef ENOBUFS /* override definition in errno.h */ 4101cb0ef41Sopenharmony_ci# define ENOBUFS WSAENOBUFS 4111cb0ef41Sopenharmony_ci# undef EISCONN /* override definition in errno.h */ 4121cb0ef41Sopenharmony_ci# define EISCONN WSAEISCONN 4131cb0ef41Sopenharmony_ci# undef ENOTCONN /* override definition in errno.h */ 4141cb0ef41Sopenharmony_ci# define ENOTCONN WSAENOTCONN 4151cb0ef41Sopenharmony_ci# define ESHUTDOWN WSAESHUTDOWN 4161cb0ef41Sopenharmony_ci# define ETOOMANYREFS WSAETOOMANYREFS 4171cb0ef41Sopenharmony_ci# undef ETIMEDOUT /* override definition in errno.h */ 4181cb0ef41Sopenharmony_ci# define ETIMEDOUT WSAETIMEDOUT 4191cb0ef41Sopenharmony_ci# undef ECONNREFUSED /* override definition in errno.h */ 4201cb0ef41Sopenharmony_ci# define ECONNREFUSED WSAECONNREFUSED 4211cb0ef41Sopenharmony_ci# undef ELOOP /* override definition in errno.h */ 4221cb0ef41Sopenharmony_ci# define ELOOP WSAELOOP 4231cb0ef41Sopenharmony_ci# ifndef ENAMETOOLONG /* possible previous definition in errno.h */ 4241cb0ef41Sopenharmony_ci# define ENAMETOOLONG WSAENAMETOOLONG 4251cb0ef41Sopenharmony_ci# endif 4261cb0ef41Sopenharmony_ci# define EHOSTDOWN WSAEHOSTDOWN 4271cb0ef41Sopenharmony_ci# undef EHOSTUNREACH /* override definition in errno.h */ 4281cb0ef41Sopenharmony_ci# define EHOSTUNREACH WSAEHOSTUNREACH 4291cb0ef41Sopenharmony_ci# ifndef ENOTEMPTY /* possible previous definition in errno.h */ 4301cb0ef41Sopenharmony_ci# define ENOTEMPTY WSAENOTEMPTY 4311cb0ef41Sopenharmony_ci# endif 4321cb0ef41Sopenharmony_ci# define EPROCLIM WSAEPROCLIM 4331cb0ef41Sopenharmony_ci# define EUSERS WSAEUSERS 4341cb0ef41Sopenharmony_ci# define EDQUOT WSAEDQUOT 4351cb0ef41Sopenharmony_ci# define ESTALE WSAESTALE 4361cb0ef41Sopenharmony_ci# define EREMOTE WSAEREMOTE 4371cb0ef41Sopenharmony_ci#endif 4381cb0ef41Sopenharmony_ci 4391cb0ef41Sopenharmony_ci 4401cb0ef41Sopenharmony_ci/* 4411cb0ef41Sopenharmony_ci * Actually use __32_getpwuid() on 64-bit VMS builds for getpwuid() 4421cb0ef41Sopenharmony_ci */ 4431cb0ef41Sopenharmony_ci 4441cb0ef41Sopenharmony_ci#if defined(__VMS) && defined(__INITIAL_POINTER_SIZE) && \ 4451cb0ef41Sopenharmony_ci (__INITIAL_POINTER_SIZE == 64) 4461cb0ef41Sopenharmony_ci# define getpwuid __32_getpwuid 4471cb0ef41Sopenharmony_ci#endif 4481cb0ef41Sopenharmony_ci 4491cb0ef41Sopenharmony_ci 4501cb0ef41Sopenharmony_ci/* 4511cb0ef41Sopenharmony_ci * Macro argv_item_t hides platform details to code using it. 4521cb0ef41Sopenharmony_ci */ 4531cb0ef41Sopenharmony_ci 4541cb0ef41Sopenharmony_ci#ifdef __VMS 4551cb0ef41Sopenharmony_ci# define argv_item_t __char_ptr32 4561cb0ef41Sopenharmony_ci#else 4571cb0ef41Sopenharmony_ci# define argv_item_t char * 4581cb0ef41Sopenharmony_ci#endif 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci 4611cb0ef41Sopenharmony_ci/* 4621cb0ef41Sopenharmony_ci * We use this ZERO_NULL to avoid picky compiler warnings, 4631cb0ef41Sopenharmony_ci * when assigning a NULL pointer to a function pointer var. 4641cb0ef41Sopenharmony_ci */ 4651cb0ef41Sopenharmony_ci 4661cb0ef41Sopenharmony_ci#define ZERO_NULL 0 4671cb0ef41Sopenharmony_ci 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ci#endif /* __SETUP_ONCE_H */ 470