|
| 1 | +/* |
| 2 | + * Copyright (c) 1982, 1986, 1993 |
| 3 | + * The Regents of the University of California. All rights reserved. |
| 4 | + * Copyright (c) 2021 Vadim Zhukov <zhuk@openbsd.org> |
| 5 | + * |
| 6 | + * Redistribution and use in source and binary forms, with or without |
| 7 | + * modification, are permitted provided that the following conditions |
| 8 | + * are met: |
| 9 | + * 1. Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer in the |
| 13 | + * documentation and/or other materials provided with the distribution. |
| 14 | + * 3. Neither the name of the University nor the names of its contributors |
| 15 | + * may be used to endorse or promote products derived from this software |
| 16 | + * without specific prior written permission. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 19 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 22 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 24 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | + * SUCH DAMAGE. |
| 29 | + * |
| 30 | + * @(#)time.h 8.2 (Berkeley) 7/10/94 |
| 31 | + */ |
| 32 | + |
| 33 | +#ifndef TLC_COMPAT_H |
| 34 | +#define TLC_COMPAT_H |
| 35 | + |
| 36 | +/* Operations on timespecs. */ |
| 37 | + |
| 38 | +#ifndef timespecclear |
| 39 | +#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 |
| 40 | +#endif |
| 41 | + |
| 42 | +#ifndef timespecisset |
| 43 | +#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) |
| 44 | +#endif |
| 45 | + |
| 46 | +#ifndef timespecisvalid |
| 47 | +#define timespecisvalid(tsp) \ |
| 48 | + ((tsp)->tv_nsec >= 0 && (tsp)->tv_nsec < 1000000000L) |
| 49 | +#endif |
| 50 | + |
| 51 | +#ifndef timespeccmp |
| 52 | +#define timespeccmp(tsp, usp, cmp) \ |
| 53 | + (((tsp)->tv_sec == (usp)->tv_sec) ? \ |
| 54 | + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ |
| 55 | + ((tsp)->tv_sec cmp (usp)->tv_sec)) |
| 56 | +#endif |
| 57 | + |
| 58 | +#ifndef timespecadd |
| 59 | +#define timespecadd(tsp, usp, vsp) \ |
| 60 | + do { \ |
| 61 | + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ |
| 62 | + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ |
| 63 | + if ((vsp)->tv_nsec >= 1000000000L) { \ |
| 64 | + (vsp)->tv_sec++; \ |
| 65 | + (vsp)->tv_nsec -= 1000000000L; \ |
| 66 | + } \ |
| 67 | + } while (0) |
| 68 | +#endif |
| 69 | + |
| 70 | +#ifndef timespecsub |
| 71 | +#define timespecsub(tsp, usp, vsp) \ |
| 72 | + do { \ |
| 73 | + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ |
| 74 | + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ |
| 75 | + if ((vsp)->tv_nsec < 0) { \ |
| 76 | + (vsp)->tv_sec--; \ |
| 77 | + (vsp)->tv_nsec += 1000000000L; \ |
| 78 | + } \ |
| 79 | + } while (0) |
| 80 | +#endif |
| 81 | + |
| 82 | +#endif |
0 commit comments