-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsleep.h
144 lines (133 loc) · 4.34 KB
/
sleep.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*-
* Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
* 2019, 2020, 2021
* mirabilos <[email protected]>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un‐
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person’s immediate fault when using the work as intended.
*/
#ifdef MKSH_USE_AUTOCONF_H
/* things that “should” have been on the command line */
#include "autoconf.h"
#undef MKSH_USE_AUTOCONF_H
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/types.h>
#if HAVE_BOTH_TIME_H && HAVE_SELECT_TIME_H
#include <sys/time.h>
#include <time.h>
#elif HAVE_SYS_TIME_H && HAVE_SELECT_TIME_H
#include <sys/time.h>
#elif HAVE_TIME_H
#include <time.h>
#endif
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#if HAVE_SYS_BSDTYPES_H
#include <sys/bsdtypes.h>
#endif
#if HAVE_BSTRING_H
#include <bstring.h>
#endif
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_STRINGS_H
#include <strings.h>
#endif
#include <unistd.h>
/* from mksh */
#if HAVE_ATTRIBUTE_FORMAT
#define MKSH_A_FORMAT(x,y,z) __attribute__((__format__(x, y, z)))
#else
#define MKSH_A_FORMAT(x,y,z) /* nothing */
#endif
#if HAVE_ATTRIBUTE_NORETURN
#define MKSH_A_NORETURN __attribute__((__noreturn__))
#else
#define MKSH_A_NORETURN /* nothing */
#endif
#if HAVE_ATTRIBUTE_UNUSED
#define MKSH_A_UNUSED __attribute__((__unused__))
#else
#define MKSH_A_UNUSED /* nothing */
#endif
#if HAVE_ATTRIBUTE_USED
#define MKSH_A_USED __attribute__((__used__))
#else
#define MKSH_A_USED /* nothing */
#endif
#if defined(MirBSD) && (MirBSD >= 0x09A1) && \
defined(__ELF__) && defined(__GNUC__) && \
!defined(__llvm__) && !defined(__NWCC__)
/*
* We got usable __IDSTRING __COPYRIGHT __RCSID __SCCSID macros
* which work for all cases; no need to redefine them using the
* "portable" macros from below when we might have the "better"
* gcc+ELF specific macros or other system dependent ones.
*/
#else
#undef __IDSTRING
#undef __IDSTRING_CONCAT
#undef __IDSTRING_EXPAND
#undef __COPYRIGHT
#undef __RCSID
#undef __SCCSID
#define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p
#define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p)
#ifdef MKSH_DONT_EMIT_IDSTRING
#define __IDSTRING(prefix,string) /* nothing */
#elif defined(__ELF__) && defined(__GNUC__) && \
!(defined(__GNUC__) && defined(__mips16) && (__GNUC__ >= 8)) && \
!defined(__llvm__) && !defined(__NWCC__) && !defined(NO_ASM)
#define __IDSTRING(prefix,string) \
__asm__(".section .comment" \
"\n .ascii \"@(\"\"#)" #prefix ": \"" \
"\n .asciz \"" string "\"" \
"\n .previous")
#else
#define __IDSTRING(prefix,string) \
static const char __IDSTRING_EXPAND(__LINE__,prefix) [] \
MKSH_A_USED = "@(""#)" #prefix ": " string
#endif
#define __COPYRIGHT(x) __IDSTRING(copyright,x)
#define __RCSID(x) __IDSTRING(rcsid,x)
#define __SCCSID(x) __IDSTRING(sccsid,x)
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/sleep/sleep.h,v 1.5 2021/10/03 20:48:08 tg Exp $");
#endif
#define ord(c) ((unsigned int)(unsigned char)(c))
/* maximum value of a type, no matter which signedness */
#define type_max(t) (((t)(-1) < (t)0) ? \
(((t)((t)1 << (sizeof(t)*CHAR_BIT - 2)) - (t)1) * (t)2 + (t)1) : \
((t)~(t)0))
/* check for overflow */
#define notoktomula(t,val,c,a) (((val) != 0) && ((c) != 0) && \
(((type_max(t) - (t)(a)) / (t)(c)) < (t)(val)))
#define notoktoadd(t,val,c) ((t)(val) > (type_max(t) - (t)(c)))
/* missing functions */
#if !HAVE_STRERROR
#define strerror(e) "no strerror to decode errno"
#endif
#define MIRBSD_SLEEP_VERSION "2021-10-03"