2020-04-10 01:11:40 -04:00
|
|
|
#ifndef RUBY_MISSING_H /*-*-C++-*-vi:se ft=cpp:*/
|
|
|
|
#define RUBY_MISSING_H 1
|
|
|
|
/**
|
2020-04-08 00:28:13 -04:00
|
|
|
* @file
|
|
|
|
* @author $Author$
|
|
|
|
* @date Sat May 11 23:46:03 JST 2002
|
|
|
|
* @copyright This file is a part of the programming language Ruby.
|
|
|
|
* Permission is hereby granted, to either redistribute and/or
|
|
|
|
* modify this file, provided that the conditions mentioned in the
|
|
|
|
* file COPYING are met. Consult the file for details.
|
|
|
|
* @brief Prototype for *.c in ./missing, and for missing timeval struct.
|
|
|
|
*/
|
2020-05-08 05:31:09 -04:00
|
|
|
#include "ruby/internal/config.h"
|
2020-04-08 00:28:13 -04:00
|
|
|
|
|
|
|
#ifdef STDC_HEADERS
|
|
|
|
# include <stddef.h>
|
2007-06-09 23:06:15 -04:00
|
|
|
#endif
|
2020-04-08 00:28:13 -04:00
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
# include <cmath>
|
|
|
|
#else
|
|
|
|
# include <math.h> /* for INFINITY and NAN */
|
2007-06-09 23:06:15 -04:00
|
|
|
#endif
|
2002-05-11 15:31:18 -04:00
|
|
|
|
2014-06-05 01:16:46 -04:00
|
|
|
#ifdef RUBY_ALTERNATIVE_MALLOC_HEADER
|
|
|
|
# include RUBY_ALTERNATIVE_MALLOC_HEADER
|
|
|
|
#endif
|
2010-07-27 05:33:55 -04:00
|
|
|
|
2013-03-16 03:28:32 -04:00
|
|
|
#if defined(HAVE_TIME_H)
|
|
|
|
# include <time.h>
|
|
|
|
#endif
|
2020-04-08 00:28:13 -04:00
|
|
|
|
2013-03-16 11:58:25 -04:00
|
|
|
#if defined(HAVE_SYS_TIME_H)
|
2013-03-16 03:28:32 -04:00
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
2020-04-08 00:28:13 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_IEEEFP_H
|
|
|
|
# include <ieeefp.h>
|
2013-03-16 11:16:32 -04:00
|
|
|
#endif
|
2013-03-16 03:28:32 -04:00
|
|
|
|
2020-05-08 05:31:09 -04:00
|
|
|
#include "ruby/internal/dllexport.h"
|
2020-04-08 00:28:13 -04:00
|
|
|
|
2015-07-21 06:51:40 -04:00
|
|
|
#ifndef M_PI
|
|
|
|
# define M_PI 3.14159265358979323846
|
|
|
|
#endif
|
|
|
|
#ifndef M_PI_2
|
|
|
|
# define M_PI_2 (M_PI/2)
|
|
|
|
#endif
|
|
|
|
|
2013-03-16 01:06:47 -04:00
|
|
|
#if !defined(HAVE_STRUCT_TIMEVAL)
|
2002-09-17 09:52:45 -04:00
|
|
|
struct timeval {
|
|
|
|
time_t tv_sec; /* seconds */
|
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 04:09:38 -05:00
|
|
|
long tv_usec; /* microseconds */
|
2002-09-17 09:52:45 -04:00
|
|
|
};
|
2013-03-16 01:06:47 -04:00
|
|
|
#endif /* HAVE_STRUCT_TIMEVAL */
|
|
|
|
|
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 04:09:38 -05:00
|
|
|
#if !defined(HAVE_STRUCT_TIMESPEC)
|
2020-04-08 00:28:13 -04:00
|
|
|
/* :BEWARE: @shyouhei warns that IT IS A WRONG IDEA to define our own version
|
|
|
|
* of struct timespec here. `clock_gettime` is a system call, and your kernel
|
|
|
|
* could expect something other than just `long` (results stack smashing if
|
|
|
|
* that happens). See also https://ewontfix.com/19/ */
|
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 04:09:38 -05:00
|
|
|
struct timespec {
|
|
|
|
time_t tv_sec; /* seconds */
|
|
|
|
long tv_nsec; /* nanoseconds */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-01-12 16:54:47 -05:00
|
|
|
#if !defined(HAVE_STRUCT_TIMEZONE)
|
|
|
|
struct timezone {
|
|
|
|
int tz_minuteswest;
|
|
|
|
int tz_dsttime;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-05-04 02:52:56 -04:00
|
|
|
RBIMPL_SYMBOL_EXPORT_BEGIN()
|
2010-07-21 17:38:25 -04:00
|
|
|
|
2002-05-11 15:31:18 -04:00
|
|
|
#ifndef HAVE_ACOSH
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double acosh(double);
|
|
|
|
RUBY_EXTERN double asinh(double);
|
|
|
|
RUBY_EXTERN double atanh(double);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_CRYPT
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN char *crypt(const char *, const char *);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_DUP2
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN int dup2(int, int);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
2006-01-25 08:30:11 -05:00
|
|
|
#ifndef HAVE_EACCESS
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN int eaccess(const char*, int);
|
2006-01-25 08:30:11 -05:00
|
|
|
#endif
|
|
|
|
|
2011-06-03 07:58:11 -04:00
|
|
|
#ifndef HAVE_ROUND
|
|
|
|
RUBY_EXTERN double round(double); /* numeric.c */
|
|
|
|
#endif
|
|
|
|
|
2002-05-11 15:31:18 -04:00
|
|
|
#ifndef HAVE_FINITE
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN int finite(double);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_FLOCK
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN int flock(int, int);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
#ifndef HAVE_FREXP
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double frexp(double, int *);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_HYPOT
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double hypot(double, double);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
2003-06-05 02:40:42 -04:00
|
|
|
#ifndef HAVE_ERF
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double erf(double);
|
|
|
|
RUBY_EXTERN double erfc(double);
|
2003-06-05 02:40:42 -04:00
|
|
|
#endif
|
|
|
|
|
2008-02-06 20:43:43 -05:00
|
|
|
#ifndef HAVE_TGAMMA
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double tgamma(double);
|
2008-02-06 20:43:43 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_LGAMMA_R
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double lgamma_r(double, int *);
|
2008-02-06 20:43:43 -05:00
|
|
|
#endif
|
|
|
|
|
2008-03-06 00:06:30 -05:00
|
|
|
#ifndef HAVE_CBRT
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double cbrt(double);
|
2008-03-06 00:06:30 -05:00
|
|
|
#endif
|
|
|
|
|
2018-01-26 23:14:26 -05:00
|
|
|
#if !defined(INFINITY) || !defined(NAN)
|
2011-10-21 13:34:58 -04:00
|
|
|
union bytesequence4_or_float {
|
|
|
|
unsigned char bytesequence[4];
|
|
|
|
float float_value;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-10-19 12:29:31 -04:00
|
|
|
#ifndef INFINITY
|
2011-06-06 02:11:37 -04:00
|
|
|
/** @internal */
|
2011-10-21 13:34:58 -04:00
|
|
|
RUBY_EXTERN const union bytesequence4_or_float rb_infinity;
|
|
|
|
# define INFINITY (rb_infinity.float_value)
|
2018-01-26 23:14:26 -05:00
|
|
|
# define USE_RB_INFINITY 1
|
2011-06-06 02:11:37 -04:00
|
|
|
#endif
|
|
|
|
|
2015-10-19 12:29:31 -04:00
|
|
|
#ifndef NAN
|
2011-06-06 02:11:37 -04:00
|
|
|
/** @internal */
|
2011-10-21 13:34:58 -04:00
|
|
|
RUBY_EXTERN const union bytesequence4_or_float rb_nan;
|
|
|
|
# define NAN (rb_nan.float_value)
|
2018-01-26 23:14:26 -05:00
|
|
|
# define USE_RB_NAN 1
|
2011-06-06 02:11:37 -04:00
|
|
|
#endif
|
2018-01-18 20:45:36 -05:00
|
|
|
|
|
|
|
#ifndef HUGE_VAL
|
|
|
|
# define HUGE_VAL ((double)INFINITY)
|
|
|
|
#endif
|
2011-06-06 02:11:37 -04:00
|
|
|
|
2020-04-08 00:28:13 -04:00
|
|
|
#if defined(isinf)
|
|
|
|
# /* Take that. */
|
|
|
|
#elif defined(HAVE_ISINF)
|
|
|
|
# /* Take that. */
|
|
|
|
#elif defined(HAVE_FINITE) && defined(HAVE_ISNAN)
|
|
|
|
# define isinf(x) (!finite(x) && !isnan(x))
|
|
|
|
#elif defined(__cplusplus) && __cplusplus >= 201103L
|
|
|
|
# // <cmath> must include constexpr bool isinf(double);
|
|
|
|
#else
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN int isinf(double);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
2020-04-08 00:28:13 -04:00
|
|
|
#if defined(isnan)
|
|
|
|
# /* Take that. */
|
|
|
|
#elif defined(HAVE_ISNAN)
|
|
|
|
# /* Take that. */
|
|
|
|
#elif defined(__cplusplus) && __cplusplus >= 201103L
|
|
|
|
# // <cmath> must include constexpr bool isnan(double);
|
|
|
|
#else
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN int isnan(double);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
2020-04-08 00:28:13 -04:00
|
|
|
#if defined(isfinite)
|
|
|
|
# /* Take that. */
|
|
|
|
#elif defined(HAVE_ISFINITE)
|
|
|
|
# /* Take that. */
|
|
|
|
#else
|
|
|
|
# define HAVE_ISFINITE 1
|
|
|
|
# define isfinite(x) finite(x)
|
2016-05-23 08:33:39 -04:00
|
|
|
#endif
|
|
|
|
|
2018-01-26 11:38:38 -05:00
|
|
|
#ifndef HAVE_NAN
|
|
|
|
RUBY_EXTERN double nan(const char *);
|
|
|
|
#endif
|
|
|
|
|
2014-05-17 20:37:10 -04:00
|
|
|
#ifndef HAVE_NEXTAFTER
|
|
|
|
RUBY_EXTERN double nextafter(double x, double y);
|
|
|
|
#endif
|
|
|
|
|
2002-05-11 15:31:18 -04:00
|
|
|
/*
|
|
|
|
#ifndef HAVE_MEMCMP
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN int memcmp(const void *, const void *, size_t);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_MEMMOVE
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN void *memmove(void *, const void *, size_t);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
#ifndef HAVE_MODF
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN double modf(double, double *);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_STRCHR
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN char *strchr(const char *, int);
|
|
|
|
RUBY_EXTERN char *strrchr(const char *, int);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRERROR
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN char *strerror(int);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRSTR
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN char *strstr(const char *, const char *);
|
2002-05-11 15:31:18 -04:00
|
|
|
#endif
|
|
|
|
|
2007-03-19 04:01:40 -04:00
|
|
|
#ifndef HAVE_STRLCPY
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN size_t strlcpy(char *, const char*, size_t);
|
2007-03-19 04:01:40 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRLCAT
|
2008-11-03 02:32:57 -05:00
|
|
|
RUBY_EXTERN size_t strlcat(char *, const char*, size_t);
|
2007-03-19 04:01:40 -04:00
|
|
|
#endif
|
|
|
|
|
2010-05-15 22:39:18 -04:00
|
|
|
#ifndef HAVE_SIGNBIT
|
|
|
|
RUBY_EXTERN int signbit(double x);
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 09:23:20 -04:00
|
|
|
#ifndef HAVE_FFS
|
|
|
|
RUBY_EXTERN int ffs(int);
|
|
|
|
#endif
|
|
|
|
|
2010-07-25 23:05:25 -04:00
|
|
|
#ifdef BROKEN_CLOSE
|
2020-04-08 00:28:13 -04:00
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/socket.h>
|
2010-07-22 01:41:54 -04:00
|
|
|
RUBY_EXTERN int ruby_getpeername(int, struct sockaddr *, socklen_t *);
|
|
|
|
RUBY_EXTERN int ruby_getsockname(int, struct sockaddr *, socklen_t *);
|
|
|
|
RUBY_EXTERN int ruby_shutdown(int, int);
|
|
|
|
RUBY_EXTERN int ruby_close(int);
|
|
|
|
#endif
|
|
|
|
|
2011-05-14 06:49:47 -04:00
|
|
|
#ifndef HAVE_SETPROCTITLE
|
|
|
|
RUBY_EXTERN void setproctitle(const char *fmt, ...);
|
|
|
|
#endif
|
|
|
|
|
2020-04-08 00:28:13 -04:00
|
|
|
#ifdef HAVE_EXPLICIT_BZERO
|
|
|
|
# /* Take that. */
|
|
|
|
#elif defined(SecureZeroMemory)
|
|
|
|
# define explicit_bzero(b, len) SecureZeroMemory(b, len)
|
|
|
|
#else
|
2015-11-30 15:26:13 -05:00
|
|
|
RUBY_EXTERN void explicit_bzero(void *b, size_t len);
|
|
|
|
#endif
|
|
|
|
|
2020-05-04 02:52:56 -04:00
|
|
|
RBIMPL_SYMBOL_EXPORT_END()
|
2007-06-09 23:06:15 -04:00
|
|
|
|
|
|
|
#endif /* RUBY_MISSING_H */
|