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>
60 #if defined(USE_QUADMATH) && defined(I_QUADMATH)
77 # define M_LOG2E M_LOG2Eq
78 # define M_LOG10E M_LOG10Eq
80 # define M_LN10 M_LN10q
82 # define M_PI_2 M_PI_2q
83 # define M_PI_4 M_PI_4q
84 # define M_1_PI M_1_PIq
85 # define M_2_PI M_2_PIq
86 # define M_2_SQRTPI M_2_SQRTPIq
87 # define M_SQRT2 M_SQRT2q
88 # define M_SQRT1_2 M_SQRT1_2q
93 # define M_E 2.71828182845904523536028747135266250
96 # define M_LOG2E 1.44269504088896340735992468100189214
99 # define M_LOG10E 0.434294481903251827651128918916605082
102 # define M_LN2 0.693147180559945309417232121458176568
105 # define M_LN10 2.30258509299404568401799145468436421
108 # define M_PI 3.14159265358979323846264338327950288
111 # define M_PI_2 1.57079632679489661923132169163975144
114 # define M_PI_4 0.785398163397448309615660845819875721
117 # define M_1_PI 0.318309886183790671537767526745028724
120 # define M_2_PI 0.636619772367581343075535053490057448
123 # define M_2_SQRTPI 1.12837916709551257389615890312154517
126 # define M_SQRT2 1.41421356237309504880168872420969808
129 # define M_SQRT1_2 0.707106781186547524400844362104849039
134 #if !defined(INFINITY) && defined(NV_INF)
135 # define INFINITY NV_INF
138 #if !defined(NAN) && defined(NV_NAN)
142 #if !defined(Inf) && defined(NV_INF)
146 #if !defined(NaN) && defined(NV_NAN)
150 /* We will have an emulation. */
152 # define FP_INFINITE 0
155 # define FP_SUBNORMAL 3
159 /* We will have an emulation. */
161 # define FE_TOWARDZERO 0
162 # define FE_TONEAREST 1
164 # define FE_DOWNWARD 3
169 acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp ldexp
170 log log10 modf pow sin sinh sqrt tan tanh
172 * Implemented in core:
174 atan2 cos exp log pow sin sqrt
178 acosh asinh atanh cbrt copysign erf erfc exp2 expm1 fdim fma fmax
179 fmin fpclassify hypot ilogb isfinite isgreater isgreaterequal isinf
180 isless islessequal islessgreater isnan isnormal isunordered lgamma
181 log1p log2 logb lrint lround nan nearbyint nextafter nexttoward remainder
182 remquo rint round scalbn signbit tgamma trunc
185 http://pubs.opengroup.org/onlinepubs/009695399/basedefs/math.h.html
187 * Berkeley/SVID extensions:
191 * Configure already (5.21.5) scans for:
193 copysign*l* fpclassify isfinite isinf isnan isnan*l* ilogb*l* signbit scalbn*l*
195 * For floating-point round mode (which matters for e.g. lrint and rint)
197 fegetround fesetround
201 /* XXX Constant FP_FAST_FMA (if true, FMA is faster) */
203 /* XXX Add ldiv(), lldiv()? It's C99, but from stdlib.h, not math.h */
205 /* XXX Beware old gamma() -- one cannot know whether that is the
206 * gamma or the log of gamma, that's why the new tgamma and lgamma.
207 * Though also remember lgamma_r. */
209 /* Certain AIX releases have the C99 math, but not in long double.
210 * The <math.h> has them, e.g. __expl128, but no library has them!
212 * Also see the comments in hints/aix.sh about long doubles. */
214 #if defined(USE_QUADMATH) && defined(I_QUADMATH)
215 # define c99_acosh acoshq
216 # define c99_asinh asinhq
217 # define c99_atanh atanhq
218 # define c99_cbrt cbrtq
219 # define c99_copysign copysignq
220 # define c99_erf erfq
221 # define c99_erfc erfcq
223 # define c99_expm1 expm1q
224 # define c99_fdim fdimq
225 # define c99_fma fmaq
226 # define c99_fmax fmaxq
227 # define c99_fmin fminq
228 # define c99_hypot hypotq
229 # define c99_ilogb ilogbq
230 # define c99_lgamma lgammaq
231 # define c99_log1p log1pq
232 # define c99_log2 log2q
236 # define c99_lrint lrintq
237 # define c99_lround lroundq
238 # define c99_nan nanq
239 # define c99_nearbyint nearbyintq
240 # define c99_nextafter nextafterq
242 # define c99_remainder remainderq
243 # define c99_remquo remquoq
244 # define c99_rint rintq
245 # define c99_round roundq
246 # define c99_scalbn scalbnq
247 # define c99_signbit signbitq
248 # define c99_tgamma tgammaq
249 # define c99_trunc truncq
250 # define bessel_j0 j0q
251 # define bessel_j1 j1q
252 # define bessel_jn jnq
253 # define bessel_y0 y0q
254 # define bessel_y1 y1q
255 # define bessel_yn ynq
256 #elif defined(USE_LONG_DOUBLE) && \
257 (defined(HAS_FREXPL) || defined(HAS_ILOGBL)) && defined(HAS_SQRTL)
258 /* Use some of the Configure scans for long double math functions
259 * as the canary for all the C99 *l variants being defined. */
260 # define c99_acosh acoshl
261 # define c99_asinh asinhl
262 # define c99_atanh atanhl
263 # define c99_cbrt cbrtl
264 # define c99_copysign copysignl
265 # define c99_erf erfl
266 # define c99_erfc erfcl
267 # define c99_exp2 exp2l
268 # define c99_expm1 expm1l
269 # define c99_fdim fdiml
270 # define c99_fma fmal
271 # define c99_fmax fmaxl
272 # define c99_fmin fminl
273 # define c99_hypot hypotl
274 # define c99_ilogb ilogbl
275 # define c99_lgamma lgammal
276 # define c99_log1p log1pl
277 # define c99_log2 log2l
278 # define c99_logb logbl
279 # if defined(USE_64_BIT_INT) && QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_LLRINTL)
280 # define c99_lrint llrintl
281 # elif defined(HAS_LRINTL)
282 # define c99_lrint lrintl
284 # if defined(USE_64_BIT_INT) && QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_LLROUNDL)
285 # define c99_lround llroundl
286 # elif defined(HAS_LROUNDL)
287 # define c99_lround lroundl
289 # define c99_nan nanl
290 # define c99_nearbyint nearbyintl
291 # define c99_nextafter nextafterl
292 # define c99_nexttoward nexttowardl
293 # define c99_remainder remainderl
294 # define c99_remquo remquol
295 # define c99_rint rintl
296 # define c99_round roundl
297 # define c99_scalbn scalbnl
298 # ifdef HAS_SIGNBIT /* possibly bad assumption */
299 # define c99_signbit signbitl
301 # define c99_tgamma tgammal
302 # define c99_trunc truncl
304 # define c99_acosh acosh
305 # define c99_asinh asinh
306 # define c99_atanh atanh
307 # define c99_cbrt cbrt
308 # define c99_copysign copysign
310 # define c99_erfc erfc
311 # define c99_exp2 exp2
312 # define c99_expm1 expm1
313 # define c99_fdim fdim
315 # define c99_fmax fmax
316 # define c99_fmin fmin
317 # define c99_hypot hypot
318 # define c99_ilogb ilogb
319 # define c99_lgamma lgamma
320 # define c99_log1p log1p
321 # define c99_log2 log2
322 # define c99_logb logb
323 # if defined(USE_64_BIT_INT) && QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_LLRINT)
324 # define c99_lrint llrint
326 # define c99_lrint lrint
328 # if defined(USE_64_BIT_INT) && QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_LLROUND)
329 # define c99_lround llround
331 # define c99_lround lround
334 # define c99_nearbyint nearbyint
335 # define c99_nextafter nextafter
336 # define c99_nexttoward nexttoward
337 # define c99_remainder remainder
338 # define c99_remquo remquo
339 # define c99_rint rint
340 # define c99_round round
341 # define c99_scalbn scalbn
342 /* We already define Perl_signbit in perl.h. */
344 # define c99_signbit signbit
346 # define c99_tgamma tgamma
347 # define c99_trunc trunc
350 /* AIX xlc (__IBMC__) really doesn't have the following long double
351 * math interfaces (no __acoshl128 aka acoshl, etc.), see
352 * hints/aix.sh. These are in the -lc128 but fail to be found
353 * during dynamic linking/loading.
355 * XXX1 Better Configure scans
356 * XXX2 Is this xlc version dependent? */
357 #if defined(USE_LONG_DOUBLE) && defined(__IBMC__)
377 # undef c99_nearbyint
378 # undef c99_nextafter
379 # undef c99_nexttoward
380 # undef c99_remainder
391 # define isunordered(x, y) (Perl_isnan(x) || Perl_isnan(y))
392 # elif defined(HAS_UNORDERED)
393 # define isunordered(x, y) unordered(x, y)
397 /* XXX these isgreater/isnormal/isunordered macros definitions should
398 * be moved further in the file to be part of the emulations, so that
399 * platforms can e.g. #undef c99_isunordered and have it work like
400 * it does for the other interfaces. */
402 #if !defined(isgreater) && defined(isunordered)
403 # define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
404 # define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
405 # define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
406 # define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
407 # define islessgreater(x, y) (!isunordered((x), (y)) && \
408 ((x) > (y) || (y) > (x)))
411 /* Check both the Configure symbol and the macro-ness (like C99 promises). */
412 #if defined(HAS_FPCLASSIFY) && defined(fpclassify)
413 # define c99_fpclassify fpclassify
415 /* Like isnormal(), the isfinite(), isinf(), and isnan() are also C99
416 and also (sizeof-arg-aware) macros, but they are already well taken
417 care of by Configure et al, and defined in perl.h as
418 Perl_isfinite(), Perl_isinf(), and Perl_isnan(). */
420 # define c99_isnormal isnormal
422 #ifdef isgreater /* canary for all the C99 is*<cmp>* macros. */
423 # define c99_isgreater isgreater
424 # define c99_isgreaterequal isgreaterequal
425 # define c99_isless isless
426 # define c99_islessequal islessequal
427 # define c99_islessgreater islessgreater
428 # define c99_isunordered isunordered
431 /* The Great Wall of Undef where according to the definedness of HAS_FOO symbols
432 * the corresponding c99_foo wrappers are undefined. This list doesn't include
433 * the isfoo() interfaces because they are either type-aware macros, or dealt
434 * separately, already in perl.h */
475 #ifndef HAS_FPCLASSIFY
476 # undef c99_fpclassify
505 #ifndef HAS_NEARBYINT
506 # undef c99_nearbyint
508 #ifndef HAS_NEXTAFTER
509 # undef c99_nextafter
511 #ifndef HAS_NEXTTOWARD
512 # undef c99_nexttoward
514 #ifndef HAS_REMAINDER
515 # undef c99_remainder
541 /* Some APIs exist under Win32 with "underbar" names. */
544 # undef c99_nextafter
545 # define c99_hypot _hypot
546 # define c99_logb _logb
547 # define c99_nextafter _nextafter
549 # define bessel_j0 _j0
550 # define bessel_j1 _j1
551 # define bessel_jn _jn
552 # define bessel_y0 _y0
553 # define bessel_y1 _y1
554 # define bessel_yn _yn
558 /* The Bessel functions: BSD, SVID, XPG4, and POSIX. But not C99. */
559 #if defined(HAS_J0) && !defined(bessel_j0)
560 # if defined(USE_LONG_DOUBLE) && defined(HAS_J0L)
561 # define bessel_j0 j0l
562 # define bessel_j1 j1l
563 # define bessel_jn jnl
564 # define bessel_y0 y0l
565 # define bessel_y1 y1l
566 # define bessel_yn ynl
568 # define bessel_j0 j0
569 # define bessel_j1 j1
570 # define bessel_jn jn
571 # define bessel_y0 y0
572 # define bessel_y1 y1
573 # define bessel_yn yn
577 /* Emulations for missing math APIs.
579 * Keep in mind that the point of many of these functions is that
580 * they, if available, are supposed to give more precise/more
581 * numerically stable results.
583 * See e.g. http://www.johndcook.com/math_h.html
587 static NV my_acosh(NV x)
589 return Perl_log(x + Perl_sqrt(x * x - 1));
591 # define c99_acosh my_acosh
595 static NV my_asinh(NV x)
597 return Perl_log(x + Perl_sqrt(x * x + 1));
599 # define c99_asinh my_asinh
603 static NV my_atanh(NV x)
605 return (Perl_log(1 + x) - Perl_log(1 - x)) / 2;
607 # define c99_atanh my_atanh
611 static NV my_cbrt(NV x)
613 static const NV one_third = (NV)1.0/3;
614 return x >= 0.0 ? Perl_pow(x, one_third) : -Perl_pow(-x, one_third);
616 # define c99_cbrt my_cbrt
620 static NV my_copysign(NV x, NV y)
622 return y >= 0 ? (x < 0 ? -x : x) : (x < 0 ? x : -x);
624 # define c99_copysign my_copysign
627 /* XXX cosh (though c89) */
630 static NV my_erf(NV x)
632 /* http://www.johndcook.com/cpp_erf.html -- public domain */
634 NV a2 = -0.284496736;
636 NV a4 = -1.453152027;
640 int sign = x < 0 ? -1 : 1; /* Save the sign. */
643 /* Abramowitz and Stegun formula 7.1.26 */
644 t = 1.0 / (1.0 + p * x);
645 y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1) * t * Perl_exp(-x*x);
649 # define c99_erf my_erf
653 static NV my_erfc(NV x) {
654 /* This is not necessarily numerically stable, but better than nothing. */
655 return 1.0 - c99_erf(x);
657 # define c99_erfc my_erfc
661 static NV my_exp2(NV x)
663 return Perl_pow((NV)2.0, x);
665 # define c99_exp2 my_exp2
669 static NV my_expm1(NV x)
671 if (PERL_ABS(x) < 1e-5)
672 /* http://www.johndcook.com/cpp_expm1.html -- public domain.
673 * Taylor series, the first four terms (the last term quartic). */
674 /* Probably not enough for long doubles. */
675 return x * (1.0 + x * (1/2.0 + x * (1/6.0 + x/24.0)));
677 return Perl_exp(x) - 1;
679 # define c99_expm1 my_expm1
683 static NV my_fdim(NV x, NV y)
685 return (Perl_isnan(x) || Perl_isnan(y)) ? NV_NAN : (x > y ? x - y : 0);
687 # define c99_fdim my_fdim
691 static NV my_fma(NV x, NV y, NV z)
695 # define c99_fma my_fma
699 static NV my_fmax(NV x, NV y)
702 return Perl_isnan(y) ? NV_NAN : y;
703 } else if (Perl_isnan(y)) {
706 return x > y ? x : y;
708 # define c99_fmax my_fmax
712 static NV my_fmin(NV x, NV y)
715 return Perl_isnan(y) ? NV_NAN : y;
716 } else if (Perl_isnan(y)) {
719 return x < y ? x : y;
721 # define c99_fmin my_fmin
724 #ifndef c99_fpclassify
726 static IV my_fpclassify(NV x)
728 #ifdef Perl_fp_class_inf
729 if (Perl_fp_class_inf(x)) return FP_INFINITE;
730 if (Perl_fp_class_nan(x)) return FP_NAN;
731 if (Perl_fp_class_norm(x)) return FP_NORMAL;
732 if (Perl_fp_class_denorm(x)) return FP_SUBNORMAL;
733 if (Perl_fp_class_zero(x)) return FP_ZERO;
734 # define c99_fpclassify my_fpclassify
742 static NV my_hypot(NV x, NV y)
744 /* http://en.wikipedia.org/wiki/Hypot */
746 x = PERL_ABS(x); /* Take absolute values. */
752 if (x < y) { /* Swap so that y is less. */
758 return x * Perl_sqrt(1.0 + t * t);
760 # define c99_hypot my_hypot
764 static IV my_ilogb(NV x)
766 return (IV)(Perl_log(x) * M_LOG2E);
768 # define c99_ilogb my_ilogb
771 /* tgamma and lgamma emulations based on
772 * http://www.johndcook.com/cpp_gamma.html,
773 * code placed in public domain.
775 * Note that these implementations (neither the johndcook originals
776 * nor these) do NOT set the global signgam variable. This is not
777 * necessarily a bad thing. */
779 /* Note that the tgamma() and lgamma() implementations
780 * here depend on each other. */
783 static NV my_tgamma(NV x);
784 # define c99_tgamma my_tgamma
787 static NV my_lgamma(NV x);
788 # define c99_lgamma my_lgamma
792 static NV my_tgamma(NV x)
794 const NV gamma = 0.577215664901532860606512090; /* Euler's gamma constant. */
795 if (Perl_isnan(x) || x < 0.0)
797 if (x == 0.0 || x == NV_INF)
798 return x == -0.0 ? -NV_INF : NV_INF;
800 /* The function domain is split into three intervals:
801 * (0, 0.001), [0.001, 12), and (12, infinity) */
803 /* First interval: (0, 0.001)
804 * For small values, 1/tgamma(x) has power series x + gamma x^2,
805 * so in this range, 1/tgamma(x) = x + gamma x^2 with error on the order of x^3.
806 * The relative error over this interval is less than 6e-7. */
808 return 1.0 / (x * (1.0 + gamma * x));
810 /* Second interval: [0.001, 12) */
812 double y = x; /* Working copy. */
814 /* Numerator coefficients for approximation over the interval (1,2) */
815 static const NV p[] = {
816 -1.71618513886549492533811E+0,
817 2.47656508055759199108314E+1,
818 -3.79804256470945635097577E+2,
819 6.29331155312818442661052E+2,
820 8.66966202790413211295064E+2,
821 -3.14512729688483675254357E+4,
822 -3.61444134186911729807069E+4,
823 6.64561438202405440627855E+4
825 /* Denominator coefficients for approximation over the interval (1, 2) */
826 static const NV q[] = {
827 -3.08402300119738975254353E+1,
828 3.15350626979604161529144E+2,
829 -1.01515636749021914166146E+3,
830 -3.10777167157231109440444E+3,
831 2.25381184209801510330112E+4,
832 4.75584627752788110767815E+3,
833 -1.34659959864969306392456E+5,
834 -1.15132259675553483497211E+5
845 n = (int)Perl_floor(y) - 1;
849 for (i = 0; i < 8; i++) {
850 num = (num + p[i]) * z;
851 den = den * z + q[i];
853 result = num / den + 1.0;
856 /* Use the identity tgamma(z) = tgamma(z+1)/z
857 * The variable "result" now holds tgamma of the original y + 1
858 * Thus we use y - 1 to get back the original y. */
862 /* Use the identity tgamma(z+n) = z*(z+1)* ... *(z+n-1)*tgamma(z) */
863 for (i = 0; i < n; i++)
870 /* Third interval: [12, +Inf) */
871 #if LDBL_MANT_DIG == 113 /* IEEE quad prec */
881 return Perl_exp(c99_lgamma(x));
886 static NV my_lgamma(NV x)
890 if (x <= 0 || x == NV_INF)
892 if (x == 1.0 || x == 2.0)
895 return Perl_log(PERL_ABS(c99_tgamma(x)));
896 /* Abramowitz and Stegun 6.1.41
897 * Asymptotic series should be good to at least 11 or 12 figures
898 * For error analysis, see Whittiker and Watson
899 * A Course in Modern Analysis (1927), page 252 */
901 static const NV c[8] = {
911 NV z = 1.0 / (x * x);
913 static const NV half_log_of_two_pi =
914 0.91893853320467274178032973640562;
917 for (i = 6; i >= 0; i--) {
922 return (x - 0.5) * Perl_log(x) - x + half_log_of_two_pi + series;
928 static NV my_log1p(NV x)
930 /* http://www.johndcook.com/cpp_log_one_plus_x.html -- public domain.
931 * Taylor series, the first four terms (the last term quartic). */
936 if (PERL_ABS(x) > 1e-4)
937 return Perl_log(1.0 + x);
939 /* Probably not enough for long doubles. */
940 return x * (1.0 + x * (-1/2.0 + x * (1/3.0 - x/4.0)));
942 # define c99_log1p my_log1p
946 static NV my_log2(NV x)
948 return Perl_log(x) * M_LOG2E;
950 # define c99_log2 my_log2
957 static int my_fegetround()
959 #ifdef HAS_FEGETROUND
961 #elif defined(HAS_FPGETROUND)
962 switch (fpgetround()) {
963 case FP_RN: return FE_TONEAREST;
964 case FP_RZ: return FE_TOWARDZERO;
965 case FP_RM: return FE_DOWNWARD;
966 case FP_RP: return FE_UPWARD;
969 #elif defined(FLT_ROUNDS)
970 switch (FLT_ROUNDS) {
971 case 0: return FE_TOWARDZERO;
972 case 1: return FE_TONEAREST;
973 case 2: return FE_UPWARD;
974 case 3: return FE_DOWNWARD;
977 #elif defined(__osf__) /* Tru64 */
978 switch (read_rnd()) {
979 case FP_RND_RN: return FE_TONEAREST;
980 case FP_RND_RZ: return FE_TOWARDZERO;
981 case FP_RND_RM: return FE_DOWNWARD;
982 case FP_RND_RP: return FE_UPWARD;
990 /* Toward closest integer. */
991 #define MY_ROUND_NEAREST(x) ((NV)((IV)((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)))
994 #define MY_ROUND_TRUNC(x) ((NV)((IV)(x)))
996 /* Toward minus infinity. */
997 #define MY_ROUND_DOWN(x) ((NV)((IV)((x) >= 0.0 ? (x) : (x) - 0.5)))
999 /* Toward plus infinity. */
1000 #define MY_ROUND_UP(x) ((NV)((IV)((x) >= 0.0 ? (x) + 0.5 : (x))))
1002 #if (!defined(c99_nearbyint) || !defined(c99_lrint)) && defined(FE_TONEAREST)
1003 static NV my_rint(NV x)
1006 switch (my_fegetround()) {
1007 case FE_TONEAREST: return MY_ROUND_NEAREST(x);
1008 case FE_TOWARDZERO: return MY_ROUND_TRUNC(x);
1009 case FE_DOWNWARD: return MY_ROUND_DOWN(x);
1010 case FE_UPWARD: return MY_ROUND_UP(x);
1011 default: return NV_NAN;
1013 #elif defined(HAS_FPGETROUND)
1014 switch (fpgetround()) {
1015 case FP_RN: return MY_ROUND_NEAREST(x);
1016 case FP_RZ: return MY_ROUND_TRUNC(x);
1017 case FP_RM: return MY_ROUND_DOWN(x);
1018 case FE_RP: return MY_ROUND_UP(x);
1019 default: return NV_NAN;
1027 /* XXX nearbyint() and rint() are not really identical -- but the difference
1028 * is messy: nearbyint is defined NOT to raise FE_INEXACT floating point
1029 * exceptions, while rint() is defined to MAYBE raise them. At the moment
1030 * Perl is blissfully unaware of such fine detail of floating point. */
1031 #ifndef c99_nearbyint
1032 # ifdef FE_TONEAREST
1033 # define c99_nearbyrint my_rint
1038 # ifdef FE_TONEAREST
1039 static IV my_lrint(NV x)
1041 return (IV)my_rint(x);
1043 # define c99_lrint my_lrint
1048 static IV my_lround(NV x)
1050 return (IV)MY_ROUND_NEAREST(x);
1052 # define c99_lround my_lround
1060 # ifdef FE_TONEAREST
1061 # define c99_rint my_rint
1066 static NV my_round(NV x)
1068 return MY_ROUND_NEAREST(x);
1070 # define c99_round my_round
1074 # if defined(Perl_ldexp) && FLT_RADIX == 2
1075 static NV my_scalbn(NV x, int y)
1077 return Perl_ldexp(x, y);
1079 # define c99_scalbn my_scalbn
1083 /* XXX sinh (though c89) */
1085 /* tgamma -- see lgamma */
1087 /* XXX tanh (though c89) */
1090 static NV my_trunc(NV x)
1092 return MY_ROUND_TRUNC(x);
1094 # define c99_trunc my_trunc
1097 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
1098 metaconfig for future extension writers. We don't use them in POSIX.
1099 (This is really sneaky :-) --AD
1101 #if defined(I_TERMIOS)
1102 #include <termios.h>
1110 #include <sys/stat.h>
1111 #include <sys/types.h>
1119 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
1120 extern char *tzname[];
1123 #if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
1124 char *tzname[] = { "" , "" };
1128 #if defined(__VMS) && !defined(__POSIX_SOURCE)
1130 # include <utsname.h>
1133 # define mkfifo(a,b) (not_here("mkfifo"),-1)
1135 /* The POSIX notion of ttyname() is better served by getname() under VMS */
1136 static char ttnambuf[64];
1137 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
1140 #if defined (__CYGWIN__)
1141 # define tzname _tzname
1143 #if defined (WIN32) || defined (NETWARE)
1145 # define mkfifo(a,b) not_here("mkfifo")
1146 # define ttyname(a) (char*)not_here("ttyname")
1147 # define sigset_t long
1150 # define mode_t short
1153 # define mode_t short
1155 # define tzset() not_here("tzset")
1157 # ifndef _POSIX_OPEN_MAX
1158 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
1161 # define sigaction(a,b,c) not_here("sigaction")
1162 # define sigpending(a) not_here("sigpending")
1163 # define sigprocmask(a,b,c) not_here("sigprocmask")
1164 # define sigsuspend(a) not_here("sigsuspend")
1165 # define sigemptyset(a) not_here("sigemptyset")
1166 # define sigaddset(a,b) not_here("sigaddset")
1167 # define sigdelset(a,b) not_here("sigdelset")
1168 # define sigfillset(a) not_here("sigfillset")
1169 # define sigismember(a,b) not_here("sigismember")
1173 # define setuid(a) not_here("setuid")
1174 # define setgid(a) not_here("setgid")
1175 #endif /* NETWARE */
1176 #ifndef USE_LONG_DOUBLE
1177 # define strtold(s1,s2) not_here("strtold")
1178 #endif /* USE_LONG_DOUBLE */
1183 # define mkfifo(a,b) not_here("mkfifo")
1184 # else /* !( defined OS2 ) */
1186 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
1189 # endif /* !HAS_MKFIFO */
1194 # include <sys/times.h>
1196 # include <sys/utsname.h>
1198 # include <sys/wait.h>
1202 #endif /* WIN32 || NETWARE */
1206 typedef long SysRetLong;
1207 typedef sigset_t* POSIX__SigSet;
1208 typedef HV* POSIX__SigAction;
1210 typedef struct termios* POSIX__Termios;
1211 #else /* Define termios types to int, and call not_here for the functions.*/
1212 #define POSIX__Termios int
1214 #define tcflag_t int
1216 #define cfgetispeed(x) not_here("cfgetispeed")
1217 #define cfgetospeed(x) not_here("cfgetospeed")
1218 #define tcdrain(x) not_here("tcdrain")
1219 #define tcflush(x,y) not_here("tcflush")
1220 #define tcsendbreak(x,y) not_here("tcsendbreak")
1221 #define cfsetispeed(x,y) not_here("cfsetispeed")
1222 #define cfsetospeed(x,y) not_here("cfsetospeed")
1223 #define ctermid(x) (char *) not_here("ctermid")
1224 #define tcflow(x,y) not_here("tcflow")
1225 #define tcgetattr(x,y) not_here("tcgetattr")
1226 #define tcsetattr(x,y,z) not_here("tcsetattr")
1229 /* Possibly needed prototypes */
1232 double strtod (const char *, char **);
1233 long strtol (const char *, char **, int);
1234 unsigned long strtoul (const char *, char **, int);
1236 long double strtold (const char *, char **);
1241 #ifndef HAS_DIFFTIME
1243 #define difftime(a,b) not_here("difftime")
1246 #ifndef HAS_FPATHCONF
1247 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
1250 #define mktime(a) not_here("mktime")
1253 #define nice(a) not_here("nice")
1255 #ifndef HAS_PATHCONF
1256 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
1259 #define sysconf(n) (SysRetLong) not_here("sysconf")
1261 #ifndef HAS_READLINK
1262 #define readlink(a,b,c) not_here("readlink")
1265 #define setpgid(a,b) not_here("setpgid")
1268 #define setsid() not_here("setsid")
1271 #define strcoll(s1,s2) not_here("strcoll")
1274 #define strtod(s1,s2) not_here("strtod")
1277 #define strtold(s1,s2) not_here("strtold")
1280 #define strtol(s1,s2,b) not_here("strtol")
1283 #define strtoul(s1,s2,b) not_here("strtoul")
1286 #define strxfrm(s1,s2,n) not_here("strxfrm")
1288 #ifndef HAS_TCGETPGRP
1289 #define tcgetpgrp(a) not_here("tcgetpgrp")
1291 #ifndef HAS_TCSETPGRP
1292 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
1296 #define times(a) not_here("times")
1297 #endif /* NETWARE */
1300 #define uname(a) not_here("uname")
1303 #define waitpid(a,b,c) not_here("waitpid")
1308 #define mblen(a,b) not_here("mblen")
1311 #ifndef HAS_MBSTOWCS
1312 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
1315 #define mbtowc(pwc, s, n) not_here("mbtowc")
1317 #ifndef HAS_WCSTOMBS
1318 #define wcstombs(s, pwcs, n) not_here("wcstombs")
1321 #define wctomb(s, wchar) not_here("wcstombs")
1323 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
1324 /* If we don't have these functions, then we wouldn't have gotten a typedef
1325 for wchar_t, the wide character type. Defining wchar_t allows the
1326 functions referencing it to compile. Its actual type is then meaningless,
1327 since without the above functions, all sections using it end up calling
1328 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
1330 #define wchar_t char
1334 #ifndef HAS_LOCALECONV
1335 # define localeconv() not_here("localeconv")
1337 struct lconv_offset {
1342 const struct lconv_offset lconv_strings[] = {
1343 #ifdef USE_LOCALE_NUMERIC
1344 {"decimal_point", STRUCT_OFFSET(struct lconv, decimal_point)},
1345 {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)},
1346 # ifndef NO_LOCALECONV_GROUPING
1347 {"grouping", STRUCT_OFFSET(struct lconv, grouping)},
1350 #ifdef USE_LOCALE_MONETARY
1351 {"int_curr_symbol", STRUCT_OFFSET(struct lconv, int_curr_symbol)},
1352 {"currency_symbol", STRUCT_OFFSET(struct lconv, currency_symbol)},
1353 {"mon_decimal_point", STRUCT_OFFSET(struct lconv, mon_decimal_point)},
1354 # ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1355 {"mon_thousands_sep", STRUCT_OFFSET(struct lconv, mon_thousands_sep)},
1357 # ifndef NO_LOCALECONV_MON_GROUPING
1358 {"mon_grouping", STRUCT_OFFSET(struct lconv, mon_grouping)},
1360 {"positive_sign", STRUCT_OFFSET(struct lconv, positive_sign)},
1361 {"negative_sign", STRUCT_OFFSET(struct lconv, negative_sign)},
1366 #ifdef USE_LOCALE_NUMERIC
1368 /* The Linux man pages say these are the field names for the structure
1369 * components that are LC_NUMERIC; the rest being LC_MONETARY */
1370 # define isLC_NUMERIC_STRING(name) (strcmp(name, "decimal_point") \
1371 || strcmp(name, "thousands_sep") \
1373 /* There should be no harm done \
1374 * checking for this, even if \
1375 * NO_LOCALECONV_GROUPING */ \
1376 || strcmp(name, "grouping"))
1378 # define isLC_NUMERIC_STRING(name) (0)
1381 const struct lconv_offset lconv_integers[] = {
1382 #ifdef USE_LOCALE_MONETARY
1383 {"int_frac_digits", STRUCT_OFFSET(struct lconv, int_frac_digits)},
1384 {"frac_digits", STRUCT_OFFSET(struct lconv, frac_digits)},
1385 {"p_cs_precedes", STRUCT_OFFSET(struct lconv, p_cs_precedes)},
1386 {"p_sep_by_space", STRUCT_OFFSET(struct lconv, p_sep_by_space)},
1387 {"n_cs_precedes", STRUCT_OFFSET(struct lconv, n_cs_precedes)},
1388 {"n_sep_by_space", STRUCT_OFFSET(struct lconv, n_sep_by_space)},
1389 {"p_sign_posn", STRUCT_OFFSET(struct lconv, p_sign_posn)},
1390 {"n_sign_posn", STRUCT_OFFSET(struct lconv, n_sign_posn)},
1391 #ifdef HAS_LC_MONETARY_2008
1392 {"int_p_cs_precedes", STRUCT_OFFSET(struct lconv, int_p_cs_precedes)},
1393 {"int_p_sep_by_space", STRUCT_OFFSET(struct lconv, int_p_sep_by_space)},
1394 {"int_n_cs_precedes", STRUCT_OFFSET(struct lconv, int_n_cs_precedes)},
1395 {"int_n_sep_by_space", STRUCT_OFFSET(struct lconv, int_n_sep_by_space)},
1396 {"int_p_sign_posn", STRUCT_OFFSET(struct lconv, int_p_sign_posn)},
1397 {"int_n_sign_posn", STRUCT_OFFSET(struct lconv, int_n_sign_posn)},
1403 #endif /* HAS_LOCALECONV */
1405 #ifdef HAS_LONG_DOUBLE
1406 # if LONG_DOUBLESIZE > NVSIZE
1407 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
1411 #ifndef HAS_LONG_DOUBLE
1423 /* Background: in most systems the low byte of the wait status
1424 * is the signal (the lowest 7 bits) and the coredump flag is
1425 * the eight bit, and the second lowest byte is the exit status.
1426 * BeOS bucks the trend and has the bytes in different order.
1427 * See beos/beos.c for how the reality is bent even in BeOS
1428 * to follow the traditional. However, to make the POSIX
1429 * wait W*() macros to work in BeOS, we need to unbend the
1430 * reality back in place. --jhi */
1431 /* In actual fact the code below is to blame here. Perl has an internal
1432 * representation of the exit status ($?), which it re-composes from the
1433 * OS's representation using the W*() POSIX macros. The code below
1434 * incorrectly uses the W*() macros on the internal representation,
1435 * which fails for OSs that have a different representation (namely BeOS
1436 * and Haiku). WMUNGE() is a hack that converts the internal
1437 * representation into the OS specific one, so that the W*() macros work
1438 * as expected. The better solution would be not to use the W*() macros
1439 * in the first place, though. -- Ingo Weinhold
1441 #if defined(__HAIKU__)
1442 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
1444 # define WMUNGE(x) (x)
1448 not_here(const char *s)
1450 croak("POSIX::%s not implemented on this architecture", s);
1454 #include "const-c.inc"
1457 restore_sigmask(pTHX_ SV *osset_sv)
1459 /* Fortunately, restoring the signal mask can't fail, because
1460 * there's nothing we can do about it if it does -- we're not
1461 * supposed to return -1 from sigaction unless the disposition
1464 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
1465 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
1469 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
1470 SV *const t = newSVrv(rv, packname);
1471 void *const p = sv_grow(t, size + 1);
1481 * (1) The CRT maintains its own copy of the environment, separate from
1482 * the Win32API copy.
1484 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
1485 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
1488 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
1489 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
1492 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
1493 * calls CRT tzset(), but only the first time it is called, and in turn
1494 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
1495 * local copy of the environment and hence gets the original setting as
1496 * perl never updates the CRT copy when assigning to $ENV{TZ}.
1498 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
1499 * putenv() to update the CRT copy of the environment (if it is different)
1500 * whenever we're about to call tzset().
1502 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
1505 * (a) Each interpreter has its own copy of the environment inside the
1506 * perlhost structure. That allows applications that host multiple
1507 * independent Perl interpreters to isolate environment changes from
1508 * each other. (This is similar to how the perlhost mechanism keeps a
1509 * separate working directory for each Perl interpreter, so that calling
1510 * chdir() will not affect other interpreters.)
1512 * (b) Only the first Perl interpreter instantiated within a process will
1513 * "write through" environment changes to the process environment.
1515 * (c) Even the primary Perl interpreter won't update the CRT copy of the
1516 * the environment, only the Win32API copy (it calls win32_putenv()).
1518 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
1519 * sense to only update the process environment when inside the main
1520 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
1521 * from here so we'll just have to check PL_curinterp instead.
1523 * Therefore, we can simply #undef getenv() and putenv() so that those names
1524 * always refer to the CRT functions, and explicitly call win32_getenv() to
1525 * access perl's %ENV.
1527 * We also #undef malloc() and free() to be sure we are using the CRT
1528 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
1529 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
1530 * when the Perl interpreter is being destroyed so we'd end up with a pointer
1531 * into deallocated memory in environ[] if a program embedding a Perl
1532 * interpreter continues to operate even after the main Perl interpreter has
1535 * Note that we don't free() the malloc()ed memory unless and until we call
1536 * malloc() again ourselves because the CRT putenv() function simply puts its
1537 * pointer argument into the environ[] array (it doesn't make a copy of it)
1538 * so this memory must otherwise be leaked.
1547 fix_win32_tzenv(void)
1549 static char* oldenv = NULL;
1551 const char* perl_tz_env = win32_getenv("TZ");
1552 const char* crt_tz_env = getenv("TZ");
1553 if (perl_tz_env == NULL)
1555 if (crt_tz_env == NULL)
1557 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
1558 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
1559 if (newenv != NULL) {
1560 sprintf(newenv, "TZ=%s", perl_tz_env);
1572 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
1573 * This code is duplicated in the Time-Piece module, so any changes made here
1574 * should be made there too.
1580 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
1581 if (PL_curinterp == aTHX)
1588 typedef int (*isfunc_t)(int);
1589 typedef void (*any_dptr_t)(void *);
1591 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
1593 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
1594 static XSPROTO(is_common)
1599 croak_xs_usage(cv, "charstring");
1604 /*int RETVAL = 0; YYY means uncomment this to return false on an
1605 * empty string input */
1607 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
1608 unsigned char *e = s + len;
1609 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
1611 if (ckWARN_d(WARN_DEPRECATED)) {
1613 /* Warn exactly once for each lexical place this function is
1614 * called. See thread at
1615 * http://markmail.org/thread/jhqcag5njmx7jpyu */
1617 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
1618 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
1619 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
1620 "Calling POSIX::%"HEKf"() is deprecated",
1621 HEKfARG(GvNAME_HEK(CvGV(cv))));
1622 (void)hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
1626 /*if (e > s) { YYY */
1627 for (RETVAL = 1; RETVAL && s < e; s++)
1637 MODULE = POSIX PACKAGE = POSIX
1642 const char *file = __FILE__;
1645 /* silence compiler warning about not_here() defined but not used */
1646 if (0) not_here("");
1648 /* Ensure we get the function, not a macro implementation. Like the C89
1649 standard says we can... */
1651 cv = newXS("POSIX::isalnum", is_common, file);
1652 XSANY.any_dptr = (any_dptr_t) &isalnum;
1654 cv = newXS("POSIX::isalpha", is_common, file);
1655 XSANY.any_dptr = (any_dptr_t) &isalpha;
1657 cv = newXS("POSIX::iscntrl", is_common, file);
1658 XSANY.any_dptr = (any_dptr_t) &iscntrl;
1660 cv = newXS("POSIX::isdigit", is_common, file);
1661 XSANY.any_dptr = (any_dptr_t) &isdigit;
1663 cv = newXS("POSIX::isgraph", is_common, file);
1664 XSANY.any_dptr = (any_dptr_t) &isgraph;
1666 cv = newXS("POSIX::islower", is_common, file);
1667 XSANY.any_dptr = (any_dptr_t) &islower;
1669 cv = newXS("POSIX::isprint", is_common, file);
1670 XSANY.any_dptr = (any_dptr_t) &isprint;
1672 cv = newXS("POSIX::ispunct", is_common, file);
1673 XSANY.any_dptr = (any_dptr_t) &ispunct;
1675 cv = newXS("POSIX::isspace", is_common, file);
1676 XSANY.any_dptr = (any_dptr_t) &isspace;
1678 cv = newXS("POSIX::isupper", is_common, file);
1679 XSANY.any_dptr = (any_dptr_t) &isupper;
1681 cv = newXS("POSIX::isxdigit", is_common, file);
1682 XSANY.any_dptr = (any_dptr_t) &isxdigit;
1685 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
1688 new(packname = "POSIX::SigSet", ...)
1689 const char * packname
1694 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1698 for (i = 1; i < items; i++)
1699 sigaddset(s, SvIV(ST(i)));
1705 POSIX::SigSet sigset
1710 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
1716 POSIX::SigSet sigset
1720 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
1725 sigismember(sigset, sig)
1726 POSIX::SigSet sigset
1729 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
1732 new(packname = "POSIX::Termios", ...)
1733 const char * packname
1737 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1738 sizeof(struct termios), packname);
1739 /* The previous implementation stored a pointer to an uninitialised
1740 struct termios. Seems safer to initialise it, particularly as
1741 this implementation exposes the struct to prying from perl-space.
1743 memset(p, 0, 1 + sizeof(struct termios));
1746 not_here("termios");
1751 getattr(termios_ref, fd = 0)
1752 POSIX::Termios termios_ref
1755 RETVAL = tcgetattr(fd, termios_ref);
1759 # If we define TCSANOW here then both a found and not found constant sub
1760 # are created causing a Constant subroutine TCSANOW redefined warning
1762 # define DEF_SETATTR_ACTION 0
1764 # define DEF_SETATTR_ACTION TCSANOW
1767 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
1768 POSIX::Termios termios_ref
1770 int optional_actions
1772 /* The second argument to the call is mandatory, but we'd like to give
1773 it a useful default. 0 isn't valid on all operating systems - on
1774 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
1775 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
1776 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
1781 getispeed(termios_ref)
1782 POSIX::Termios termios_ref
1786 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
1791 getiflag(termios_ref)
1792 POSIX::Termios termios_ref
1798 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1801 RETVAL = termios_ref->c_iflag;
1804 RETVAL = termios_ref->c_oflag;
1807 RETVAL = termios_ref->c_cflag;
1810 RETVAL = termios_ref->c_lflag;
1813 RETVAL = 0; /* silence compiler warning */
1816 not_here(GvNAME(CvGV(cv)));
1823 getcc(termios_ref, ccix)
1824 POSIX::Termios termios_ref
1827 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1829 croak("Bad getcc subscript");
1830 RETVAL = termios_ref->c_cc[ccix];
1839 setispeed(termios_ref, speed)
1840 POSIX::Termios termios_ref
1846 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
1851 setiflag(termios_ref, flag)
1852 POSIX::Termios termios_ref
1859 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1862 termios_ref->c_iflag = flag;
1865 termios_ref->c_oflag = flag;
1868 termios_ref->c_cflag = flag;
1871 termios_ref->c_lflag = flag;
1875 not_here(GvNAME(CvGV(cv)));
1879 setcc(termios_ref, ccix, cc)
1880 POSIX::Termios termios_ref
1884 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1886 croak("Bad setcc subscript");
1887 termios_ref->c_cc[ccix] = cc;
1893 MODULE = POSIX PACKAGE = POSIX
1895 INCLUDE: const-xs.inc
1901 POSIX::WIFEXITED = 1
1902 POSIX::WIFSIGNALED = 2
1903 POSIX::WIFSTOPPED = 3
1907 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
1908 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
1909 RETVAL = 0; /* Silence compilers that notice this, but don't realise
1910 that not_here() can't return. */
1915 RETVAL = WEXITSTATUS(WMUNGE(status));
1917 not_here("WEXITSTATUS");
1922 RETVAL = WIFEXITED(WMUNGE(status));
1924 not_here("WIFEXITED");
1929 RETVAL = WIFSIGNALED(WMUNGE(status));
1931 not_here("WIFSIGNALED");
1936 RETVAL = WIFSTOPPED(WMUNGE(status));
1938 not_here("WIFSTOPPED");
1943 RETVAL = WSTOPSIG(WMUNGE(status));
1945 not_here("WSTOPSIG");
1950 RETVAL = WTERMSIG(WMUNGE(status));
1952 not_here("WTERMSIG");
1956 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
1962 open(filename, flags = O_RDONLY, mode = 0666)
1967 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1968 TAINT_PROPER("open");
1969 RETVAL = open(filename, flags, mode);
1977 #ifndef HAS_LOCALECONV
1978 localeconv(); /* A stub to call not_here(). */
1980 struct lconv *lcbuf;
1982 /* localeconv() deals with both LC_NUMERIC and LC_MONETARY, but
1983 * LC_MONETARY is already in the correct locale */
1984 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
1987 sv_2mortal((SV*)RETVAL);
1988 if ((lcbuf = localeconv())) {
1989 const struct lconv_offset *strings = lconv_strings;
1990 const struct lconv_offset *integers = lconv_integers;
1991 const char *ptr = (const char *) lcbuf;
1994 /* This string may be controlled by either LC_NUMERIC, or
1997 #if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY)
1998 = _is_cur_LC_category_utf8((isLC_NUMERIC_STRING(strings->name))
2001 #elif defined(USE_LOCALE_NUMERIC)
2002 = _is_cur_LC_category_utf8(LC_NUMERIC);
2003 #elif defined(USE_LOCALE_MONETARY)
2004 = _is_cur_LC_category_utf8(LC_MONETARY);
2009 const char *value = *((const char **)(ptr + strings->offset));
2011 if (value && *value) {
2012 (void) hv_store(RETVAL,
2014 strlen(strings->name),
2015 newSVpvn_utf8(value,
2018 /* We mark it as UTF-8 if a utf8 locale
2019 * and is valid and variant under UTF-8 */
2021 && ! is_invariant_string((U8 *) value, 0)
2022 && is_utf8_string((U8 *) value, 0)),
2025 } while ((++strings)->name);
2028 const char value = *((const char *)(ptr + integers->offset));
2030 if (value != CHAR_MAX)
2031 (void) hv_store(RETVAL, integers->name,
2032 strlen(integers->name), newSViv(value), 0);
2033 } while ((++integers)->name);
2035 RESTORE_NUMERIC_STANDARD();
2036 #endif /* HAS_LOCALECONV */
2041 setlocale(category, locale = 0)
2047 #ifdef USE_LOCALE_NUMERIC
2048 /* A 0 (or NULL) locale means only query what the current one is. We
2049 * have the LC_NUMERIC name saved, because we are normally switched
2050 * into the C locale for it. Switch back so an LC_ALL query will yield
2051 * the correct results; all other categories don't require special
2054 if (category == LC_NUMERIC) {
2055 XSRETURN_PV(PL_numeric_name);
2058 else if (category == LC_ALL) {
2059 SET_NUMERIC_LOCAL();
2064 #ifdef WIN32 /* Use wrapper on Windows */
2065 retval = Perl_my_setlocale(aTHX_ category, locale);
2067 retval = setlocale(category, locale);
2070 /* Should never happen that a query would return an error, but be
2071 * sure and reset to C locale */
2073 SET_NUMERIC_STANDARD();
2078 /* Save retval since subsequent setlocale() calls may overwrite it. */
2079 retval = savepv(retval);
2081 /* For locale == 0, we may have switched to NUMERIC_LOCAL. Switch back
2084 SET_NUMERIC_STANDARD();
2085 XSRETURN_PV(retval);
2089 #ifdef USE_LOCALE_CTYPE
2090 if (category == LC_CTYPE
2092 || category == LC_ALL
2098 if (category == LC_ALL)
2099 newctype = setlocale(LC_CTYPE, NULL);
2103 new_ctype(newctype);
2105 #endif /* USE_LOCALE_CTYPE */
2106 #ifdef USE_LOCALE_COLLATE
2107 if (category == LC_COLLATE
2109 || category == LC_ALL
2115 if (category == LC_ALL)
2116 newcoll = setlocale(LC_COLLATE, NULL);
2120 new_collate(newcoll);
2122 #endif /* USE_LOCALE_COLLATE */
2123 #ifdef USE_LOCALE_NUMERIC
2124 if (category == LC_NUMERIC
2126 || category == LC_ALL
2132 if (category == LC_ALL)
2133 newnum = setlocale(LC_NUMERIC, NULL);
2137 new_numeric(newnum);
2139 #endif /* USE_LOCALE_NUMERIC */
2185 RETVAL = Perl_acos(x); /* C89 math */
2189 RETVAL = c99_acosh(x);
2195 RETVAL = Perl_asin(x); /* C89 math */
2199 RETVAL = c99_asinh(x);
2205 RETVAL = Perl_atan(x); /* C89 math */
2209 RETVAL = c99_atanh(x);
2216 RETVAL = c99_cbrt(x);
2222 RETVAL = Perl_ceil(x); /* C89 math */
2225 RETVAL = Perl_cosh(x); /* C89 math */
2229 RETVAL = c99_erf(x);
2236 RETVAL = c99_erfc(x);
2243 RETVAL = c99_exp2(x);
2250 RETVAL = c99_expm1(x);
2256 RETVAL = Perl_floor(x); /* C89 math */
2260 RETVAL = bessel_j0(x);
2267 RETVAL = bessel_j1(x);
2273 /* XXX Note: the lgamma modifies a global variable (signgam),
2274 * which is evil. Some platforms have lgamma_r, which has
2275 * extra output parameter instead of the global variable. */
2277 RETVAL = c99_lgamma(x);
2283 RETVAL = log10(x); /* C89 math */
2287 RETVAL = c99_log1p(x);
2294 RETVAL = c99_log2(x);
2301 RETVAL = c99_logb(x);
2307 #ifdef c99_nearbyint
2308 RETVAL = c99_nearbyint(x);
2310 not_here("nearbyint");
2315 RETVAL = c99_rint(x);
2322 RETVAL = c99_round(x);
2328 RETVAL = Perl_sinh(x); /* C89 math */
2331 RETVAL = Perl_tan(x); /* C89 math */
2334 RETVAL = Perl_tanh(x); /* C89 math */
2338 RETVAL = c99_tgamma(x);
2345 RETVAL = c99_trunc(x);
2352 RETVAL = bessel_y0(x);
2360 RETVAL = bessel_y1(x);
2371 #ifdef HAS_FEGETROUND
2372 RETVAL = my_fegetround();
2375 not_here("fegetround");
2384 #ifdef HAS_FEGETROUND /* canary for fesetround */
2385 RETVAL = fesetround(x);
2386 #elif defined(HAS_FPGETROUND) /* canary for fpsetround */
2388 case FE_TONEAREST: RETVAL = fpsetround(FP_RN); break;
2389 case FE_TOWARDZERO: RETVAL = fpsetround(FP_RZ); break;
2390 case FE_DOWNWARD: RETVAL = fpsetround(FP_RM); break;
2391 case FE_UPWARD: RETVAL = fpsetround(FP_RP); break;
2392 default: RETVAL = -1; break;
2394 #elif defined(__osf__) /* Tru64 */
2396 case FE_TONEAREST: RETVAL = write_rnd(FP_RND_RN); break;
2397 case FE_TOWARDZERO: RETVAL = write_rnd(FP_RND_RZ); break;
2398 case FE_DOWNWARD: RETVAL = write_rnd(FP_RND_RM); break;
2399 case FE_UPWARD: RETVAL = write_rnd(FP_RND_RP); break;
2400 default: RETVAL = -1; break;
2405 not_here("fesetround");
2427 #ifdef c99_fpclassify
2428 RETVAL = c99_fpclassify(x);
2430 not_here("fpclassify");
2435 RETVAL = c99_ilogb(x);
2441 RETVAL = Perl_isfinite(x);
2444 RETVAL = Perl_isinf(x);
2447 RETVAL = Perl_isnan(x);
2451 RETVAL = c99_isnormal(x);
2453 not_here("isnormal");
2458 RETVAL = c99_lrint(x);
2465 RETVAL = c99_lround(x);
2473 RETVAL = Perl_signbit(x);
2475 RETVAL = (x < 0) || (x == -0.0);
2508 RETVAL = c99_copysign(x, y);
2510 not_here("copysign");
2515 RETVAL = c99_fdim(x, y);
2522 RETVAL = c99_fmax(x, y);
2529 RETVAL = c99_fmin(x, y);
2535 RETVAL = Perl_fmod(x, y); /* C89 math */
2539 RETVAL = c99_hypot(x, y);
2545 #ifdef c99_isgreater
2546 RETVAL = c99_isgreater(x, y);
2548 not_here("isgreater");
2552 #ifdef c99_isgreaterequal
2553 RETVAL = c99_isgreaterequal(x, y);
2555 not_here("isgreaterequal");
2560 RETVAL = c99_isless(x, y);
2566 #ifdef c99_islessequal
2567 RETVAL = c99_islessequal(x, y);
2569 not_here("islessequal");
2573 #ifdef c99_islessgreater
2574 RETVAL = c99_islessgreater(x, y);
2576 not_here("islessgreater");
2580 #ifdef c99_isunordered
2581 RETVAL = c99_isunordered(x, y);
2583 not_here("isunordered");
2587 #ifdef c99_nextafter
2588 RETVAL = c99_nextafter(x, y);
2590 not_here("nextafter");
2594 #ifdef c99_nexttoward
2595 RETVAL = c99_nexttoward(x, y);
2597 not_here("nexttoward");
2602 #ifdef c99_remainder
2603 RETVAL = c99_remainder(x, y);
2605 not_here("remainder");
2617 /* (We already know stack is long enough.) */
2618 PUSHs(sv_2mortal(newSVnv(Perl_frexp(x,&expvar)))); /* C89 math */
2619 PUSHs(sv_2mortal(newSViv(expvar)));
2631 /* (We already know stack is long enough.) */
2632 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar)))); /* C89 math */
2633 PUSHs(sv_2mortal(newSVnv(intvar)));
2642 PUSHs(sv_2mortal(newSVnv(c99_remquo(x,y,&intvar))));
2643 PUSHs(sv_2mortal(newSVnv(intvar)));
2656 RETVAL = c99_scalbn(x, y);
2676 RETVAL = c99_fma(x, y, z);
2687 RETVAL = c99_nan(s ? s : "");
2688 #elif defined(NV_NAN)
2689 /* XXX if s != NULL, warn about unused argument,
2690 * or implement the nan payload setting. */
2691 /* NVSIZE == 8: the NaN "header" (the exponent) is 0x7FF (the 0x800
2692 * is the sign bit, which should be irrelevant for NaN, so really
2693 * also 0xFFF), leaving 64 - 12 = 52 bits for the NaN payload
2694 * (6.5 bytes, note about infinities below).
2696 * (USE_LONG_DOUBLE and)
2697 * LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN:
2698 * the NaN "header" is still 0x7FF, leaving 80 - 12 = 68 bits
2699 * for the payload (8.5 bytes, note about infinities below).
2701 * doubledouble? aargh. Maybe like doubles, 52 + 52 = 104 bits?
2704 * the NaN "header" is still 0x7FF, leaving 128 - 12 = 116 bits
2705 * for the payload (14.5 bytes, note about infinities below)
2707 * Which ones of the NaNs are 'signaling' and which are 'quiet',
2708 * depends. In the IEEE-754 1985, nothing was specified. But the
2709 * majority of companies decided that the MSB of the mantissa was
2710 * the bit for 'quiet'. (Only PA-RISC and MIPS were different,
2711 * using the MSB as 'signaling'.) The IEEE-754 2008 *recommended*
2712 * (but did not dictate) the MSB as the 'quiet' bit.
2714 * In other words, on most platforms, and for 64-bit doubles:
2715 * [7FF8000000000000, 7FFFFFFFFFFFFFFF] quiet
2716 * [FFF8000000000000, FFFFFFFFFFFFFFFF] quiet
2717 * [7FF0000000000001, 7FF7FFFFFFFFFFFF] signaling
2718 * [FFF0000000000001, FFF7FFFFFFFFFFFF] signaling
2720 * The C99 nan() is supposed to generate *quiet* NaNs.
2722 * Note the asymmetry:
2723 * The 7FF0000000000000 is positive infinity,
2724 * the FFF0000000000000 is negative infinity.
2746 RETVAL = bessel_jn(x, y);
2754 RETVAL = bessel_yn(x, y);
2764 sigaction(sig, optaction, oldaction = 0)
2767 POSIX::SigAction oldaction
2769 #if defined(WIN32) || defined(NETWARE)
2770 RETVAL = not_here("sigaction");
2772 # This code is really grody because we're trying to make the signal
2773 # interface look beautiful, which is hard.
2777 POSIX__SigAction action;
2778 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
2779 struct sigaction act;
2780 struct sigaction oact;
2784 POSIX__SigSet sigset;
2789 croak("Negative signals are not allowed");
2792 if (sig == 0 && SvPOK(ST(0))) {
2793 const char *s = SvPVX_const(ST(0));
2794 int i = whichsig(s);
2796 if (i < 0 && memEQ(s, "SIG", 3))
2797 i = whichsig(s + 3);
2799 if (ckWARN(WARN_SIGNAL))
2800 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2801 "No such signal: SIG%s", s);
2808 if (sig > NSIG) { /* NSIG - 1 is still okay. */
2809 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2810 "No such signal: %d", sig);
2814 sigsvp = hv_fetch(GvHVn(siggv),
2816 strlen(PL_sig_name[sig]),
2819 /* Check optaction and set action */
2820 if(SvTRUE(optaction)) {
2821 if(sv_isa(optaction, "POSIX::SigAction"))
2822 action = (HV*)SvRV(optaction);
2824 croak("action is not of type POSIX::SigAction");
2830 /* sigaction() is supposed to look atomic. In particular, any
2831 * signal handler invoked during a sigaction() call should
2832 * see either the old or the new disposition, and not something
2833 * in between. We use sigprocmask() to make it so.
2836 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
2840 /* Restore signal mask no matter how we exit this block. */
2841 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
2842 SAVEFREESV( osset_sv );
2843 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
2845 RETVAL=-1; /* In case both oldaction and action are 0. */
2847 /* Remember old disposition if desired. */
2849 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
2851 croak("Can't supply an oldaction without a HANDLER");
2852 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
2853 sv_setsv(*svp, *sigsvp);
2856 sv_setpvs(*svp, "DEFAULT");
2858 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
2863 /* Get back the mask. */
2864 svp = hv_fetchs(oldaction, "MASK", TRUE);
2865 if (sv_isa(*svp, "POSIX::SigSet")) {
2866 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2869 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
2873 *sigset = oact.sa_mask;
2875 /* Get back the flags. */
2876 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
2877 sv_setiv(*svp, oact.sa_flags);
2879 /* Get back whether the old handler used safe signals. */
2880 svp = hv_fetchs(oldaction, "SAFE", TRUE);
2882 /* compare incompatible pointers by casting to integer */
2883 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
2887 /* Safe signals use "csighandler", which vectors through the
2888 PL_sighandlerp pointer when it's safe to do so.
2889 (BTW, "csighandler" is very different from "sighandler".) */
2890 svp = hv_fetchs(action, "SAFE", FALSE);
2894 (*svp && SvTRUE(*svp))
2895 ? PL_csighandlerp : PL_sighandlerp
2898 /* Vector new Perl handler through %SIG.
2899 (The core signal handlers read %SIG to dispatch.) */
2900 svp = hv_fetchs(action, "HANDLER", FALSE);
2902 croak("Can't supply an action without a HANDLER");
2903 sv_setsv(*sigsvp, *svp);
2905 /* This call actually calls sigaction() with almost the
2906 right settings, including appropriate interpretation
2907 of DEFAULT and IGNORE. However, why are we doing
2908 this when we're about to do it again just below? XXX */
2909 SvSETMAGIC(*sigsvp);
2911 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
2913 const char *s=SvPVX_const(*svp);
2914 if(strEQ(s,"IGNORE")) {
2915 act.sa_handler = SIG_IGN;
2917 else if(strEQ(s,"DEFAULT")) {
2918 act.sa_handler = SIG_DFL;
2922 /* Set up any desired mask. */
2923 svp = hv_fetchs(action, "MASK", FALSE);
2924 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
2925 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2926 act.sa_mask = *sigset;
2929 sigemptyset(& act.sa_mask);
2931 /* Set up any desired flags. */
2932 svp = hv_fetchs(action, "FLAGS", FALSE);
2933 act.sa_flags = svp ? SvIV(*svp) : 0;
2935 /* Don't worry about cleaning up *sigsvp if this fails,
2936 * because that means we tried to disposition a
2937 * nonblockable signal, in which case *sigsvp is
2938 * essentially meaningless anyway.
2940 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
2955 POSIX::SigSet sigset
2959 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
2966 sigprocmask(how, sigset, oldsigset = 0)
2968 POSIX::SigSet sigset = NO_INIT
2969 POSIX::SigSet oldsigset = NO_INIT
2971 if (! SvOK(ST(1))) {
2973 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
2974 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
2976 croak("sigset is not of type POSIX::SigSet");
2979 if (items < 3 || ! SvOK(ST(2))) {
2981 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
2982 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
2984 croak("oldsigset is not of type POSIX::SigSet");
2997 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
2998 the well known documented POSIX behaviour for a POSIX API.
2999 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
3000 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
3002 RETVAL = dup2(fd1, fd2);
3008 lseek(fd, offset, whence)
3013 Off_t pos = PerlLIO_lseek(fd, offset, whence);
3014 RETVAL = sizeof(Off_t) > sizeof(IV)
3015 ? newSVnv((NV)pos) : newSViv((IV)pos);
3024 if ((incr = nice(incr)) != -1 || errno == 0) {
3026 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
3028 XPUSHs(sv_2mortal(newSViv(incr)));
3035 if (pipe(fds) != -1) {
3037 PUSHs(sv_2mortal(newSViv(fds[0])));
3038 PUSHs(sv_2mortal(newSViv(fds[1])));
3042 read(fd, buffer, nbytes)
3044 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
3048 char * buffer = sv_grow( sv_buffer, nbytes+1 );
3051 SvCUR_set(sv_buffer, RETVAL);
3052 SvPOK_only(sv_buffer);
3053 *SvEND(sv_buffer) = '\0';
3054 SvTAINTED_on(sv_buffer);
3070 tcsetpgrp(fd, pgrp_id)
3079 if (uname(&buf) >= 0) {
3081 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
3082 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
3083 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
3084 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
3085 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
3088 uname((char *) 0); /* A stub to call not_here(). */
3092 write(fd, buffer, nbytes)
3103 RETVAL = newSVpvs("");
3104 SvGROW(RETVAL, L_tmpnam);
3105 /* Yes, we know tmpnam() is bad. So bad that some compilers
3106 * and linkers warn against using it. But it is here for
3107 * completeness. POSIX.pod warns against using it.
3109 * Then again, maybe this should be removed at some point.
3110 * No point in enabling dangerous interfaces. */
3111 if (ckWARN_d(WARN_DEPRECATED)) {
3112 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
3113 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
3114 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Calling POSIX::tmpnam() is deprecated");
3115 (void)hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
3118 len = strlen(tmpnam(SvPV(RETVAL, i)));
3119 SvCUR_set(RETVAL, len);
3132 mbstowcs(s, pwcs, n)
3144 wcstombs(s, pwcs, n)
3166 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3167 num = strtod(str, &unparsed);
3168 PUSHs(sv_2mortal(newSVnv(num)));
3169 if (GIMME_V == G_ARRAY) {
3172 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3174 PUSHs(&PL_sv_undef);
3176 RESTORE_NUMERIC_STANDARD();
3187 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3188 num = strtold(str, &unparsed);
3189 PUSHs(sv_2mortal(newSVnv(num)));
3190 if (GIMME_V == G_ARRAY) {
3193 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3195 PUSHs(&PL_sv_undef);
3197 RESTORE_NUMERIC_STANDARD();
3202 strtol(str, base = 0)
3209 num = strtol(str, &unparsed, base);
3210 #if IVSIZE <= LONGSIZE
3211 if (num < IV_MIN || num > IV_MAX)
3212 PUSHs(sv_2mortal(newSVnv((double)num)));
3215 PUSHs(sv_2mortal(newSViv((IV)num)));
3216 if (GIMME_V == G_ARRAY) {
3219 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3221 PUSHs(&PL_sv_undef);
3225 strtoul(str, base = 0)
3232 PERL_UNUSED_VAR(str);
3233 PERL_UNUSED_VAR(base);
3234 num = strtoul(str, &unparsed, base);
3235 #if IVSIZE <= LONGSIZE
3237 PUSHs(sv_2mortal(newSVnv((double)num)));
3240 PUSHs(sv_2mortal(newSViv((IV)num)));
3241 if (GIMME_V == G_ARRAY) {
3244 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3246 PUSHs(&PL_sv_undef);
3257 char *p = SvPV(src,srclen);
3259 buflen = srclen * 4 + 1;
3260 ST(0) = sv_2mortal(newSV(buflen));
3261 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)buflen);
3262 if (dstlen >= buflen) {
3264 SvGROW(ST(0), dstlen);
3265 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
3268 SvCUR_set(ST(0), dstlen);
3273 mkfifo(filename, mode)
3280 RETVAL = access(filename, mode);
3282 TAINT_PROPER("mkfifo");
3283 RETVAL = mkfifo(filename, mode);
3295 RETVAL = ix == 1 ? close(fd)
3296 : (ix < 1 ? tcdrain(fd) : dup(fd));
3309 RETVAL = ix == 1 ? tcflush(fd, action)
3310 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
3315 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
3331 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
3334 mytm.tm_hour = hour;
3335 mytm.tm_mday = mday;
3337 mytm.tm_year = year;
3338 mytm.tm_wday = wday;
3339 mytm.tm_yday = yday;
3340 mytm.tm_isdst = isdst;
3342 const time_t result = mktime(&mytm);
3343 if (result == (time_t)-1)
3345 else if (result == 0)
3346 sv_setpvn(TARG, "0 but true", 10);
3348 sv_setiv(TARG, (IV)result);
3350 sv_setpv(TARG, asctime(&mytm));
3368 realtime = times( &tms );
3370 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
3371 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
3372 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
3373 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
3374 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
3377 difftime(time1, time2)
3381 #XXX: if $xsubpp::WantOptimize is always the default
3382 # sv_setpv(TARG, ...) could be used rather than
3383 # ST(0) = sv_2mortal(newSVpv(...))
3385 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
3401 /* allowing user-supplied (rather than literal) formats
3402 * is normally frowned upon as a potential security risk;
3403 * but this is part of the API so we have to allow it */
3404 GCC_DIAG_IGNORE(-Wformat-nonliteral);
3405 buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
3407 sv = sv_newmortal();
3409 STRLEN len = strlen(buf);
3410 sv_usepvn_flags(sv, buf, len, SV_HAS_TRAILING_NUL);
3412 || (! is_invariant_string((U8*) buf, len)
3413 && is_utf8_string((U8*) buf, len)
3414 #ifdef USE_LOCALE_TIME
3415 && _is_cur_LC_category_utf8(LC_TIME)
3421 else { /* We can't distinguish between errors and just an empty
3422 * return; in all cases just return an empty string */
3423 SvUPGRADE(sv, SVt_PV);
3424 SvPV_set(sv, (char *) "");
3427 SvLEN_set(sv, 0); /* Won't attempt to free the string when sv
3442 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
3443 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
3449 #ifdef HAS_CTERMID_R
3450 s = (char *) safemalloc((size_t) L_ctermid);
3452 RETVAL = ctermid(s);
3456 #ifdef HAS_CTERMID_R
3465 RETVAL = cuserid(s);
3469 not_here("cuserid");
3480 pathconf(filename, name)
3491 unsigned int seconds
3493 RETVAL = PerlProc_sleep(seconds);
3519 XSprePUSH; PUSHTARG;
3523 lchown(uid, gid, path)
3529 /* yes, the order of arguments is different,
3530 * but consistent with CORE::chown() */
3531 RETVAL = lchown(path, uid, gid);
3533 PERL_UNUSED_VAR(uid);
3534 PERL_UNUSED_VAR(gid);
3535 PERL_UNUSED_VAR(path);
3536 RETVAL = not_here("lchown");