From c04c64a28fc1e223ba3744c9074c60ec610b4e5c Mon Sep 17 00:00:00 2001 From: Duncaen Date: Tue, 12 Dec 2017 17:14:45 +0100 Subject: [PATCH] persist_timestamp: move timespec macros to libopenbsd --- libopenbsd/sys-time.h | 60 +++++++++++++++++++++++++++++++++++++++++++ persist_timestamp.c | 32 ++++++++--------------- 2 files changed, 70 insertions(+), 22 deletions(-) create mode 100644 libopenbsd/sys-time.h diff --git a/libopenbsd/sys-time.h b/libopenbsd/sys-time.h new file mode 100644 index 0000000..2a40dc5 --- /dev/null +++ b/libopenbsd/sys-time.h @@ -0,0 +1,60 @@ +/* $OpenBSD: time.h,v 1.37 2017/12/11 23:31:16 jca Exp $ */ +/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */ + +/* + * 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 _SYS_TIME_H_ +#define _SYS_TIME_H_ + +/* Operations on timespecs. */ +#ifndef timespecisset +#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +#endif +#ifndef timespeccmp +#define timespeccmp(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? \ + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ + ((tsp)->tv_sec cmp (usp)->tv_sec)) +#endif +#ifndef timespecadd +#define timespecadd(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 >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) +#endif + +#endif /* !_SYS_TIME_H_ */ diff --git a/persist_timestamp.c b/persist_timestamp.c index 81ea273..bd32fe5 100644 --- a/persist_timestamp.c +++ b/persist_timestamp.c @@ -1,18 +1,21 @@ +#include +#include + +#if !defined(timespecisset) || \ + !defined(timespeccmp) || \ + !defined(timespecadd) +# include "sys-time.h" +#endif + #include #include #include #include -#include +#include #include -#include #include #include #include -#include -#include - -#include -#include #include "includes.h" @@ -26,21 +29,6 @@ # endif #endif -#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) -#define timespeccmp(tsp, usp, cmp) \ - (((tsp)->tv_sec == (usp)->tv_sec) ? \ - ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ - ((tsp)->tv_sec cmp (usp)->tv_sec)) -#define timespecadd(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 >= 1000000000L) { \ - (vsp)->tv_sec++; \ - (vsp)->tv_nsec -= 1000000000L; \ - } \ - } while (0) - - #ifdef __linux__ /* Use tty_nr from /proc/self/stat instead of using * ttyname(3), stdin, stdout and stderr are user -- 2.39.2