commit b45ef13d08286e9dfb77fdad14c845885535f0b7 from: Omar Polo date: Mon Feb 19 16:22:42 2024 UTC add compats for the time-related macros used by ev commit - 12ba5e21a1193b98af6ee1e5eb3da838d5c788f1 commit + b45ef13d08286e9dfb77fdad14c845885535f0b7 blob - 43721af75e5fb7c4331fa895ce67714cf7d8aa5b blob + 03d3867f58c169f7934e4b82c559bdb8a5962bb9 --- compat.h +++ compat.h @@ -148,4 +148,67 @@ void setproctitle(const char*, ...); #define __dead __attribute__((__noreturn__)) #endif +/* + * The following time-related macros from sys/time.h are subject to: + * + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef HAVE_TIMESPECSUB +#define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) +#endif + +#ifndef HAVE_TIMERCMP +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#endif + +#ifndef HAVE_TIMEVAL_TO_TIMESPEC +#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} while (0) +#define TIMESPEC_TO_TIMEVAL(tv, ts) do { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ +} while (0) +#endif + #endif /* COMPAT_H */ blob - 74a04e4740503352aa7992b55ffe45527e077726 blob + 0b572aff86a4f2ac798228ff343c33117317fea5 --- configure.ac +++ configure.ac @@ -72,6 +72,28 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ AC_DEFINE([HAVE_QUEUE_H], 1, [QUEUE_H]) ], AC_MSG_RESULT(no)) +AC_CHECK_DECL(timespecsub, + [AC_DEFINE([HAVE_TIMESPECSUB], 1, [have timespecsub])], [], + [#include ]) + +AC_CHECK_DECL(timercmp, + [AC_DEFINE([HAVE_TIMERCMP], 1, [have timercmp])], [], + [#include ]) + +dnl can't be used as r-value. +AC_MSG_CHECKING([for TIMEVAL_TO_TIMESPEC]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +#include +], [ + struct timeval a = {0, 0}; + struct timespec b; + TIMEVAL_TO_TIMESPEC(&a, &b); + return (int)b.tv_sec; +])], [ + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_TIMEVAL_TO_TIMESPEC], 1, [have TIMEVAL_TO_TIMESPEC]) +], AC_MSG_RESULT(no)) + AC_CHECK_HEADER([endian.h], [AC_DEFINE(HAVE_ENDIAN_H, 1, [have endian.h])], [ AC_CHECK_HEADER([sys/endian.h], [AC_DEFINE(HAVE_SYS_ENDIAN_H, 1, [have sys/endian.h])], [