6 * Ideally this should be somewhere down in the includes
7 * but putting it in other places is giving compiler errors.
8 * Also here I am unable to check for HAS_UNAME since it wouldn't have
9 * yet come into the file at this stage - sgp 18th Oct 2000
11 #include <sys/utsname.h>
14 #define PERL_NO_GET_CONTEXT
17 #define PERLIO_NOT_STDIO 1
20 #if defined(PERL_IMPLICIT_SYS)
24 # define open PerlLIO_open3
27 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
32 #include <sys/errno2.h>
61 # define M_E 2.71828182845904523536028747135266250
64 # define M_LOG2E 1.44269504088896340735992468100189214
67 # define M_LOG10E 0.434294481903251827651128918916605082
70 # define M_LN2 0.693147180559945309417232121458176568
73 # define M_LN10 2.30258509299404568401799145468436421
76 # define M_PI 3.14159265358979323846264338327950288
79 # define M_PI_2 1.57079632679489661923132169163975144
82 # define M_PI_4 0.785398163397448309615660845819875721
85 # define M_1_PI 0.318309886183790671537767526745028724
88 # define M_2_PI 0.636619772367581343075535053490057448
91 # define M_2_SQRTPI 1.12837916709551257389615890312154517
94 # define M_SQRT2 1.41421356237309504880168872420969808
97 # define M_SQRT1_2 0.707106781186547524400844362104849039
100 #if !defined(INFINITY) && defined(NV_INF)
101 # define INFINITY NV_INF
104 #if !defined(NAN) && defined(NV_NAN)
108 #if !defined(Inf) && defined(NV_INF)
112 #if !defined(NaN) && defined(NV_NAN)
116 /* We will have an emulation. */
118 # define FP_INFINITE 0
121 # define FP_SUBNORMAL 3
127 acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp ldexp
128 log log10 modf pow sin sinh sqrt tan tanh
130 * Implemented in core:
132 atan2 cos exp log pow sin sqrt
134 * Berkeley/SVID extensions:
140 acosh asinh atanh cbrt copysign cosh erf erfc exp2 expm1 fdim fma
141 fmax fmin fpclassify hypot ilogb isfinite isgreater isgreaterequal
142 isinf isless islessequal islessgreater isnan isnormal isunordered
143 lgamma log1p log2 logb lrint nan nearbyint nextafter nexttoward remainder
144 remquo rint round scalbn signbit sinh tanh tgamma trunc
146 * Configure already (5.21.0) scans for:
148 fpclassify isfinite isinf isnan ilogb*l* signbit
152 /* XXX Add ldiv(), lldiv()? It's C99, but from stdlib.h, not math.h */
154 /* XXX Beware old gamma() -- one cannot know whether that is the
155 gamma or the log of gamma, that's why the new tgamma and lgamma. */
157 /* XXX The truthiness of acosh() is the canary for all of the
158 * C99 math. This is very likely wrong, especially in non-UNIX lands
159 * like Win32 and VMS, but also older UNIXes have issues. For Win32
160 * we later do some undefines for these interfaces.
162 * But we are very trying very hard to avoid introducing separate Configure
163 * symbols for all the 40-ish new math symbols. Especially since the set
164 * of missing functions doesn't seem to follow any patterns. */
167 # if defined(USE_LONG_DOUBLE) && defined(HAS_ILOGBL)
168 /* There's already a symbol for ilogbl, we will use its truthiness
169 * as the canary for all the *l variants being defined. */
170 # define c99_acosh acoshl
171 # define c99_asinh asinhl
172 # define c99_atanh atanhl
173 # define c99_cbrt cbrtl
174 # define c99_copysign copysignl
175 # define c99_erf erfl
176 # define c99_erfc erfcl
177 # define c99_exp2 exp2l
178 # define c99_expm1 expm1l
179 # define c99_fdim fdiml
180 # define c99_fma fmal
181 # define c99_fmax fmaxl
182 # define c99_fmin fminl
183 # define c99_hypot hypotl
184 # define c99_ilogb ilogbl
185 # define c99_lgamma gammal
186 # define c99_log1p log1pl
187 # define c99_log2 log2l
188 # define c99_logb logbl
189 # if defined(USE_64_BIT_INT) && QUADKIND == QUAD_IS_LONG_LONG
190 # define c99_lrint llrintl
192 # define c99_lrint lrintl
194 # define c99_nan nanl
195 # define c99_nearbyint nearbyintl
196 # define c99_nextafter nextafterl
197 # define c99_nexttoward nexttowardl
198 # define c99_remainder remainderl
199 # define c99_remquo remquol
200 # define c99_rint rintl
201 # define c99_round roundl
202 # define c99_scalbn scalbnl
203 # ifdef HAS_SIGNBIT /* possibly bad assumption */
204 # define c99_signbit signbitl
206 # define c99_tgamma tgammal
207 # define c99_trunc truncl
209 # define c99_acosh acosh
210 # define c99_asinh asinh
211 # define c99_atanh atanh
212 # define c99_cbrt cbrt
213 # define c99_copysign copysign
215 # define c99_erfc erfc
216 # define c99_exp2 exp2
217 # define c99_expm1 expm1
218 # define c99_fdim fdim
220 # define c99_fmax fmax
221 # define c99_fmin fmin
222 # define c99_hypot hypot
223 # define c99_ilogb ilogb
224 # define c99_lgamma lgamma
225 # define c99_log1p log1p
226 # define c99_log2 log2
227 # define c99_logb logb
228 # if defined(USE_64_BIT_INT) && QUADKIND == QUAD_IS_LONG_LONG
229 # define c99_lrint llrint
231 # define c99_lrint lrint
234 # define c99_nearbyint nearbyint
235 # define c99_nextafter nextafter
236 # define c99_nexttoward nexttoward
237 # define c99_remainder remainder
238 # define c99_remquo remquo
239 # define c99_rint rint
240 # define c99_round round
241 # define c99_scalbn scalbn
242 /* We already define Perl_signbit in perl.h. */
244 # define c99_signbit signbit
246 # define c99_tgamma tgamma
247 # define c99_trunc trunc
250 /* Check both the Configure symbol and the macro-ness (like C99 promises). */
251 # if defined(HAS_FPCLASSIFY) && defined(fpclassify)
252 # define c99_fpclassify fpclassify
254 /* Like isnormal(), the isfinite(), isinf(), and isnan() are also C99
255 and also (sizeof-arg-aware) macros, but they are already well taken
256 care of by Configure et al, and defined in perl.h as
257 Perl_isfinite(), Perl_isinf(), and Perl_isnan(). */
259 # define c99_isnormal isnormal
261 # ifdef isgreater /* canary for all the C99 is*<cmp>* macros. */
262 # define c99_isgreater isgreater
263 # define c99_isgreaterequal isgreaterequal
264 # define c99_isless isless
265 # define c99_islessequal islessequal
266 # define c99_islessgreater islessgreater
267 # define c99_isunordered isunordered
271 /* If on legacy platforms, and not using gcc, some C99 math interfaces
272 * might be missing, turn them off so that the emulations hopefully
273 * kick in. This is admittedly nasty, and fragile, but the alternative
274 * is to have Configure scans for all the 40+ interfaces.
276 * In other words: if you have an incomplete (or broken) C99 math interface,
277 * #undef the c99_foo here, and let the emulations kick in. */
281 /* HP-UX on PA-RISC is missing certain C99 math functions,
282 * but on IA64 (Integrity) these do exist. */
283 # if defined(__hpux) && defined(__hppa)
289 # undef c99_fpclassify
292 # undef c99_nearbyint
293 # undef c99_nexttoward
301 # if defined(__irix__)
306 # if defined(__osf__) /* Tru64 */
311 # undef c99_fpclassify
314 # undef c99_isunordered
316 # undef c99_nearbyint
317 # undef c99_nexttoward
326 /* XXX Regarding C99 math.h, VMS seems to be missing these:
328 nan nearbyint round scalbn
333 # undef c99_nearbyint
338 /* XXX Regarding C99 math.h, Win32 seems to be missing these:
340 exp2 fdim fma fmax fmin fpclassify ilogb lgamma log1p log2 lrint
341 remquo rint signbit tgamma trunc
343 Win32 does seem to have these:
345 acosh asinh atanh cbrt copysign cosh erf erfc expm1 hypot log10 nan
346 nearbyint nextafter nexttoward remainder round scalbn
348 And the Bessel functions are defined like _this.
368 /* Some APIs exist under Win32 with "underbar" names. */
371 # undef c99_nextafter
372 # define c99_hypot _hypot
373 # define c99_logb _logb
374 # define c99_nextafter _nextafter
376 # define bessel_j0 _j0
377 # define bessel_j1 _j1
378 # define bessel_jn _jn
379 # define bessel_y0 _y0
380 # define bessel_y1 _y1
381 # define bessel_yn _yn
385 /* The Bessel functions: BSD, SVID, XPG4, and POSIX. But not C99. */
387 # if defined(USE_LONG_DOUBLE) && defined(HAS_J0L)
388 # define bessel_j0 j0l
389 # define bessel_j1 j1l
390 # define bessel_jn jnl
391 # define bessel_y0 y0l
392 # define bessel_y1 y1l
393 # define bessel_yn ynl
395 # define bessel_j0 j0
396 # define bessel_j1 j1
397 # define bessel_jn jn
398 # define bessel_y0 y0
399 # define bessel_y1 y1
400 # define bessel_yn yn
404 /* Emulations for missing math APIs.
406 * Keep in mind that the point of many of these functions is that
407 * they, if available, are supposed to give more precise/more
408 * numerically stable results.
410 * See e.g. http://www.johndcook.com/math_h.html
414 static NV my_acosh(NV x)
416 return Perl_log(x + Perl_sqrt(x * x - 1));
418 # define c99_acosh my_acosh
422 static NV my_asinh(NV x)
424 return Perl_log(x + Perl_sqrt(x * x + 1));
426 # define c99_asinh my_asinh
430 static NV my_atanh(NV x)
432 return (Perl_log(1 + x) - Perl_log(1 - x)) / 2;
434 # define c99_atanh my_atanh
438 static NV my_cbrt(NV x)
440 static const NV one_third = (NV)1.0/3;
441 return x >= 0.0 ? Perl_pow(x, one_third) : -Perl_pow(-x, one_third);
443 # define c99_cbrt my_cbrt
447 static NV my_copysign(NV x, NV y)
449 return y >= 0 ? (x < 0 ? -x : x) : (x < 0 ? x : -x);
451 # define c99_copysign my_copysign
454 /* XXX cosh (though c89) */
456 /* XXX erf -- non-trivial */
457 /* XXX erfc -- non-trivial */
460 static NV my_exp2(NV x)
462 return Perl_pow((NV)2.0, x);
464 # define c99_exp2 my_exp2
468 static NV my_expm1(NV x)
470 if (PERL_ABS(x) < 1e-5)
471 /* Probably not enough for long doubles. */
472 return x * (1.0 + x * (0.5 + x / 6.0)); /* Taylor series */
474 return Perl_exp(x) - 1;
476 # define c99_expm1 my_expm1
480 static NV my_fdim(NV x, NV y)
482 return x > y ? x - y : 0;
484 # define c99_fdim my_fdim
488 static NV my_fmax(NV x, NV y)
491 return Perl_isnan(y) ? NV_NAN : y;
492 } else if (Perl_isnan(y)) {
495 return x > y ? x : y;
497 # define c99_fmax my_fmax
501 static NV my_fmin(NV x, NV y)
504 return Perl_isnan(y) ? NV_NAN : y;
505 } else if (Perl_isnan(y)) {
508 return x < y ? x : y;
510 # define c99_fmin my_fmin
513 static NV my_fpclassify(NV x)
515 #if defined(HAS_FPCLASSIFY) && defined(FP_PLUS_INF) /* E.g. HP-UX */
516 switch (Perl_fp_class(x)) {
517 case FP_PLUS_INF: case FP_MINUS_INF: return FP_INFINITE;
518 case FP_SNAN: case FP_QNAN: return FP_NAN;
519 case FP_PLUS_NORM: case FP_MINUS_NORM: return FP_NORMAL;
520 case FP_PLUS_DENORM: case FP_MINUS_DENORM: return FP_SUBNORMAL;
521 case FP_PLUS_ZERO: case FP_MINUS_ZERO: return FP_ZERO;
524 # define c99_fpclassify my_fpclassify
525 #elif (defined(HAS_FPCLASS) || defined(HAS_FPCLASSL)) && defined(FP_CLASS_SNAN)
526 switch (Perl_fp_class(x)) {
527 case FP_CLASS_NINF: case FP_CLASS_PINF: return FP_INFINITE;
528 case FP_CLASS_SNAN: case FP_CLASS_QNAN: return FP_NAN;
529 case FP_CLASS_NNORM: case FP_CLASS_PNORM: return FP_NORMAL;
530 case FP_CLASS_NDENORM: case FP_CLASS_PDENORM: return FP_SUBNORMAL;
531 case FP_CLASS_NZERO: case FP_CLASS_PZERO: return FP_ZERO;
534 # define c99_fpclassify my_fpclassify
535 #elif (defined(HAS_FPCLASS) || defined(HAS_FP_CLASSL)) && defined(FP_SNAN)
536 switch (Perl_fp_class(x)) {
537 case FP_NINF: case FP_PINF: return FP_INFINITE;
538 case FP_SNAN: case FP_QNAN: return FP_NAN;
539 case FP_NNORM: case FP_PNORM: return FP_NORMAL;
540 case FP_NDENORM: case FP_PDENORM: return FP_SUBNORMAL;
541 case FP_NZERO: case FP_PZERO: return FP_ZERO;
544 # define c99_fpclassify my_fpclassify
545 #elif defined(HAS_FP_CLASS) && defined(FP_POS_INF)
546 switch (Perl_fp_class(x)) {
547 case FP_NEG_INF: case FP_POS_INF: return FP_INFINITE;
548 case FP_SNAN: case FP_QNAN: return FP_NAN;
549 case FP_NEG_NORM: case FP_POS_NORM: return FP_NORMAL;
550 case FP_NEG_DENORM: case FP_POS_DENORM: return FP_SUBNORMAL;
551 case FP_NEG_ZERO: case FP_POS_ZERO: return FP_ZERO;
554 # define c99_fpclassify my_fpclassify
555 #elif defined(HAS_CLASS) && defined(FP_PLUS_INF)
556 switch (Perl_fp_class(x)) {
557 case FP_MINUS_INF: case FP_PLUS_INF: return FP_INFINITE;
558 case FP_SNAN: case FP_QNAN: return FP_NAN;
559 case FP_MINUS_NORM: case FP_PLUS_NORM: return FP_NORMAL;
560 case FP_MINUS_DENORM: case FP_PLUS_DENORM: return FP_SUBNORMAL;
561 case FP_MINUS_ZERO: case FP_PLUS_ZERO: return FP_ZERO;
564 # define c99_fpclassify my_fpclassify
565 #elif defined(HAS_FP_CLASSIFY)
566 return Perl_fp_class(x);
567 # define c99_fpclassify my_fpclassify
569 int fpclass = _fpclass(x);
570 if (Perl_fp_class_inf(x)) return FP_INFINITE;
571 if (Perl_fp_class_nan(x)) return FP_NAN;
572 if (Perl_fp_class_norm(x)) return FP_NORMAL;
573 if (Perl_fp_class_denorm(x)) return FP_SUBNORMAL;
574 if (Perl_fp_class_zero(x)) return FP_ZERO;
576 # define c99_fpclassify my_fpclassify
583 static NV my_hypot(NV x, NV y)
587 return PERL_ABS(x) * Perl_sqrt(1 + t * t);
591 # define c99_hypot my_hypot
595 static IV my_ilogb(NV x)
597 return (IV)(Perl_log(x) * M_LOG2E);
599 # define c99_ilogb my_ilogb
602 /* XXX lgamma -- non-trivial */
605 static NV my_log1p(NV x)
607 if (PERL_ABS(x) > 1e-4)
608 return Perl_log(1.0 + x);
610 /* Probably not enough for long doubles. */
611 return x * (1.0 - x * (-x / 2.0 + x / 3.0)); /* Taylor series */
613 # define c99_log1p my_log1p
617 static NV my_log2(NV x)
619 return Perl_log(x) * M_LOG2E;
621 # define c99_log2 my_log2
628 static int my_fegetround()
630 #ifdef HAS_FEGETROUND
632 #elif defined(FLT_ROUNDS)
634 /* XXX emulate using fpgetround() (HAS_FPGETROUND):
635 * FP_RN to nearest, FP_RM down, FP_RP, up, FP_RZ truncate */
641 static NV my_rint(NV x)
644 switch (my_fegetround()) {
647 return (NV)((IV)(x >= 0.0 ? x + 0.5 : x - 0.5)); /* like round() */
649 return (NV)((IV)(x)); /* like trunc() */
651 return (NV)((IV)(x >= 0.0 ? x : x - 0.5));
653 return (NV)((IV)(x >= 0.0 ? x + 0.5 : x));
656 /* XXX emulate using fpsetround() (HAS_FPGETROUND):
657 * FP_RN to nearest, FP_RM down, FP_RP, up, FP_RZ truncate */
662 /* XXX nearbyint() and rint() are not really identical -- but the difference
663 * is messy: nearbyint is defined NOT to raise FE_INEXACT floating point
664 * exceptions, while rint() is defined to MAYBE raise them. At the moment
665 * Perl is blissfully unaware of such fine detail of floating point. */
666 #ifndef c99_nearbyint
668 # define c99_nearbyrint my_rint
674 static IV lrint(NV x)
676 return (IV)my_rint(x);
678 # define c99_lrint my_lrint
688 # define c99_rint my_rint
693 static NV my_round(NV x)
695 return (NV)((IV)(x >= 0.0 ? x + 0.5 : x - 0.5));
697 # define c99_round my_round
701 # if defined(Perl_ldexpl) && FLT_RADIX == 2
702 static NV my_scalbn(NV x)
704 return Perl_ldexp(x, y);
706 # define c99_scalbn my_scalbn
710 /* XXX sinh (though c89) */
714 static NV my_tgamma(NV x)
716 double l = c99_lgamma(x);
717 return signgam * Perl_exp(l); /* XXX evil global signgam, need lgamma_r */
719 # define c99_tgamma my_tgamma
720 /* XXX tgamma without lgamma -- non-trivial */
724 /* XXX tanh (though c89) */
727 static NV my_trunc(NV x)
729 return (NV)((IV)(x));
731 # define c99_trunc my_trunc
734 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
735 metaconfig for future extension writers. We don't use them in POSIX.
736 (This is really sneaky :-) --AD
738 #if defined(I_TERMIOS)
747 #include <sys/stat.h>
748 #include <sys/types.h>
756 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
757 extern char *tzname[];
760 #if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
761 char *tzname[] = { "" , "" };
765 #if defined(__VMS) && !defined(__POSIX_SOURCE)
767 # include <utsname.h>
770 # define mkfifo(a,b) (not_here("mkfifo"),-1)
772 /* The POSIX notion of ttyname() is better served by getname() under VMS */
773 static char ttnambuf[64];
774 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
777 #if defined (__CYGWIN__)
778 # define tzname _tzname
780 #if defined (WIN32) || defined (NETWARE)
782 # define mkfifo(a,b) not_here("mkfifo")
783 # define ttyname(a) (char*)not_here("ttyname")
784 # define sigset_t long
787 # define mode_t short
790 # define mode_t short
792 # define tzset() not_here("tzset")
794 # ifndef _POSIX_OPEN_MAX
795 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
798 # define sigaction(a,b,c) not_here("sigaction")
799 # define sigpending(a) not_here("sigpending")
800 # define sigprocmask(a,b,c) not_here("sigprocmask")
801 # define sigsuspend(a) not_here("sigsuspend")
802 # define sigemptyset(a) not_here("sigemptyset")
803 # define sigaddset(a,b) not_here("sigaddset")
804 # define sigdelset(a,b) not_here("sigdelset")
805 # define sigfillset(a) not_here("sigfillset")
806 # define sigismember(a,b) not_here("sigismember")
810 # define setuid(a) not_here("setuid")
811 # define setgid(a) not_here("setgid")
813 # define strtold(s1,s2) not_here("strtold")
818 # define mkfifo(a,b) not_here("mkfifo")
819 # else /* !( defined OS2 ) */
821 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
824 # endif /* !HAS_MKFIFO */
829 # include <sys/times.h>
831 # include <sys/utsname.h>
833 # include <sys/wait.h>
837 #endif /* WIN32 || NETWARE */
841 typedef long SysRetLong;
842 typedef sigset_t* POSIX__SigSet;
843 typedef HV* POSIX__SigAction;
845 typedef struct termios* POSIX__Termios;
846 #else /* Define termios types to int, and call not_here for the functions.*/
847 #define POSIX__Termios int
851 #define cfgetispeed(x) not_here("cfgetispeed")
852 #define cfgetospeed(x) not_here("cfgetospeed")
853 #define tcdrain(x) not_here("tcdrain")
854 #define tcflush(x,y) not_here("tcflush")
855 #define tcsendbreak(x,y) not_here("tcsendbreak")
856 #define cfsetispeed(x,y) not_here("cfsetispeed")
857 #define cfsetospeed(x,y) not_here("cfsetospeed")
858 #define ctermid(x) (char *) not_here("ctermid")
859 #define tcflow(x,y) not_here("tcflow")
860 #define tcgetattr(x,y) not_here("tcgetattr")
861 #define tcsetattr(x,y,z) not_here("tcsetattr")
864 /* Possibly needed prototypes */
867 double strtod (const char *, char **);
868 long strtol (const char *, char **, int);
869 unsigned long strtoul (const char *, char **, int);
871 long double strtold (const char *, char **);
878 #define difftime(a,b) not_here("difftime")
881 #ifndef HAS_FPATHCONF
882 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
885 #define mktime(a) not_here("mktime")
888 #define nice(a) not_here("nice")
891 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
894 #define sysconf(n) (SysRetLong) not_here("sysconf")
897 #define readlink(a,b,c) not_here("readlink")
900 #define setpgid(a,b) not_here("setpgid")
903 #define setsid() not_here("setsid")
906 #define strcoll(s1,s2) not_here("strcoll")
909 #define strtod(s1,s2) not_here("strtod")
912 #define strtold(s1,s2) not_here("strtold")
915 #define strtol(s1,s2,b) not_here("strtol")
918 #define strtoul(s1,s2,b) not_here("strtoul")
921 #define strxfrm(s1,s2,n) not_here("strxfrm")
923 #ifndef HAS_TCGETPGRP
924 #define tcgetpgrp(a) not_here("tcgetpgrp")
926 #ifndef HAS_TCSETPGRP
927 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
931 #define times(a) not_here("times")
935 #define uname(a) not_here("uname")
938 #define waitpid(a,b,c) not_here("waitpid")
943 #define mblen(a,b) not_here("mblen")
947 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
950 #define mbtowc(pwc, s, n) not_here("mbtowc")
953 #define wcstombs(s, pwcs, n) not_here("wcstombs")
956 #define wctomb(s, wchar) not_here("wcstombs")
958 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
959 /* If we don't have these functions, then we wouldn't have gotten a typedef
960 for wchar_t, the wide character type. Defining wchar_t allows the
961 functions referencing it to compile. Its actual type is then meaningless,
962 since without the above functions, all sections using it end up calling
963 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
969 #ifndef HAS_LOCALECONV
970 # define localeconv() not_here("localeconv")
972 struct lconv_offset {
977 const struct lconv_offset lconv_strings[] = {
978 #ifdef USE_LOCALE_NUMERIC
979 {"decimal_point", STRUCT_OFFSET(struct lconv, decimal_point)},
980 {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)},
981 # ifndef NO_LOCALECONV_GROUPING
982 {"grouping", STRUCT_OFFSET(struct lconv, grouping)},
985 #ifdef USE_LOCALE_MONETARY
986 {"int_curr_symbol", STRUCT_OFFSET(struct lconv, int_curr_symbol)},
987 {"currency_symbol", STRUCT_OFFSET(struct lconv, currency_symbol)},
988 {"mon_decimal_point", STRUCT_OFFSET(struct lconv, mon_decimal_point)},
989 # ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
990 {"mon_thousands_sep", STRUCT_OFFSET(struct lconv, mon_thousands_sep)},
992 # ifndef NO_LOCALECONV_MON_GROUPING
993 {"mon_grouping", STRUCT_OFFSET(struct lconv, mon_grouping)},
995 {"positive_sign", STRUCT_OFFSET(struct lconv, positive_sign)},
996 {"negative_sign", STRUCT_OFFSET(struct lconv, negative_sign)},
1001 #ifdef USE_LOCALE_NUMERIC
1003 /* The Linux man pages say these are the field names for the structure
1004 * components that are LC_NUMERIC; the rest being LC_MONETARY */
1005 # define isLC_NUMERIC_STRING(name) (strcmp(name, "decimal_point") \
1006 || strcmp(name, "thousands_sep") \
1008 /* There should be no harm done \
1009 * checking for this, even if \
1010 * NO_LOCALECONV_GROUPING */ \
1011 || strcmp(name, "grouping"))
1013 # define isLC_NUMERIC_STRING(name) (0)
1016 const struct lconv_offset lconv_integers[] = {
1017 #ifdef USE_LOCALE_MONETARY
1018 {"int_frac_digits", STRUCT_OFFSET(struct lconv, int_frac_digits)},
1019 {"frac_digits", STRUCT_OFFSET(struct lconv, frac_digits)},
1020 {"p_cs_precedes", STRUCT_OFFSET(struct lconv, p_cs_precedes)},
1021 {"p_sep_by_space", STRUCT_OFFSET(struct lconv, p_sep_by_space)},
1022 {"n_cs_precedes", STRUCT_OFFSET(struct lconv, n_cs_precedes)},
1023 {"n_sep_by_space", STRUCT_OFFSET(struct lconv, n_sep_by_space)},
1024 {"p_sign_posn", STRUCT_OFFSET(struct lconv, p_sign_posn)},
1025 {"n_sign_posn", STRUCT_OFFSET(struct lconv, n_sign_posn)},
1030 #endif /* HAS_LOCALECONV */
1032 #ifdef HAS_LONG_DOUBLE
1033 # if LONG_DOUBLESIZE > NVSIZE
1034 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
1038 #ifndef HAS_LONG_DOUBLE
1050 /* Background: in most systems the low byte of the wait status
1051 * is the signal (the lowest 7 bits) and the coredump flag is
1052 * the eight bit, and the second lowest byte is the exit status.
1053 * BeOS bucks the trend and has the bytes in different order.
1054 * See beos/beos.c for how the reality is bent even in BeOS
1055 * to follow the traditional. However, to make the POSIX
1056 * wait W*() macros to work in BeOS, we need to unbend the
1057 * reality back in place. --jhi */
1058 /* In actual fact the code below is to blame here. Perl has an internal
1059 * representation of the exit status ($?), which it re-composes from the
1060 * OS's representation using the W*() POSIX macros. The code below
1061 * incorrectly uses the W*() macros on the internal representation,
1062 * which fails for OSs that have a different representation (namely BeOS
1063 * and Haiku). WMUNGE() is a hack that converts the internal
1064 * representation into the OS specific one, so that the W*() macros work
1065 * as expected. The better solution would be not to use the W*() macros
1066 * in the first place, though. -- Ingo Weinhold
1068 #if defined(__HAIKU__)
1069 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
1071 # define WMUNGE(x) (x)
1075 not_here(const char *s)
1077 croak("POSIX::%s not implemented on this architecture", s);
1081 #include "const-c.inc"
1084 restore_sigmask(pTHX_ SV *osset_sv)
1086 /* Fortunately, restoring the signal mask can't fail, because
1087 * there's nothing we can do about it if it does -- we're not
1088 * supposed to return -1 from sigaction unless the disposition
1091 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
1092 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
1096 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
1097 SV *const t = newSVrv(rv, packname);
1098 void *const p = sv_grow(t, size + 1);
1108 * (1) The CRT maintains its own copy of the environment, separate from
1109 * the Win32API copy.
1111 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
1112 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
1115 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
1116 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
1119 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
1120 * calls CRT tzset(), but only the first time it is called, and in turn
1121 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
1122 * local copy of the environment and hence gets the original setting as
1123 * perl never updates the CRT copy when assigning to $ENV{TZ}.
1125 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
1126 * putenv() to update the CRT copy of the environment (if it is different)
1127 * whenever we're about to call tzset().
1129 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
1132 * (a) Each interpreter has its own copy of the environment inside the
1133 * perlhost structure. That allows applications that host multiple
1134 * independent Perl interpreters to isolate environment changes from
1135 * each other. (This is similar to how the perlhost mechanism keeps a
1136 * separate working directory for each Perl interpreter, so that calling
1137 * chdir() will not affect other interpreters.)
1139 * (b) Only the first Perl interpreter instantiated within a process will
1140 * "write through" environment changes to the process environment.
1142 * (c) Even the primary Perl interpreter won't update the CRT copy of the
1143 * the environment, only the Win32API copy (it calls win32_putenv()).
1145 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
1146 * sense to only update the process environment when inside the main
1147 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
1148 * from here so we'll just have to check PL_curinterp instead.
1150 * Therefore, we can simply #undef getenv() and putenv() so that those names
1151 * always refer to the CRT functions, and explicitly call win32_getenv() to
1152 * access perl's %ENV.
1154 * We also #undef malloc() and free() to be sure we are using the CRT
1155 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
1156 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
1157 * when the Perl interpreter is being destroyed so we'd end up with a pointer
1158 * into deallocated memory in environ[] if a program embedding a Perl
1159 * interpreter continues to operate even after the main Perl interpreter has
1162 * Note that we don't free() the malloc()ed memory unless and until we call
1163 * malloc() again ourselves because the CRT putenv() function simply puts its
1164 * pointer argument into the environ[] array (it doesn't make a copy of it)
1165 * so this memory must otherwise be leaked.
1174 fix_win32_tzenv(void)
1176 static char* oldenv = NULL;
1178 const char* perl_tz_env = win32_getenv("TZ");
1179 const char* crt_tz_env = getenv("TZ");
1180 if (perl_tz_env == NULL)
1182 if (crt_tz_env == NULL)
1184 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
1185 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
1186 if (newenv != NULL) {
1187 sprintf(newenv, "TZ=%s", perl_tz_env);
1199 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
1200 * This code is duplicated in the Time-Piece module, so any changes made here
1201 * should be made there too.
1207 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
1208 if (PL_curinterp == aTHX)
1215 typedef int (*isfunc_t)(int);
1216 typedef void (*any_dptr_t)(void *);
1218 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
1220 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
1221 static XSPROTO(is_common)
1226 croak_xs_usage(cv, "charstring");
1231 /*int RETVAL = 0; YYY means uncomment this to return false on an
1232 * empty string input */
1234 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
1235 unsigned char *e = s + len;
1236 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
1238 if (ckWARN_d(WARN_DEPRECATED)) {
1240 /* Warn exactly once for each lexical place this function is
1241 * called. See thread at
1242 * http://markmail.org/thread/jhqcag5njmx7jpyu */
1244 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
1245 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
1246 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
1247 "Calling POSIX::%"HEKf"() is deprecated",
1248 HEKfARG(GvNAME_HEK(CvGV(cv))));
1249 hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
1253 /*if (e > s) { YYY */
1254 for (RETVAL = 1; RETVAL && s < e; s++)
1264 MODULE = POSIX PACKAGE = POSIX
1269 const char *file = __FILE__;
1272 /* silence compiler warning about not_here() defined but not used */
1273 if (0) not_here("");
1275 /* Ensure we get the function, not a macro implementation. Like the C89
1276 standard says we can... */
1278 cv = newXS("POSIX::isalnum", is_common, file);
1279 XSANY.any_dptr = (any_dptr_t) &isalnum;
1281 cv = newXS("POSIX::isalpha", is_common, file);
1282 XSANY.any_dptr = (any_dptr_t) &isalpha;
1284 cv = newXS("POSIX::iscntrl", is_common, file);
1285 XSANY.any_dptr = (any_dptr_t) &iscntrl;
1287 cv = newXS("POSIX::isdigit", is_common, file);
1288 XSANY.any_dptr = (any_dptr_t) &isdigit;
1290 cv = newXS("POSIX::isgraph", is_common, file);
1291 XSANY.any_dptr = (any_dptr_t) &isgraph;
1293 cv = newXS("POSIX::islower", is_common, file);
1294 XSANY.any_dptr = (any_dptr_t) &islower;
1296 cv = newXS("POSIX::isprint", is_common, file);
1297 XSANY.any_dptr = (any_dptr_t) &isprint;
1299 cv = newXS("POSIX::ispunct", is_common, file);
1300 XSANY.any_dptr = (any_dptr_t) &ispunct;
1302 cv = newXS("POSIX::isspace", is_common, file);
1303 XSANY.any_dptr = (any_dptr_t) &isspace;
1305 cv = newXS("POSIX::isupper", is_common, file);
1306 XSANY.any_dptr = (any_dptr_t) &isupper;
1308 cv = newXS("POSIX::isxdigit", is_common, file);
1309 XSANY.any_dptr = (any_dptr_t) &isxdigit;
1312 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
1315 new(packname = "POSIX::SigSet", ...)
1316 const char * packname
1321 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1325 for (i = 1; i < items; i++)
1326 sigaddset(s, SvIV(ST(i)));
1332 POSIX::SigSet sigset
1337 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
1343 POSIX::SigSet sigset
1347 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
1352 sigismember(sigset, sig)
1353 POSIX::SigSet sigset
1356 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
1359 new(packname = "POSIX::Termios", ...)
1360 const char * packname
1364 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1365 sizeof(struct termios), packname);
1366 /* The previous implementation stored a pointer to an uninitialised
1367 struct termios. Seems safer to initialise it, particularly as
1368 this implementation exposes the struct to prying from perl-space.
1370 memset(p, 0, 1 + sizeof(struct termios));
1373 not_here("termios");
1378 getattr(termios_ref, fd = 0)
1379 POSIX::Termios termios_ref
1382 RETVAL = tcgetattr(fd, termios_ref);
1386 # If we define TCSANOW here then both a found and not found constant sub
1387 # are created causing a Constant subroutine TCSANOW redefined warning
1389 # define DEF_SETATTR_ACTION 0
1391 # define DEF_SETATTR_ACTION TCSANOW
1394 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
1395 POSIX::Termios termios_ref
1397 int optional_actions
1399 /* The second argument to the call is mandatory, but we'd like to give
1400 it a useful default. 0 isn't valid on all operating systems - on
1401 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
1402 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
1403 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
1408 getispeed(termios_ref)
1409 POSIX::Termios termios_ref
1413 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
1418 getiflag(termios_ref)
1419 POSIX::Termios termios_ref
1425 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1428 RETVAL = termios_ref->c_iflag;
1431 RETVAL = termios_ref->c_oflag;
1434 RETVAL = termios_ref->c_cflag;
1437 RETVAL = termios_ref->c_lflag;
1440 RETVAL = 0; /* silence compiler warning */
1443 not_here(GvNAME(CvGV(cv)));
1450 getcc(termios_ref, ccix)
1451 POSIX::Termios termios_ref
1454 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1456 croak("Bad getcc subscript");
1457 RETVAL = termios_ref->c_cc[ccix];
1466 setispeed(termios_ref, speed)
1467 POSIX::Termios termios_ref
1473 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
1478 setiflag(termios_ref, flag)
1479 POSIX::Termios termios_ref
1486 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1489 termios_ref->c_iflag = flag;
1492 termios_ref->c_oflag = flag;
1495 termios_ref->c_cflag = flag;
1498 termios_ref->c_lflag = flag;
1502 not_here(GvNAME(CvGV(cv)));
1506 setcc(termios_ref, ccix, cc)
1507 POSIX::Termios termios_ref
1511 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1513 croak("Bad setcc subscript");
1514 termios_ref->c_cc[ccix] = cc;
1520 MODULE = POSIX PACKAGE = POSIX
1522 INCLUDE: const-xs.inc
1528 POSIX::WIFEXITED = 1
1529 POSIX::WIFSIGNALED = 2
1530 POSIX::WIFSTOPPED = 3
1534 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
1535 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
1536 RETVAL = 0; /* Silence compilers that notice this, but don't realise
1537 that not_here() can't return. */
1542 RETVAL = WEXITSTATUS(WMUNGE(status));
1544 not_here("WEXITSTATUS");
1549 RETVAL = WIFEXITED(WMUNGE(status));
1551 not_here("WIFEXITED");
1556 RETVAL = WIFSIGNALED(WMUNGE(status));
1558 not_here("WIFSIGNALED");
1563 RETVAL = WIFSTOPPED(WMUNGE(status));
1565 not_here("WIFSTOPPED");
1570 RETVAL = WSTOPSIG(WMUNGE(status));
1572 not_here("WSTOPSIG");
1577 RETVAL = WTERMSIG(WMUNGE(status));
1579 not_here("WTERMSIG");
1583 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
1589 open(filename, flags = O_RDONLY, mode = 0666)
1594 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1595 TAINT_PROPER("open");
1596 RETVAL = open(filename, flags, mode);
1604 #ifndef HAS_LOCALECONV
1605 localeconv(); /* A stub to call not_here(). */
1607 struct lconv *lcbuf;
1609 /* localeconv() deals with both LC_NUMERIC and LC_MONETARY, but
1610 * LC_MONETARY is already in the correct locale */
1611 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
1614 sv_2mortal((SV*)RETVAL);
1615 if ((lcbuf = localeconv())) {
1616 const struct lconv_offset *strings = lconv_strings;
1617 const struct lconv_offset *integers = lconv_integers;
1618 const char *ptr = (const char *) lcbuf;
1621 /* This string may be controlled by either LC_NUMERIC, or
1624 #if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY)
1625 = _is_cur_LC_category_utf8((isLC_NUMERIC_STRING(strings->name))
1628 #elif defined(USE_LOCALE_NUMERIC)
1629 = _is_cur_LC_category_utf8(LC_NUMERIC);
1630 #elif defined(USE_LOCALE_MONETARY)
1631 = _is_cur_LC_category_utf8(LC_MONETARY);
1636 const char *value = *((const char **)(ptr + strings->offset));
1638 if (value && *value) {
1639 (void) hv_store(RETVAL,
1641 strlen(strings->name),
1642 newSVpvn_utf8(value,
1645 /* We mark it as UTF-8 if a utf8 locale
1646 * and is valid, non-ascii UTF-8 */
1648 && ! is_ascii_string((U8 *) value, 0)
1649 && is_utf8_string((U8 *) value, 0)),
1652 } while ((++strings)->name);
1655 const char value = *((const char *)(ptr + integers->offset));
1657 if (value != CHAR_MAX)
1658 (void) hv_store(RETVAL, integers->name,
1659 strlen(integers->name), newSViv(value), 0);
1660 } while ((++integers)->name);
1662 RESTORE_NUMERIC_STANDARD();
1663 #endif /* HAS_LOCALECONV */
1668 setlocale(category, locale = 0)
1674 #ifdef USE_LOCALE_NUMERIC
1675 /* A 0 (or NULL) locale means only query what the current one is. We
1676 * have the LC_NUMERIC name saved, because we are normally switched
1677 * into the C locale for it. Switch back so an LC_ALL query will yield
1678 * the correct results; all other categories don't require special
1681 if (category == LC_NUMERIC) {
1682 XSRETURN_PV(PL_numeric_name);
1685 else if (category == LC_ALL) {
1686 SET_NUMERIC_LOCAL();
1691 #ifdef WIN32 /* Use wrapper on Windows */
1692 retval = Perl_my_setlocale(aTHX_ category, locale);
1694 retval = setlocale(category, locale);
1697 /* Should never happen that a query would return an error, but be
1698 * sure and reset to C locale */
1700 SET_NUMERIC_STANDARD();
1705 /* Save retval since subsequent setlocale() calls may overwrite it. */
1706 retval = savepv(retval);
1708 /* For locale == 0, we may have switched to NUMERIC_LOCAL. Switch back
1711 SET_NUMERIC_STANDARD();
1712 XSRETURN_PV(retval);
1716 #ifdef USE_LOCALE_CTYPE
1717 if (category == LC_CTYPE
1719 || category == LC_ALL
1725 if (category == LC_ALL)
1726 newctype = setlocale(LC_CTYPE, NULL);
1730 new_ctype(newctype);
1732 #endif /* USE_LOCALE_CTYPE */
1733 #ifdef USE_LOCALE_COLLATE
1734 if (category == LC_COLLATE
1736 || category == LC_ALL
1742 if (category == LC_ALL)
1743 newcoll = setlocale(LC_COLLATE, NULL);
1747 new_collate(newcoll);
1749 #endif /* USE_LOCALE_COLLATE */
1750 #ifdef USE_LOCALE_NUMERIC
1751 if (category == LC_NUMERIC
1753 || category == LC_ALL
1759 if (category == LC_ALL)
1760 newnum = setlocale(LC_NUMERIC, NULL);
1764 new_numeric(newnum);
1766 #endif /* USE_LOCALE_NUMERIC */
1811 RETVAL = acos(x); /* C89 math */
1815 RETVAL = c99_acosh(x);
1821 RETVAL = asin(x); /* C89 math */
1825 RETVAL = c99_asinh(x);
1831 RETVAL = atan(x); /* C89 math */
1835 RETVAL = c99_atanh(x);
1842 RETVAL = c99_cbrt(x);
1848 RETVAL = ceil(x); /* C89 math */
1851 RETVAL = cosh(x); /* C89 math */
1855 RETVAL = c99_erf(x);
1869 RETVAL = c99_exp2(x);
1876 RETVAL = c99_expm1(x);
1882 RETVAL = floor(x); /* C89 math */
1886 RETVAL = bessel_j0(x);
1893 RETVAL = bessel_j1(x);
1901 RETVAL = c99_lgamma(x);
1907 RETVAL = log10(x); /* C89 math */
1911 RETVAL = c99_log1p(x);
1918 RETVAL = c99_log2(x);
1925 RETVAL = c99_logb(x);
1931 #ifdef c99_nearbyint
1932 RETVAL = c99_nearbyint(x);
1934 not_here("nearbyint");
1939 RETVAL = c99_rint(x);
1946 RETVAL = c99_round(x);
1952 RETVAL = sinh(x); /* C89 math */
1955 RETVAL = tan(x); /* C89 math */
1958 RETVAL = tanh(x); /* C89 math */
1963 RETVAL = c99_tgamma(x);
1970 RETVAL = c99_trunc(x);
1977 RETVAL = bessel_y0(x);
1985 RETVAL = bessel_y1(x);
1996 #ifdef HAS_FEGETROUND
1997 RETVAL = my_fegetround();
2000 not_here("fegetround");
2009 #ifdef HAS_FEGETROUND /* canary for fesetround */
2010 RETVAL = fesetround(x);
2013 not_here("fesetround");
2033 #ifdef c99_fpclassify
2034 RETVAL = c99_fpclassify(x);
2036 not_here("fpclassify");
2041 RETVAL = c99_ilogb(x);
2047 RETVAL = Perl_isfinite(x);
2050 RETVAL = Perl_isinf(x);
2053 RETVAL = Perl_isnan(x);
2057 RETVAL = c99_isnormal(x);
2059 not_here("isnormal");
2064 RETVAL = c99_lrint(x);
2072 RETVAL = Perl_signbit(x);
2103 RETVAL = c99_copysign(x, y);
2105 not_here("copysign");
2110 RETVAL = c99_fdim(x, y);
2117 RETVAL = c99_fmax(x, y);
2124 RETVAL = c99_fmin(x, y);
2130 RETVAL = fmod(x, y); /* C89 math */
2134 RETVAL = c99_hypot(x, y);
2140 #ifdef c99_isgreater
2141 RETVAL = c99_isgreater(x, y);
2143 not_here("isgreater");
2147 #ifdef c99_isgreaterequal
2148 RETVAL = c99_isgreaterequal(x, y);
2150 not_here("isgreaterequal");
2155 RETVAL = c99_isless(x, y);
2161 #ifdef c99_islessequal
2162 RETVAL = c99_islessequal(x, y);
2164 not_here("islessequal");
2168 #ifdef c99_islessgreater
2169 RETVAL = c99_islessgreater(x, y);
2171 not_here("islessgreater");
2175 #ifdef c99_isunordered
2176 RETVAL = c99_isunordered(x, y);
2178 not_here("isunordered");
2182 #ifdef c99_nextafter
2183 RETVAL = c99_nextafter(x, y);
2185 not_here("nextafter");
2189 #ifdef c99_nexttoward
2190 RETVAL = c99_nexttoward(x, y);
2192 not_here("nexttoward");
2197 #ifdef c99_remainder
2198 RETVAL = c99_remainder(x, y);
2200 not_here("remainder");
2212 /* (We already know stack is long enough.) */
2213 PUSHs(sv_2mortal(newSVnv(Perl_frexp(x,&expvar)))); /* C89 math */
2214 PUSHs(sv_2mortal(newSViv(expvar)));
2226 /* (We already know stack is long enough.) */
2227 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar)))); /* C89 math */
2228 PUSHs(sv_2mortal(newSVnv(intvar)));
2237 PUSHs(sv_2mortal(newSVnv(c99_remquo(x,y,&intvar))));
2238 PUSHs(sv_2mortal(newSVnv(intvar)));
2249 RETVAL = c99_scalbn(x, y);
2264 RETVAL = c99_fma(x, y, z);
2277 RETVAL = c99_nan(s);
2296 RETVAL = bessel_jn(x, y);
2304 RETVAL = bessel_yn(x, y);
2314 sigaction(sig, optaction, oldaction = 0)
2317 POSIX::SigAction oldaction
2319 #if defined(WIN32) || defined(NETWARE)
2320 RETVAL = not_here("sigaction");
2322 # This code is really grody because we're trying to make the signal
2323 # interface look beautiful, which is hard.
2327 POSIX__SigAction action;
2328 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
2329 struct sigaction act;
2330 struct sigaction oact;
2334 POSIX__SigSet sigset;
2339 croak("Negative signals are not allowed");
2342 if (sig == 0 && SvPOK(ST(0))) {
2343 const char *s = SvPVX_const(ST(0));
2344 int i = whichsig(s);
2346 if (i < 0 && memEQ(s, "SIG", 3))
2347 i = whichsig(s + 3);
2349 if (ckWARN(WARN_SIGNAL))
2350 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2351 "No such signal: SIG%s", s);
2358 if (sig > NSIG) { /* NSIG - 1 is still okay. */
2359 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2360 "No such signal: %d", sig);
2364 sigsvp = hv_fetch(GvHVn(siggv),
2366 strlen(PL_sig_name[sig]),
2369 /* Check optaction and set action */
2370 if(SvTRUE(optaction)) {
2371 if(sv_isa(optaction, "POSIX::SigAction"))
2372 action = (HV*)SvRV(optaction);
2374 croak("action is not of type POSIX::SigAction");
2380 /* sigaction() is supposed to look atomic. In particular, any
2381 * signal handler invoked during a sigaction() call should
2382 * see either the old or the new disposition, and not something
2383 * in between. We use sigprocmask() to make it so.
2386 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
2390 /* Restore signal mask no matter how we exit this block. */
2391 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
2392 SAVEFREESV( osset_sv );
2393 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
2395 RETVAL=-1; /* In case both oldaction and action are 0. */
2397 /* Remember old disposition if desired. */
2399 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
2401 croak("Can't supply an oldaction without a HANDLER");
2402 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
2403 sv_setsv(*svp, *sigsvp);
2406 sv_setpvs(*svp, "DEFAULT");
2408 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
2413 /* Get back the mask. */
2414 svp = hv_fetchs(oldaction, "MASK", TRUE);
2415 if (sv_isa(*svp, "POSIX::SigSet")) {
2416 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2419 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
2423 *sigset = oact.sa_mask;
2425 /* Get back the flags. */
2426 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
2427 sv_setiv(*svp, oact.sa_flags);
2429 /* Get back whether the old handler used safe signals. */
2430 svp = hv_fetchs(oldaction, "SAFE", TRUE);
2432 /* compare incompatible pointers by casting to integer */
2433 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
2437 /* Safe signals use "csighandler", which vectors through the
2438 PL_sighandlerp pointer when it's safe to do so.
2439 (BTW, "csighandler" is very different from "sighandler".) */
2440 svp = hv_fetchs(action, "SAFE", FALSE);
2444 (*svp && SvTRUE(*svp))
2445 ? PL_csighandlerp : PL_sighandlerp
2448 /* Vector new Perl handler through %SIG.
2449 (The core signal handlers read %SIG to dispatch.) */
2450 svp = hv_fetchs(action, "HANDLER", FALSE);
2452 croak("Can't supply an action without a HANDLER");
2453 sv_setsv(*sigsvp, *svp);
2455 /* This call actually calls sigaction() with almost the
2456 right settings, including appropriate interpretation
2457 of DEFAULT and IGNORE. However, why are we doing
2458 this when we're about to do it again just below? XXX */
2459 SvSETMAGIC(*sigsvp);
2461 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
2463 const char *s=SvPVX_const(*svp);
2464 if(strEQ(s,"IGNORE")) {
2465 act.sa_handler = SIG_IGN;
2467 else if(strEQ(s,"DEFAULT")) {
2468 act.sa_handler = SIG_DFL;
2472 /* Set up any desired mask. */
2473 svp = hv_fetchs(action, "MASK", FALSE);
2474 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
2475 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2476 act.sa_mask = *sigset;
2479 sigemptyset(& act.sa_mask);
2481 /* Set up any desired flags. */
2482 svp = hv_fetchs(action, "FLAGS", FALSE);
2483 act.sa_flags = svp ? SvIV(*svp) : 0;
2485 /* Don't worry about cleaning up *sigsvp if this fails,
2486 * because that means we tried to disposition a
2487 * nonblockable signal, in which case *sigsvp is
2488 * essentially meaningless anyway.
2490 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
2505 POSIX::SigSet sigset
2509 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
2516 sigprocmask(how, sigset, oldsigset = 0)
2518 POSIX::SigSet sigset = NO_INIT
2519 POSIX::SigSet oldsigset = NO_INIT
2521 if (! SvOK(ST(1))) {
2523 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
2524 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
2526 croak("sigset is not of type POSIX::SigSet");
2529 if (items < 3 || ! SvOK(ST(2))) {
2531 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
2532 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
2534 croak("oldsigset is not of type POSIX::SigSet");
2547 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
2548 the well known documented POSIX behaviour for a POSIX API.
2549 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
2550 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
2552 RETVAL = dup2(fd1, fd2);
2558 lseek(fd, offset, whence)
2563 Off_t pos = PerlLIO_lseek(fd, offset, whence);
2564 RETVAL = sizeof(Off_t) > sizeof(IV)
2565 ? newSVnv((NV)pos) : newSViv((IV)pos);
2574 if ((incr = nice(incr)) != -1 || errno == 0) {
2576 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
2578 XPUSHs(sv_2mortal(newSViv(incr)));
2585 if (pipe(fds) != -1) {
2587 PUSHs(sv_2mortal(newSViv(fds[0])));
2588 PUSHs(sv_2mortal(newSViv(fds[1])));
2592 read(fd, buffer, nbytes)
2594 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
2598 char * buffer = sv_grow( sv_buffer, nbytes+1 );
2601 SvCUR_set(sv_buffer, RETVAL);
2602 SvPOK_only(sv_buffer);
2603 *SvEND(sv_buffer) = '\0';
2604 SvTAINTED_on(sv_buffer);
2620 tcsetpgrp(fd, pgrp_id)
2629 if (uname(&buf) >= 0) {
2631 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
2632 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
2633 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
2634 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
2635 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
2638 uname((char *) 0); /* A stub to call not_here(). */
2642 write(fd, buffer, nbytes)
2653 RETVAL = newSVpvs("");
2654 SvGROW(RETVAL, L_tmpnam);
2655 /* Yes, we know tmpnam() is bad. So bad that some compilers
2656 * and linkers warn against using it. But it is here for
2657 * completeness. POSIX.pod warns against using it.
2659 * Then again, maybe this should be removed at some point.
2660 * No point in enabling dangerous interfaces. */
2661 len = strlen(tmpnam(SvPV(RETVAL, i)));
2662 SvCUR_set(RETVAL, len);
2675 mbstowcs(s, pwcs, n)
2687 wcstombs(s, pwcs, n)
2709 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
2710 num = strtod(str, &unparsed);
2711 PUSHs(sv_2mortal(newSVnv(num)));
2712 if (GIMME == G_ARRAY) {
2715 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
2717 PUSHs(&PL_sv_undef);
2719 RESTORE_NUMERIC_STANDARD();
2730 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
2731 num = strtold(str, &unparsed);
2732 PUSHs(sv_2mortal(newSVnv(num)));
2733 if (GIMME == G_ARRAY) {
2736 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
2738 PUSHs(&PL_sv_undef);
2740 RESTORE_NUMERIC_STANDARD();
2745 strtol(str, base = 0)
2752 num = strtol(str, &unparsed, base);
2753 #if IVSIZE <= LONGSIZE
2754 if (num < IV_MIN || num > IV_MAX)
2755 PUSHs(sv_2mortal(newSVnv((double)num)));
2758 PUSHs(sv_2mortal(newSViv((IV)num)));
2759 if (GIMME == G_ARRAY) {
2762 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
2764 PUSHs(&PL_sv_undef);
2768 strtoul(str, base = 0)
2775 num = strtoul(str, &unparsed, base);
2776 #if IVSIZE <= LONGSIZE
2778 PUSHs(sv_2mortal(newSVnv((double)num)));
2781 PUSHs(sv_2mortal(newSViv((IV)num)));
2782 if (GIMME == G_ARRAY) {
2785 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
2787 PUSHs(&PL_sv_undef);
2798 char *p = SvPV(src,srclen);
2800 buflen = srclen * 4 + 1;
2801 ST(0) = sv_2mortal(newSV(buflen));
2802 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)buflen);
2803 if (dstlen >= buflen) {
2805 SvGROW(ST(0), dstlen);
2806 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
2809 SvCUR_set(ST(0), dstlen);
2814 mkfifo(filename, mode)
2821 RETVAL = access(filename, mode);
2823 TAINT_PROPER("mkfifo");
2824 RETVAL = mkfifo(filename, mode);
2836 RETVAL = ix == 1 ? close(fd)
2837 : (ix < 1 ? tcdrain(fd) : dup(fd));
2850 RETVAL = ix == 1 ? tcflush(fd, action)
2851 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
2856 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
2872 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
2875 mytm.tm_hour = hour;
2876 mytm.tm_mday = mday;
2878 mytm.tm_year = year;
2879 mytm.tm_wday = wday;
2880 mytm.tm_yday = yday;
2881 mytm.tm_isdst = isdst;
2883 const time_t result = mktime(&mytm);
2884 if (result == (time_t)-1)
2886 else if (result == 0)
2887 sv_setpvn(TARG, "0 but true", 10);
2889 sv_setiv(TARG, (IV)result);
2891 sv_setpv(TARG, asctime(&mytm));
2909 realtime = times( &tms );
2911 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
2912 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
2913 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
2914 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
2915 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
2918 difftime(time1, time2)
2922 #XXX: if $xsubpp::WantOptimize is always the default
2923 # sv_setpv(TARG, ...) could be used rather than
2924 # ST(0) = sv_2mortal(newSVpv(...))
2926 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
2942 /* allowing user-supplied (rather than literal) formats
2943 * is normally frowned upon as a potential security risk;
2944 * but this is part of the API so we have to allow it */
2945 GCC_DIAG_IGNORE(-Wformat-nonliteral);
2946 buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
2948 sv = sv_newmortal();
2950 STRLEN len = strlen(buf);
2951 sv_usepvn_flags(sv, buf, len, SV_HAS_TRAILING_NUL);
2953 || (! is_ascii_string((U8*) buf, len)
2954 && is_utf8_string((U8*) buf, len)
2955 #ifdef USE_LOCALE_TIME
2956 && _is_cur_LC_category_utf8(LC_TIME)
2962 else { /* We can't distinguish between errors and just an empty
2963 * return; in all cases just return an empty string */
2964 SvUPGRADE(sv, SVt_PV);
2965 SvPV_set(sv, (char *) "");
2968 SvLEN_set(sv, 0); /* Won't attempt to free the string when sv
2983 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
2984 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
2990 #ifdef HAS_CTERMID_R
2991 s = (char *) safemalloc((size_t) L_ctermid);
2993 RETVAL = ctermid(s);
2997 #ifdef HAS_CTERMID_R
3006 RETVAL = cuserid(s);
3009 not_here("cuserid");
3020 pathconf(filename, name)
3031 unsigned int seconds
3033 RETVAL = PerlProc_sleep(seconds);
3059 XSprePUSH; PUSHTARG;
3063 lchown(uid, gid, path)
3069 /* yes, the order of arguments is different,
3070 * but consistent with CORE::chown() */
3071 RETVAL = lchown(path, uid, gid);
3073 RETVAL = not_here("lchown");