From 173bfbf7886608a4a7abbfac6a42ac4bf4a3432d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 20 Sep 2020 16:14:20 +0100 Subject: New upstream version 1.5.0 --- openbsd-compat/clock_gettime.c | 32 ++++++++++++++++++++++++++++ openbsd-compat/diff.sh | 24 --------------------- openbsd-compat/openbsd-compat.h | 2 ++ openbsd-compat/time.h | 46 +++++++++++++++++++++++++++++++++++++++++ openbsd-compat/types.h | 7 ------- 5 files changed, 80 insertions(+), 31 deletions(-) create mode 100644 openbsd-compat/clock_gettime.c delete mode 100755 openbsd-compat/diff.sh create mode 100644 openbsd-compat/time.h (limited to 'openbsd-compat') diff --git a/openbsd-compat/clock_gettime.c b/openbsd-compat/clock_gettime.c new file mode 100644 index 0000000..ca261a6 --- /dev/null +++ b/openbsd-compat/clock_gettime.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 Yubico AB. All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +#include "openbsd-compat.h" + +#if !defined(HAVE_CLOCK_GETTIME) + +#if _WIN32 +int +clock_gettime(clockid_t clock_id, struct timespec *tp) +{ + ULONGLONG ms; + + if (clock_id != CLOCK_MONOTONIC) { + errno = EINVAL; + return (-1); + } + + ms = GetTickCount64(); + tp->tv_sec = ms / 1000L; + tp->tv_nsec = (ms % 1000L) * 1000000L; + + return (0); +} +#else +#error "please provide an implementation of clock_gettime() for your platform" +#endif /* _WIN32 */ + +#endif /* !defined(HAVE_CLOCK_GETTIME) */ diff --git a/openbsd-compat/diff.sh b/openbsd-compat/diff.sh deleted file mode 100755 index f21e7d8..0000000 --- a/openbsd-compat/diff.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -u - -# Copyright (c) 2019 Yubico AB. All rights reserved. -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file. - -OPENSSH=$(realpath ../../openssh) -LIBRESSL=$(realpath ../../libressl-2.8.3) -[[ ! -d "${OPENSSH}" || ! -d "${LIBRESSL}" ]] && exit 1 - -diff -pu bsd-getpagesize.c ${OPENSSH}/openbsd-compat/bsd-getpagesize.c -diff -pu err.h ${LIBRESSL}/include/compat/err.h -diff -pu explicit_bzero.c ${OPENSSH}/openbsd-compat/explicit_bzero.c -diff -pu explicit_bzero_win32.c ${LIBRESSL}/crypto/compat/explicit_bzero_win.c -diff -pu getopt.h ${OPENSSH}/openbsd-compat/getopt.h -diff -pu getopt_long.c ${OPENSSH}/openbsd-compat/getopt_long.c -diff -pu posix_win.c ${LIBRESSL}/crypto/compat/posix_win.c -diff -pu readpassphrase.c ${OPENSSH}/openbsd-compat/readpassphrase.c -diff -pu readpassphrase.h ${OPENSSH}/openbsd-compat/readpassphrase.h -diff -pu recallocarray.c ${OPENSSH}/openbsd-compat/recallocarray.c -diff -pu strlcat.c ${OPENSSH}/openbsd-compat/strlcat.c -diff -pu strlcpy.c ${OPENSSH}/openbsd-compat/strlcpy.c -diff -pu timingsafe_bcmp.c ${OPENSSH}/openbsd-compat/timingsafe_bcmp.c -diff -pu types.h ${LIBRESSL}/include/compat/sys/types.h diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 30d80b3..4f847a5 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h @@ -90,4 +90,6 @@ int timingsafe_bcmp(const void *, const void *, size_t); ssize_t getline(char **, size_t *, FILE *); #endif +#include "time.h" + #endif /* !_OPENBSD_COMPAT_H */ diff --git a/openbsd-compat/time.h b/openbsd-compat/time.h new file mode 100644 index 0000000..23ac0fe --- /dev/null +++ b/openbsd-compat/time.h @@ -0,0 +1,46 @@ +/* + * Public domain + * sys/time.h compatibility shim + */ + +#if defined(_MSC_VER) && (_MSC_VER >= 1900) +#include <../ucrt/time.h> +#elif defined(_MSC_VER) && (_MSC_VER < 1900) +#include <../include/time.h> +#else +#include +#endif + +#ifndef _COMPAT_TIME_H +#define _COMPAT_TIME_H + +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC CLOCK_REALTIME +#endif + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif + +#ifndef HAVE_CLOCK_GETTIME +typedef int clockid_t; +int clock_gettime(clockid_t, struct timespec *); +#endif + +#ifdef HAVE_TIMESPECSUB +#include +#endif + +#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 + +#endif /* _COMPAT_TIME_H */ diff --git a/openbsd-compat/types.h b/openbsd-compat/types.h index cc1da66..e3aa6b5 100644 --- a/openbsd-compat/types.h +++ b/openbsd-compat/types.h @@ -23,13 +23,6 @@ typedef uint32_t uid_t; #endif #ifdef _MSC_VER -typedef unsigned char u_char; -typedef unsigned short u_short; -typedef unsigned int u_int; -typedef uint32_t in_addr_t; -typedef uint32_t mode_t; -typedef uint32_t uid_t; - #include typedef SSIZE_T ssize_t; -- cgit v1.2.3