Ruby: include/ruby/missing.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

missing.h
Go to the documentation of this file.
1#ifndef RUBY_MISSING_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RUBY_MISSING_H 1
13#include "ruby/internal/config.h"
14
15#ifdef STDC_HEADERS
16# include <stddef.h>
17#endif
18
19#if defined(__cplusplus)
20# include <cmath>
21#else
22# include <math.h> /* for INFINITY and NAN */
23#endif
24
25#ifdef RUBY_ALTERNATIVE_MALLOC_HEADER
26# include RUBY_ALTERNATIVE_MALLOC_HEADER
27#endif
28
29#if defined(HAVE_TIME_H)
30# include <time.h>
31#endif
32
33#if defined(HAVE_SYS_TIME_H)
34# include <sys/time.h>
35#endif
36
37#ifdef HAVE_IEEEFP_H
38# include <ieeefp.h>
39#endif
40
41#include "ruby/internal/dllexport.h"
42
43#ifndef M_PI
44# define M_PI 3.14159265358979323846
45#endif
46#ifndef M_PI_2
47# define M_PI_2 (M_PI/2)
48#endif
49
50#if !defined(HAVE_STRUCT_TIMEVAL)
51 struct timeval {
52 time_t tv_sec; /* seconds */
53 long tv_usec; /* microseconds */
54};
55#endif /* HAVE_STRUCT_TIMEVAL */
56
57#if !defined(HAVE_STRUCT_TIMESPEC)
58/* :BEWARE: @shyouhei warns that IT IS A WRONG IDEA to define our own version
59 * of struct timespec here. `clock_gettime` is a system call, and your kernel
60 * could expect something other than just `long` (results stack smashing if
61 * that happens). See also https://ewontfix.com/19/ */
62 struct timespec {
63 time_t tv_sec; /* seconds */
64 long tv_nsec; /* nanoseconds */
65};
66#endif
67
68#if !defined(HAVE_STRUCT_TIMEZONE)
69 struct timezone {
70 int tz_minuteswest;
71 int tz_dsttime;
72};
73#endif
74
75 RBIMPL_SYMBOL_EXPORT_BEGIN()
76
77#ifndef HAVE_ACOSH
78 RUBY_EXTERN double acosh(double);
79 RUBY_EXTERN double asinh(double);
80 RUBY_EXTERN double atanh(double);
81#endif
82
83#ifndef HAVE_CRYPT
84 RUBY_EXTERN char *crypt(const char *, const char *);
85#endif
86
87#ifndef HAVE_DUP2
88 RUBY_EXTERN int dup2(int, int);
89#endif
90
91#ifndef HAVE_EACCESS
92 RUBY_EXTERN int eaccess(const char*, int);
93#endif
94
95#ifndef HAVE_ROUND
96 RUBY_EXTERN double round(double); /* numeric.c */
97#endif
98
99#ifndef HAVE_FINITE
100 RUBY_EXTERN int finite(double);
101#endif
102
103#ifndef HAVE_FLOCK
104 RUBY_EXTERN int flock(int, int);
105#endif
106
107/*
108#ifndef HAVE_FREXP
109RUBY_EXTERN double frexp(double, int *);
110#endif
111*/
112
113#ifndef HAVE_HYPOT
114 RUBY_EXTERN double hypot(double, double);
115#endif
116
117#ifndef HAVE_ERF
118 RUBY_EXTERN double erf(double);
119 RUBY_EXTERN double erfc(double);
120#endif
121
122#ifndef HAVE_TGAMMA
123 RUBY_EXTERN double tgamma(double);
124#endif
125
126#ifndef HAVE_LGAMMA_R
127 RUBY_EXTERN double lgamma_r(double, int *);
128#endif
129
130#ifndef HAVE_CBRT
131 RUBY_EXTERN double cbrt(double);
132#endif
133
134#if !defined(INFINITY) || !defined(NAN)
135 union bytesequence4_or_float {
136 unsigned char bytesequence[4];
137 float float_value;
138};
139#endif
140
141#ifndef INFINITY
143 RUBY_EXTERN const union bytesequence4_or_float rb_infinity;
144# define INFINITY (rb_infinity.float_value)
145# define USE_RB_INFINITY 1
146#endif
147
148#ifndef NAN
150 RUBY_EXTERN const union bytesequence4_or_float rb_nan;
151# define NAN (rb_nan.float_value)
152# define USE_RB_NAN 1
153#endif
154
155#ifndef HUGE_VAL
156# define HUGE_VAL ((double)INFINITY)
157#endif
158
159#if defined(isinf)
160# /* Take that. */
161#elif defined(HAVE_ISINF)
162# /* Take that. */
163#elif defined(HAVE_FINITE) && defined(HAVE_ISNAN)
164# define isinf(x) (!finite(x) && !isnan(x))
165#elif defined(__cplusplus) && __cplusplus >= 201103L
166# // <cmath> must include constexpr bool isinf(double);
167#else
168 RUBY_EXTERN int isinf(double);
169#endif
170
171#if defined(isnan)
172# /* Take that. */
173#elif defined(HAVE_ISNAN)
174# /* Take that. */
175#elif defined(__cplusplus) && __cplusplus >= 201103L
176# // <cmath> must include constexpr bool isnan(double);
177#else
178 RUBY_EXTERN int isnan(double);
179#endif
180
181#if defined(isfinite)
182# /* Take that. */
183#elif defined(HAVE_ISFINITE)
184# /* Take that. */
185#else
186# define HAVE_ISFINITE 1
187# define isfinite(x) finite(x)
188#endif
189
190#ifndef HAVE_NAN
191 RUBY_EXTERN double nan(const char *);
192#endif
193
194#ifndef HAVE_NEXTAFTER
195 RUBY_EXTERN double nextafter(double x, double y);
196#endif
197
198/*
199#ifndef HAVE_MEMCMP
200RUBY_EXTERN int memcmp(const void *, const void *, size_t);
201#endif
202*/
203
204#ifndef HAVE_MEMMOVE
205 RUBY_EXTERN void *memmove(void *, const void *, size_t);
206#endif
207
208/*
209#ifndef HAVE_MODF
210RUBY_EXTERN double modf(double, double *);
211#endif
212*/
213
214#ifndef HAVE_STRCHR
215 RUBY_EXTERN char *strchr(const char *, int);
216 RUBY_EXTERN char *strrchr(const char *, int);
217#endif
218
219#ifndef HAVE_STRERROR
220 RUBY_EXTERN char *strerror(int);
221#endif
222
223#ifndef HAVE_STRSTR
224 RUBY_EXTERN char *strstr(const char *, const char *);
225#endif
226
227#ifndef HAVE_STRLCPY
228 RUBY_EXTERN size_t strlcpy(char *, const char*, size_t);
229#endif
230
231#ifndef HAVE_STRLCAT
232 RUBY_EXTERN size_t strlcat(char *, const char*, size_t);
233#endif
234
235#ifndef HAVE_SIGNBIT
236 RUBY_EXTERN int signbit(double x);
237#endif
238
239#ifndef HAVE_FFS
240 RUBY_EXTERN int ffs(int);
241#endif
242
243#ifdef BROKEN_CLOSE
244# include <sys/types.h>
245# include <sys/socket.h>
246 RUBY_EXTERN int ruby_getpeername(int, struct sockaddr *, socklen_t *);
247 RUBY_EXTERN int ruby_getsockname(int, struct sockaddr *, socklen_t *);
248 RUBY_EXTERN int ruby_shutdown(int, int);
249 RUBY_EXTERN int ruby_close(int);
250#endif
251
252#ifndef HAVE_SETPROCTITLE
253 RUBY_EXTERN void setproctitle(const char *fmt, ...);
254#endif
255
256#ifdef HAVE_EXPLICIT_BZERO
257# /* Take that. */
258#elif defined(SecureZeroMemory)
259# define explicit_bzero(b, len) SecureZeroMemory(b, len)
260#else
261 RUBY_EXTERN void explicit_bzero(void *b, size_t len);
262#endif
263
264 RBIMPL_SYMBOL_EXPORT_END()
265
266#endif /* RUBY_MISSING_H */
ruby_getpeername
int ruby_getpeername(int s, struct sockaddr *name, socklen_t *namelen)
Definition: close.c:10
ruby_close
int ruby_close(int s)
Definition: close.c:60
ruby_getsockname
int ruby_getsockname(int s, struct sockaddr *name, socklen_t *namelen)
Definition: close.c:27
ruby_shutdown
int ruby_shutdown(int s, int how)
Definition: close.c:44
dllexport.h
Tewaking visibility of C variables/functions.
RUBY_EXTERN
#define RUBY_EXTERN
Definition: dllexport.h:36
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
len
uint8_t len
Definition: escape.c:17
socklen_t
int socklen_t
Definition: getaddrinfo.c:83
config.h
Thin wrapper to ruby/config.h.
round
double round(double)
Definition: numeric.c:92
eaccess
int eaccess(const char *, int)
Definition: file.c:1529
rb_infinity
const union bytesequence4_or_float rb_infinity
Definition: numeric.c:78
dup2
int dup2(int, int)
Definition: dup2.c:27
hypot
double hypot(double, double)
Definition: hypot.c:6
strstr
char * strstr(const char *, const char *)
Definition: strstr.c:8
strerror
char * strerror(int)
Definition: strerror.c:11
erfc
double erfc(double)
Definition: erf.c:81
ffs
int ffs(int)
Definition: ffs.c:6
strrchr
char * strrchr(const char *, int)
Definition: strchr.c:20
strlcat
size_t strlcat(char *, const char *, size_t)
Definition: strlcat.c:31
strlcpy
size_t strlcpy(char *, const char *, size_t)
Definition: strlcpy.c:29
tgamma
double tgamma(double)
Definition: tgamma.c:66
signbit
int signbit(double x)
Definition: signbit.c:5
nan
double nan(const char *)
Definition: nan.c:7
memmove
void * memmove(void *, const void *, size_t)
Definition: memmove.c:7
atanh
double atanh(double)
Definition: acosh.c:75
acosh
double acosh(double)
Definition: acosh.c:36
strchr
char * strchr(const char *, int)
Definition: strchr.c:8
crypt
char * crypt(const char *, const char *)
lgamma_r
double lgamma_r(double, int *)
Definition: lgamma_r.c:63
finite
int finite(double)
Definition: finite.c:6
rb_nan
const union bytesequence4_or_float rb_nan
Definition: numeric.c:85
nextafter
double nextafter(double x, double y)
Definition: nextafter.c:9
explicit_bzero
void explicit_bzero(void *b, size_t len)
Definition: explicit_bzero.c:77
setproctitle
void setproctitle(const char *fmt,...)
Definition: setproctitle.c:139
asinh
double asinh(double)
Definition: acosh.c:52
cbrt
double cbrt(double)
Definition: cbrt.c:4
flock
int flock(int, int)
Definition: flock.c:125
erf
double erf(double)
Definition: erf.c:71
isinf
int isinf(double n)
Definition: isinf.c:56
math.h
Internal header for Math.
timespec
Definition: missing.h:62
timespec::tv_nsec
long tv_nsec
Definition: missing.h:64
timespec::tv_sec
time_t tv_sec
Definition: missing.h:63
timeval
Definition: missing.h:51
timeval::tv_usec
long tv_usec
Definition: missing.h:53
timeval::tv_sec
time_t tv_sec
Definition: missing.h:52
timezone
Definition: missing.h:69
timezone::tz_minuteswest
int tz_minuteswest
Definition: missing.h:70
timezone::tz_dsttime
int tz_dsttime
Definition: missing.h:71
bytesequence4_or_float
Definition: missing.h:135
bytesequence4_or_float::bytesequence
unsigned char bytesequence[4]
Definition: missing.h:136
bytesequence4_or_float::float_value
float float_value
Definition: missing.h:137
isnan
#define isnan(x)
Definition: win32.h:346