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
280 # define c99_lrint llrintl
282 # define c99_lrint lrintl
284 # if defined(USE_64_BIT_INT) && QUADKIND == QUAD_IS_LONG_LONG
285 # define c99_lround llroundl
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
352 # define isunordered(x, y) (Perl_isnan(x) || Perl_isnan(y))
353 # elif defined(HAS_UNORDERED)
354 # define isunordered(x, y) unordered(x, y)
358 /* XXX these isgreater/isnormal/isunordered macros definitions should
359 * be moved further in the file to be part of the emulations, so that
360 * platforms can e.g. #undef c99_isunordered and have it work like
361 * it does for the other interfaces. */
363 #if !defined(isgreater) && defined(isunordered)
364 # define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
365 # define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
366 # define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
367 # define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
368 # define islessgreater(x, y) (!isunordered((x), (y)) && \
369 ((x) > (y) || (y) > (x)))
372 /* Check both the Configure symbol and the macro-ness (like C99 promises). */
373 #if defined(HAS_FPCLASSIFY) && defined(fpclassify)
374 # define c99_fpclassify fpclassify
376 /* Like isnormal(), the isfinite(), isinf(), and isnan() are also C99
377 and also (sizeof-arg-aware) macros, but they are already well taken
378 care of by Configure et al, and defined in perl.h as
379 Perl_isfinite(), Perl_isinf(), and Perl_isnan(). */
381 # define c99_isnormal isnormal
383 #ifdef isgreater /* canary for all the C99 is*<cmp>* macros. */
384 # define c99_isgreater isgreater
385 # define c99_isgreaterequal isgreaterequal
386 # define c99_isless isless
387 # define c99_islessequal islessequal
388 # define c99_islessgreater islessgreater
389 # define c99_isunordered isunordered
392 /* The Great Wall of Undef where according to the definedness of HAS_FOO symbols
393 * the corresponding c99_foo wrappers are undefined. This list doesn't include
394 * the isfoo() interfaces because they are either type-aware macros, or dealt
395 * separately, already in perl.h */
436 #ifndef HAS_FPCLASSIFY
437 # undef c99_fpclassify
466 #ifndef HAS_NEARBYINT
467 # undef c99_nearbyint
469 #ifndef HAS_NEXTAFTER
470 # undef c99_nextafter
472 #ifndef HAS_NEXTTOWARD
473 # undef c99_nexttoward
475 #ifndef HAS_REMAINDER
476 # undef c99_remainder
502 /* Some APIs exist under Win32 with "underbar" names. */
505 # undef c99_nextafter
506 # define c99_hypot _hypot
507 # define c99_logb _logb
508 # define c99_nextafter _nextafter
510 # define bessel_j0 _j0
511 # define bessel_j1 _j1
512 # define bessel_jn _jn
513 # define bessel_y0 _y0
514 # define bessel_y1 _y1
515 # define bessel_yn _yn
519 /* The Bessel functions: BSD, SVID, XPG4, and POSIX. But not C99. */
520 #if defined(HAS_J0) && !defined(bessel_j0)
521 # if defined(USE_LONG_DOUBLE) && defined(HAS_J0L)
522 # define bessel_j0 j0l
523 # define bessel_j1 j1l
524 # define bessel_jn jnl
525 # define bessel_y0 y0l
526 # define bessel_y1 y1l
527 # define bessel_yn ynl
529 # define bessel_j0 j0
530 # define bessel_j1 j1
531 # define bessel_jn jn
532 # define bessel_y0 y0
533 # define bessel_y1 y1
534 # define bessel_yn yn
538 /* Emulations for missing math APIs.
540 * Keep in mind that the point of many of these functions is that
541 * they, if available, are supposed to give more precise/more
542 * numerically stable results.
544 * See e.g. http://www.johndcook.com/math_h.html
548 static NV my_acosh(NV x)
550 return Perl_log(x + Perl_sqrt(x * x - 1));
552 # define c99_acosh my_acosh
556 static NV my_asinh(NV x)
558 return Perl_log(x + Perl_sqrt(x * x + 1));
560 # define c99_asinh my_asinh
564 static NV my_atanh(NV x)
566 return (Perl_log(1 + x) - Perl_log(1 - x)) / 2;
568 # define c99_atanh my_atanh
572 static NV my_cbrt(NV x)
574 static const NV one_third = (NV)1.0/3;
575 return x >= 0.0 ? Perl_pow(x, one_third) : -Perl_pow(-x, one_third);
577 # define c99_cbrt my_cbrt
581 static NV my_copysign(NV x, NV y)
583 return y >= 0 ? (x < 0 ? -x : x) : (x < 0 ? x : -x);
585 # define c99_copysign my_copysign
588 /* XXX cosh (though c89) */
591 static NV my_erf(NV x)
593 /* http://www.johndcook.com/cpp_erf.html -- public domain */
595 NV a2 = -0.284496736;
597 NV a4 = -1.453152027;
601 int sign = x < 0 ? -1 : 1; /* Save the sign. */
604 /* Abramowitz and Stegun formula 7.1.26 */
605 t = 1.0 / (1.0 + p * x);
606 y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1) * t * Perl_exp(-x*x);
610 # define c99_erf my_erf
614 static NV my_erfc(NV x) {
615 /* This is not necessarily numerically stable, but better than nothing. */
616 return 1.0 - c99_erf(x);
618 # define c99_erfc my_erfc
622 static NV my_exp2(NV x)
624 return Perl_pow((NV)2.0, x);
626 # define c99_exp2 my_exp2
630 static NV my_expm1(NV x)
632 if (PERL_ABS(x) < 1e-5)
633 /* http://www.johndcook.com/cpp_expm1.html -- public domain.
634 * Taylor series, the first four terms (the last term quartic). */
635 /* Probably not enough for long doubles. */
636 return x * (1.0 + x * (1/2.0 + x * (1/6.0 + x/24.0)));
638 return Perl_exp(x) - 1;
640 # define c99_expm1 my_expm1
644 static NV my_fdim(NV x, NV y)
646 return (Perl_isnan(x) || Perl_isnan(y)) ? NV_NAN : (x > y ? x - y : 0);
648 # define c99_fdim my_fdim
652 static NV my_fma(NV x, NV y, NV z)
656 # define c99_fma my_fma
660 static NV my_fmax(NV x, NV y)
663 return Perl_isnan(y) ? NV_NAN : y;
664 } else if (Perl_isnan(y)) {
667 return x > y ? x : y;
669 # define c99_fmax my_fmax
673 static NV my_fmin(NV x, NV y)
676 return Perl_isnan(y) ? NV_NAN : y;
677 } else if (Perl_isnan(y)) {
680 return x < y ? x : y;
682 # define c99_fmin my_fmin
685 #ifndef c99_fpclassify
687 static IV my_fpclassify(NV x)
689 #ifdef Perl_fp_class_inf
690 if (Perl_fp_class_inf(x)) return FP_INFINITE;
691 if (Perl_fp_class_nan(x)) return FP_NAN;
692 if (Perl_fp_class_norm(x)) return FP_NORMAL;
693 if (Perl_fp_class_denorm(x)) return FP_SUBNORMAL;
694 if (Perl_fp_class_zero(x)) return FP_ZERO;
695 # define c99_fpclassify my_fpclassify
703 static NV my_hypot(NV x, NV y)
705 /* http://en.wikipedia.org/wiki/Hypot */
707 x = PERL_ABS(x); /* Take absolute values. */
713 if (x < y) { /* Swap so that y is less. */
719 return x * Perl_sqrt(1.0 + t * t);
721 # define c99_hypot my_hypot
725 static IV my_ilogb(NV x)
727 return (IV)(Perl_log(x) * M_LOG2E);
729 # define c99_ilogb my_ilogb
732 /* tgamma and lgamma emulations based on
733 * http://www.johndcook.com/cpp_gamma.html,
734 * code placed in public domain.
736 * Note that these implementations (neither the johndcook originals
737 * nor these) do NOT set the global signgam variable. This is not
738 * necessarily a bad thing. */
740 /* Note that the tgamma() and lgamma() implementations
741 * here depend on each other. */
744 static NV my_tgamma(NV x);
745 # define c99_tgamma my_tgamma
748 static NV my_lgamma(NV x);
749 # define c99_lgamma my_lgamma
753 static NV my_tgamma(NV x)
755 const NV gamma = 0.577215664901532860606512090; /* Euler's gamma constant. */
756 if (Perl_isnan(x) || x < 0.0)
758 if (x == 0.0 || x == NV_INF)
759 return x == -0.0 ? -NV_INF : NV_INF;
761 /* The function domain is split into three intervals:
762 * (0, 0.001), [0.001, 12), and (12, infinity) */
764 /* First interval: (0, 0.001)
765 * For small values, 1/tgamma(x) has power series x + gamma x^2,
766 * so in this range, 1/tgamma(x) = x + gamma x^2 with error on the order of x^3.
767 * The relative error over this interval is less than 6e-7. */
769 return 1.0 / (x * (1.0 + gamma * x));
771 /* Second interval: [0.001, 12) */
773 double y = x; /* Working copy. */
775 /* Numerator coefficients for approximation over the interval (1,2) */
776 static const NV p[] = {
777 -1.71618513886549492533811E+0,
778 2.47656508055759199108314E+1,
779 -3.79804256470945635097577E+2,
780 6.29331155312818442661052E+2,
781 8.66966202790413211295064E+2,
782 -3.14512729688483675254357E+4,
783 -3.61444134186911729807069E+4,
784 6.64561438202405440627855E+4
786 /* Denominator coefficients for approximation over the interval (1, 2) */
787 static const NV q[] = {
788 -3.08402300119738975254353E+1,
789 3.15350626979604161529144E+2,
790 -1.01515636749021914166146E+3,
791 -3.10777167157231109440444E+3,
792 2.25381184209801510330112E+4,
793 4.75584627752788110767815E+3,
794 -1.34659959864969306392456E+5,
795 -1.15132259675553483497211E+5
806 n = Perl_floor(y) - 1;
810 for (i = 0; i < 8; i++) {
811 num = (num + p[i]) * z;
812 den = den * z + q[i];
814 result = num / den + 1.0;
817 /* Use the identity tgamma(z) = tgamma(z+1)/z
818 * The variable "result" now holds tgamma of the original y + 1
819 * Thus we use y - 1 to get back the original y. */
823 /* Use the identity tgamma(z+n) = z*(z+1)* ... *(z+n-1)*tgamma(z) */
824 for (i = 0; i < n; i++)
831 /* Third interval: [12, +Inf) */
832 #if LDBL_MANT_DIG == 113 /* IEEE quad prec */
842 return Perl_exp(c99_lgamma(x));
847 static NV my_lgamma(NV x)
851 if (x <= 0 || x == NV_INF)
853 if (x == 1.0 || x == 2.0)
856 return Perl_log(PERL_ABS(c99_tgamma(x)));
857 /* Abramowitz and Stegun 6.1.41
858 * Asymptotic series should be good to at least 11 or 12 figures
859 * For error analysis, see Whittiker and Watson
860 * A Course in Modern Analysis (1927), page 252 */
862 static const NV c[8] = {
872 NV z = 1.0 / (x * x);
874 static const NV half_log_of_two_pi =
875 0.91893853320467274178032973640562;
878 for (i = 6; i >= 0; i--) {
883 return (x - 0.5) * Perl_log(x) - x + half_log_of_two_pi + series;
889 static NV my_log1p(NV x)
891 /* http://www.johndcook.com/cpp_log_one_plus_x.html -- public domain.
892 * Taylor series, the first four terms (the last term quartic). */
897 if (PERL_ABS(x) > 1e-4)
898 return Perl_log(1.0 + x);
900 /* Probably not enough for long doubles. */
901 return x * (1.0 + x * (-1/2.0 + x * (1/3.0 - x/4.0)));
903 # define c99_log1p my_log1p
907 static NV my_log2(NV x)
909 return Perl_log(x) * M_LOG2E;
911 # define c99_log2 my_log2
918 static int my_fegetround()
920 #ifdef HAS_FEGETROUND
922 #elif defined(HAS_FPGETROUND)
923 switch (fpgetround()) {
924 case FP_RN: return FE_TONEAREST;
925 case FP_RZ: return FE_TOWARDZERO;
926 case FP_RM: return FE_DOWNWARD;
927 case FP_RP: return FE_UPWARD;
930 #elif defined(FLT_ROUNDS)
931 switch (FLT_ROUNDS) {
932 case 0: return FE_TOWARDZERO;
933 case 1: return FE_TONEAREST;
934 case 2: return FE_UPWARD;
935 case 3: return FE_DOWNWARD;
938 #elif defined(__osf__) /* Tru64 */
939 switch (read_rnd()) {
940 case FP_RND_RN: return FE_TONEAREST;
941 case FP_RND_RZ: return FE_TOWARDZERO;
942 case FP_RND_RM: return FE_DOWNWARD;
943 case FP_RND_RP: return FE_UPWARD;
951 /* Toward closest integer. */
952 #define MY_ROUND_NEAREST(x) ((NV)((IV)((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)))
955 #define MY_ROUND_TRUNC(x) ((NV)((IV)(x)))
957 /* Toward minus infinity. */
958 #define MY_ROUND_DOWN(x) ((NV)((IV)((x) >= 0.0 ? (x) : (x) - 0.5)))
960 /* Toward plus infinity. */
961 #define MY_ROUND_UP(x) ((NV)((IV)((x) >= 0.0 ? (x) + 0.5 : (x))))
963 #if (!defined(c99_nearbyint) || !defined(c99_lrint)) && defined(FE_TONEAREST)
964 static NV my_rint(NV x)
967 switch (my_fegetround()) {
968 case FE_TONEAREST: return MY_ROUND_NEAREST(x);
969 case FE_TOWARDZERO: return MY_ROUND_TRUNC(x);
970 case FE_DOWNWARD: return MY_ROUND_DOWN(x);
971 case FE_UPWARD: return MY_ROUND_UP(x);
972 default: return NV_NAN;
974 #elif defined(HAS_FPGETROUND)
975 switch (fpgetround()) {
976 case FP_RN: return MY_ROUND_NEAREST(x);
977 case FP_RZ: return MY_ROUND_TRUNC(x);
978 case FP_RM: return MY_ROUND_DOWN(x);
979 case FE_RP: return MY_ROUND_UP(x);
980 default: return NV_NAN;
988 /* XXX nearbyint() and rint() are not really identical -- but the difference
989 * is messy: nearbyint is defined NOT to raise FE_INEXACT floating point
990 * exceptions, while rint() is defined to MAYBE raise them. At the moment
991 * Perl is blissfully unaware of such fine detail of floating point. */
992 #ifndef c99_nearbyint
994 # define c99_nearbyrint my_rint
1000 static IV my_lrint(NV x)
1002 return (IV)my_rint(x);
1004 # define c99_lrint my_lrint
1009 static IV my_lround(NV x)
1011 return (IV)MY_ROUND_NEAREST(x);
1013 # define c99_lround my_lround
1021 # ifdef FE_TONEAREST
1022 # define c99_rint my_rint
1027 static NV my_round(NV x)
1029 return MY_ROUND_NEAREST(x);
1031 # define c99_round my_round
1035 # if defined(Perl_ldexp) && FLT_RADIX == 2
1036 static NV my_scalbn(NV x, int y)
1038 return Perl_ldexp(x, y);
1040 # define c99_scalbn my_scalbn
1044 /* XXX sinh (though c89) */
1046 /* tgamma -- see lgamma */
1048 /* XXX tanh (though c89) */
1051 static NV my_trunc(NV x)
1053 return MY_ROUND_TRUNC(x);
1055 # define c99_trunc my_trunc
1058 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
1059 metaconfig for future extension writers. We don't use them in POSIX.
1060 (This is really sneaky :-) --AD
1062 #if defined(I_TERMIOS)
1063 #include <termios.h>
1071 #include <sys/stat.h>
1072 #include <sys/types.h>
1080 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
1081 extern char *tzname[];
1084 #if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
1085 char *tzname[] = { "" , "" };
1089 #if defined(__VMS) && !defined(__POSIX_SOURCE)
1091 # include <utsname.h>
1094 # define mkfifo(a,b) (not_here("mkfifo"),-1)
1096 /* The POSIX notion of ttyname() is better served by getname() under VMS */
1097 static char ttnambuf[64];
1098 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
1101 #if defined (__CYGWIN__)
1102 # define tzname _tzname
1104 #if defined (WIN32) || defined (NETWARE)
1106 # define mkfifo(a,b) not_here("mkfifo")
1107 # define ttyname(a) (char*)not_here("ttyname")
1108 # define sigset_t long
1111 # define mode_t short
1114 # define mode_t short
1116 # define tzset() not_here("tzset")
1118 # ifndef _POSIX_OPEN_MAX
1119 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
1122 # define sigaction(a,b,c) not_here("sigaction")
1123 # define sigpending(a) not_here("sigpending")
1124 # define sigprocmask(a,b,c) not_here("sigprocmask")
1125 # define sigsuspend(a) not_here("sigsuspend")
1126 # define sigemptyset(a) not_here("sigemptyset")
1127 # define sigaddset(a,b) not_here("sigaddset")
1128 # define sigdelset(a,b) not_here("sigdelset")
1129 # define sigfillset(a) not_here("sigfillset")
1130 # define sigismember(a,b) not_here("sigismember")
1134 # define setuid(a) not_here("setuid")
1135 # define setgid(a) not_here("setgid")
1136 #endif /* NETWARE */
1137 # define strtold(s1,s2) not_here("strtold")
1142 # define mkfifo(a,b) not_here("mkfifo")
1143 # else /* !( defined OS2 ) */
1145 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
1148 # endif /* !HAS_MKFIFO */
1153 # include <sys/times.h>
1155 # include <sys/utsname.h>
1157 # include <sys/wait.h>
1161 #endif /* WIN32 || NETWARE */
1165 typedef long SysRetLong;
1166 typedef sigset_t* POSIX__SigSet;
1167 typedef HV* POSIX__SigAction;
1169 typedef struct termios* POSIX__Termios;
1170 #else /* Define termios types to int, and call not_here for the functions.*/
1171 #define POSIX__Termios int
1173 #define tcflag_t int
1175 #define cfgetispeed(x) not_here("cfgetispeed")
1176 #define cfgetospeed(x) not_here("cfgetospeed")
1177 #define tcdrain(x) not_here("tcdrain")
1178 #define tcflush(x,y) not_here("tcflush")
1179 #define tcsendbreak(x,y) not_here("tcsendbreak")
1180 #define cfsetispeed(x,y) not_here("cfsetispeed")
1181 #define cfsetospeed(x,y) not_here("cfsetospeed")
1182 #define ctermid(x) (char *) not_here("ctermid")
1183 #define tcflow(x,y) not_here("tcflow")
1184 #define tcgetattr(x,y) not_here("tcgetattr")
1185 #define tcsetattr(x,y,z) not_here("tcsetattr")
1188 /* Possibly needed prototypes */
1191 double strtod (const char *, char **);
1192 long strtol (const char *, char **, int);
1193 unsigned long strtoul (const char *, char **, int);
1195 long double strtold (const char *, char **);
1200 #ifndef HAS_DIFFTIME
1202 #define difftime(a,b) not_here("difftime")
1205 #ifndef HAS_FPATHCONF
1206 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
1209 #define mktime(a) not_here("mktime")
1212 #define nice(a) not_here("nice")
1214 #ifndef HAS_PATHCONF
1215 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
1218 #define sysconf(n) (SysRetLong) not_here("sysconf")
1220 #ifndef HAS_READLINK
1221 #define readlink(a,b,c) not_here("readlink")
1224 #define setpgid(a,b) not_here("setpgid")
1227 #define setsid() not_here("setsid")
1230 #define strcoll(s1,s2) not_here("strcoll")
1233 #define strtod(s1,s2) not_here("strtod")
1236 #define strtold(s1,s2) not_here("strtold")
1239 #define strtol(s1,s2,b) not_here("strtol")
1242 #define strtoul(s1,s2,b) not_here("strtoul")
1245 #define strxfrm(s1,s2,n) not_here("strxfrm")
1247 #ifndef HAS_TCGETPGRP
1248 #define tcgetpgrp(a) not_here("tcgetpgrp")
1250 #ifndef HAS_TCSETPGRP
1251 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
1255 #define times(a) not_here("times")
1256 #endif /* NETWARE */
1259 #define uname(a) not_here("uname")
1262 #define waitpid(a,b,c) not_here("waitpid")
1267 #define mblen(a,b) not_here("mblen")
1270 #ifndef HAS_MBSTOWCS
1271 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
1274 #define mbtowc(pwc, s, n) not_here("mbtowc")
1276 #ifndef HAS_WCSTOMBS
1277 #define wcstombs(s, pwcs, n) not_here("wcstombs")
1280 #define wctomb(s, wchar) not_here("wcstombs")
1282 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
1283 /* If we don't have these functions, then we wouldn't have gotten a typedef
1284 for wchar_t, the wide character type. Defining wchar_t allows the
1285 functions referencing it to compile. Its actual type is then meaningless,
1286 since without the above functions, all sections using it end up calling
1287 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
1289 #define wchar_t char
1293 #ifndef HAS_LOCALECONV
1294 # define localeconv() not_here("localeconv")
1296 struct lconv_offset {
1301 const struct lconv_offset lconv_strings[] = {
1302 #ifdef USE_LOCALE_NUMERIC
1303 {"decimal_point", STRUCT_OFFSET(struct lconv, decimal_point)},
1304 {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)},
1305 # ifndef NO_LOCALECONV_GROUPING
1306 {"grouping", STRUCT_OFFSET(struct lconv, grouping)},
1309 #ifdef USE_LOCALE_MONETARY
1310 {"int_curr_symbol", STRUCT_OFFSET(struct lconv, int_curr_symbol)},
1311 {"currency_symbol", STRUCT_OFFSET(struct lconv, currency_symbol)},
1312 {"mon_decimal_point", STRUCT_OFFSET(struct lconv, mon_decimal_point)},
1313 # ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1314 {"mon_thousands_sep", STRUCT_OFFSET(struct lconv, mon_thousands_sep)},
1316 # ifndef NO_LOCALECONV_MON_GROUPING
1317 {"mon_grouping", STRUCT_OFFSET(struct lconv, mon_grouping)},
1319 {"positive_sign", STRUCT_OFFSET(struct lconv, positive_sign)},
1320 {"negative_sign", STRUCT_OFFSET(struct lconv, negative_sign)},
1325 #ifdef USE_LOCALE_NUMERIC
1327 /* The Linux man pages say these are the field names for the structure
1328 * components that are LC_NUMERIC; the rest being LC_MONETARY */
1329 # define isLC_NUMERIC_STRING(name) (strcmp(name, "decimal_point") \
1330 || strcmp(name, "thousands_sep") \
1332 /* There should be no harm done \
1333 * checking for this, even if \
1334 * NO_LOCALECONV_GROUPING */ \
1335 || strcmp(name, "grouping"))
1337 # define isLC_NUMERIC_STRING(name) (0)
1340 const struct lconv_offset lconv_integers[] = {
1341 #ifdef USE_LOCALE_MONETARY
1342 {"int_frac_digits", STRUCT_OFFSET(struct lconv, int_frac_digits)},
1343 {"frac_digits", STRUCT_OFFSET(struct lconv, frac_digits)},
1344 {"p_cs_precedes", STRUCT_OFFSET(struct lconv, p_cs_precedes)},
1345 {"p_sep_by_space", STRUCT_OFFSET(struct lconv, p_sep_by_space)},
1346 {"n_cs_precedes", STRUCT_OFFSET(struct lconv, n_cs_precedes)},
1347 {"n_sep_by_space", STRUCT_OFFSET(struct lconv, n_sep_by_space)},
1348 {"p_sign_posn", STRUCT_OFFSET(struct lconv, p_sign_posn)},
1349 {"n_sign_posn", STRUCT_OFFSET(struct lconv, n_sign_posn)},
1350 #ifdef HAS_LC_MONETARY_2008
1351 {"int_p_cs_precedes", STRUCT_OFFSET(struct lconv, int_p_cs_precedes)},
1352 {"int_p_sep_by_space", STRUCT_OFFSET(struct lconv, int_p_sep_by_space)},
1353 {"int_n_cs_precedes", STRUCT_OFFSET(struct lconv, int_n_cs_precedes)},
1354 {"int_n_sep_by_space", STRUCT_OFFSET(struct lconv, int_n_sep_by_space)},
1355 {"int_p_sign_posn", STRUCT_OFFSET(struct lconv, int_p_sign_posn)},
1356 {"int_n_sign_posn", STRUCT_OFFSET(struct lconv, int_n_sign_posn)},
1362 #endif /* HAS_LOCALECONV */
1364 #ifdef HAS_LONG_DOUBLE
1365 # if LONG_DOUBLESIZE > NVSIZE
1366 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
1370 #ifndef HAS_LONG_DOUBLE
1382 /* Background: in most systems the low byte of the wait status
1383 * is the signal (the lowest 7 bits) and the coredump flag is
1384 * the eight bit, and the second lowest byte is the exit status.
1385 * BeOS bucks the trend and has the bytes in different order.
1386 * See beos/beos.c for how the reality is bent even in BeOS
1387 * to follow the traditional. However, to make the POSIX
1388 * wait W*() macros to work in BeOS, we need to unbend the
1389 * reality back in place. --jhi */
1390 /* In actual fact the code below is to blame here. Perl has an internal
1391 * representation of the exit status ($?), which it re-composes from the
1392 * OS's representation using the W*() POSIX macros. The code below
1393 * incorrectly uses the W*() macros on the internal representation,
1394 * which fails for OSs that have a different representation (namely BeOS
1395 * and Haiku). WMUNGE() is a hack that converts the internal
1396 * representation into the OS specific one, so that the W*() macros work
1397 * as expected. The better solution would be not to use the W*() macros
1398 * in the first place, though. -- Ingo Weinhold
1400 #if defined(__HAIKU__)
1401 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
1403 # define WMUNGE(x) (x)
1407 not_here(const char *s)
1409 croak("POSIX::%s not implemented on this architecture", s);
1413 #include "const-c.inc"
1416 restore_sigmask(pTHX_ SV *osset_sv)
1418 /* Fortunately, restoring the signal mask can't fail, because
1419 * there's nothing we can do about it if it does -- we're not
1420 * supposed to return -1 from sigaction unless the disposition
1423 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
1424 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
1428 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
1429 SV *const t = newSVrv(rv, packname);
1430 void *const p = sv_grow(t, size + 1);
1440 * (1) The CRT maintains its own copy of the environment, separate from
1441 * the Win32API copy.
1443 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
1444 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
1447 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
1448 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
1451 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
1452 * calls CRT tzset(), but only the first time it is called, and in turn
1453 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
1454 * local copy of the environment and hence gets the original setting as
1455 * perl never updates the CRT copy when assigning to $ENV{TZ}.
1457 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
1458 * putenv() to update the CRT copy of the environment (if it is different)
1459 * whenever we're about to call tzset().
1461 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
1464 * (a) Each interpreter has its own copy of the environment inside the
1465 * perlhost structure. That allows applications that host multiple
1466 * independent Perl interpreters to isolate environment changes from
1467 * each other. (This is similar to how the perlhost mechanism keeps a
1468 * separate working directory for each Perl interpreter, so that calling
1469 * chdir() will not affect other interpreters.)
1471 * (b) Only the first Perl interpreter instantiated within a process will
1472 * "write through" environment changes to the process environment.
1474 * (c) Even the primary Perl interpreter won't update the CRT copy of the
1475 * the environment, only the Win32API copy (it calls win32_putenv()).
1477 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
1478 * sense to only update the process environment when inside the main
1479 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
1480 * from here so we'll just have to check PL_curinterp instead.
1482 * Therefore, we can simply #undef getenv() and putenv() so that those names
1483 * always refer to the CRT functions, and explicitly call win32_getenv() to
1484 * access perl's %ENV.
1486 * We also #undef malloc() and free() to be sure we are using the CRT
1487 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
1488 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
1489 * when the Perl interpreter is being destroyed so we'd end up with a pointer
1490 * into deallocated memory in environ[] if a program embedding a Perl
1491 * interpreter continues to operate even after the main Perl interpreter has
1494 * Note that we don't free() the malloc()ed memory unless and until we call
1495 * malloc() again ourselves because the CRT putenv() function simply puts its
1496 * pointer argument into the environ[] array (it doesn't make a copy of it)
1497 * so this memory must otherwise be leaked.
1506 fix_win32_tzenv(void)
1508 static char* oldenv = NULL;
1510 const char* perl_tz_env = win32_getenv("TZ");
1511 const char* crt_tz_env = getenv("TZ");
1512 if (perl_tz_env == NULL)
1514 if (crt_tz_env == NULL)
1516 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
1517 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
1518 if (newenv != NULL) {
1519 sprintf(newenv, "TZ=%s", perl_tz_env);
1531 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
1532 * This code is duplicated in the Time-Piece module, so any changes made here
1533 * should be made there too.
1539 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
1540 if (PL_curinterp == aTHX)
1547 typedef int (*isfunc_t)(int);
1548 typedef void (*any_dptr_t)(void *);
1550 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
1552 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
1553 static XSPROTO(is_common)
1558 croak_xs_usage(cv, "charstring");
1563 /*int RETVAL = 0; YYY means uncomment this to return false on an
1564 * empty string input */
1566 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
1567 unsigned char *e = s + len;
1568 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
1570 if (ckWARN_d(WARN_DEPRECATED)) {
1572 /* Warn exactly once for each lexical place this function is
1573 * called. See thread at
1574 * http://markmail.org/thread/jhqcag5njmx7jpyu */
1576 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
1577 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
1578 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
1579 "Calling POSIX::%"HEKf"() is deprecated",
1580 HEKfARG(GvNAME_HEK(CvGV(cv))));
1581 hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
1585 /*if (e > s) { YYY */
1586 for (RETVAL = 1; RETVAL && s < e; s++)
1596 MODULE = POSIX PACKAGE = POSIX
1601 const char *file = __FILE__;
1604 /* silence compiler warning about not_here() defined but not used */
1605 if (0) not_here("");
1607 /* Ensure we get the function, not a macro implementation. Like the C89
1608 standard says we can... */
1610 cv = newXS("POSIX::isalnum", is_common, file);
1611 XSANY.any_dptr = (any_dptr_t) &isalnum;
1613 cv = newXS("POSIX::isalpha", is_common, file);
1614 XSANY.any_dptr = (any_dptr_t) &isalpha;
1616 cv = newXS("POSIX::iscntrl", is_common, file);
1617 XSANY.any_dptr = (any_dptr_t) &iscntrl;
1619 cv = newXS("POSIX::isdigit", is_common, file);
1620 XSANY.any_dptr = (any_dptr_t) &isdigit;
1622 cv = newXS("POSIX::isgraph", is_common, file);
1623 XSANY.any_dptr = (any_dptr_t) &isgraph;
1625 cv = newXS("POSIX::islower", is_common, file);
1626 XSANY.any_dptr = (any_dptr_t) &islower;
1628 cv = newXS("POSIX::isprint", is_common, file);
1629 XSANY.any_dptr = (any_dptr_t) &isprint;
1631 cv = newXS("POSIX::ispunct", is_common, file);
1632 XSANY.any_dptr = (any_dptr_t) &ispunct;
1634 cv = newXS("POSIX::isspace", is_common, file);
1635 XSANY.any_dptr = (any_dptr_t) &isspace;
1637 cv = newXS("POSIX::isupper", is_common, file);
1638 XSANY.any_dptr = (any_dptr_t) &isupper;
1640 cv = newXS("POSIX::isxdigit", is_common, file);
1641 XSANY.any_dptr = (any_dptr_t) &isxdigit;
1644 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
1647 new(packname = "POSIX::SigSet", ...)
1648 const char * packname
1653 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1657 for (i = 1; i < items; i++)
1658 sigaddset(s, SvIV(ST(i)));
1664 POSIX::SigSet sigset
1669 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
1675 POSIX::SigSet sigset
1679 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
1684 sigismember(sigset, sig)
1685 POSIX::SigSet sigset
1688 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
1691 new(packname = "POSIX::Termios", ...)
1692 const char * packname
1696 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1697 sizeof(struct termios), packname);
1698 /* The previous implementation stored a pointer to an uninitialised
1699 struct termios. Seems safer to initialise it, particularly as
1700 this implementation exposes the struct to prying from perl-space.
1702 memset(p, 0, 1 + sizeof(struct termios));
1705 not_here("termios");
1710 getattr(termios_ref, fd = 0)
1711 POSIX::Termios termios_ref
1714 RETVAL = tcgetattr(fd, termios_ref);
1718 # If we define TCSANOW here then both a found and not found constant sub
1719 # are created causing a Constant subroutine TCSANOW redefined warning
1721 # define DEF_SETATTR_ACTION 0
1723 # define DEF_SETATTR_ACTION TCSANOW
1726 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
1727 POSIX::Termios termios_ref
1729 int optional_actions
1731 /* The second argument to the call is mandatory, but we'd like to give
1732 it a useful default. 0 isn't valid on all operating systems - on
1733 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
1734 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
1735 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
1740 getispeed(termios_ref)
1741 POSIX::Termios termios_ref
1745 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
1750 getiflag(termios_ref)
1751 POSIX::Termios termios_ref
1757 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1760 RETVAL = termios_ref->c_iflag;
1763 RETVAL = termios_ref->c_oflag;
1766 RETVAL = termios_ref->c_cflag;
1769 RETVAL = termios_ref->c_lflag;
1772 RETVAL = 0; /* silence compiler warning */
1775 not_here(GvNAME(CvGV(cv)));
1782 getcc(termios_ref, ccix)
1783 POSIX::Termios termios_ref
1786 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1788 croak("Bad getcc subscript");
1789 RETVAL = termios_ref->c_cc[ccix];
1798 setispeed(termios_ref, speed)
1799 POSIX::Termios termios_ref
1805 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
1810 setiflag(termios_ref, flag)
1811 POSIX::Termios termios_ref
1818 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1821 termios_ref->c_iflag = flag;
1824 termios_ref->c_oflag = flag;
1827 termios_ref->c_cflag = flag;
1830 termios_ref->c_lflag = flag;
1834 not_here(GvNAME(CvGV(cv)));
1838 setcc(termios_ref, ccix, cc)
1839 POSIX::Termios termios_ref
1843 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1845 croak("Bad setcc subscript");
1846 termios_ref->c_cc[ccix] = cc;
1852 MODULE = POSIX PACKAGE = POSIX
1854 INCLUDE: const-xs.inc
1860 POSIX::WIFEXITED = 1
1861 POSIX::WIFSIGNALED = 2
1862 POSIX::WIFSTOPPED = 3
1866 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
1867 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
1868 RETVAL = 0; /* Silence compilers that notice this, but don't realise
1869 that not_here() can't return. */
1874 RETVAL = WEXITSTATUS(WMUNGE(status));
1876 not_here("WEXITSTATUS");
1881 RETVAL = WIFEXITED(WMUNGE(status));
1883 not_here("WIFEXITED");
1888 RETVAL = WIFSIGNALED(WMUNGE(status));
1890 not_here("WIFSIGNALED");
1895 RETVAL = WIFSTOPPED(WMUNGE(status));
1897 not_here("WIFSTOPPED");
1902 RETVAL = WSTOPSIG(WMUNGE(status));
1904 not_here("WSTOPSIG");
1909 RETVAL = WTERMSIG(WMUNGE(status));
1911 not_here("WTERMSIG");
1915 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
1921 open(filename, flags = O_RDONLY, mode = 0666)
1926 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1927 TAINT_PROPER("open");
1928 RETVAL = open(filename, flags, mode);
1936 #ifndef HAS_LOCALECONV
1937 localeconv(); /* A stub to call not_here(). */
1939 struct lconv *lcbuf;
1941 /* localeconv() deals with both LC_NUMERIC and LC_MONETARY, but
1942 * LC_MONETARY is already in the correct locale */
1943 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
1946 sv_2mortal((SV*)RETVAL);
1947 if ((lcbuf = localeconv())) {
1948 const struct lconv_offset *strings = lconv_strings;
1949 const struct lconv_offset *integers = lconv_integers;
1950 const char *ptr = (const char *) lcbuf;
1953 /* This string may be controlled by either LC_NUMERIC, or
1956 #if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY)
1957 = _is_cur_LC_category_utf8((isLC_NUMERIC_STRING(strings->name))
1960 #elif defined(USE_LOCALE_NUMERIC)
1961 = _is_cur_LC_category_utf8(LC_NUMERIC);
1962 #elif defined(USE_LOCALE_MONETARY)
1963 = _is_cur_LC_category_utf8(LC_MONETARY);
1968 const char *value = *((const char **)(ptr + strings->offset));
1970 if (value && *value) {
1971 (void) hv_store(RETVAL,
1973 strlen(strings->name),
1974 newSVpvn_utf8(value,
1977 /* We mark it as UTF-8 if a utf8 locale
1978 * and is valid and variant under UTF-8 */
1980 && ! is_invariant_string((U8 *) value, 0)
1981 && is_utf8_string((U8 *) value, 0)),
1984 } while ((++strings)->name);
1987 const char value = *((const char *)(ptr + integers->offset));
1989 if (value != CHAR_MAX)
1990 (void) hv_store(RETVAL, integers->name,
1991 strlen(integers->name), newSViv(value), 0);
1992 } while ((++integers)->name);
1994 RESTORE_NUMERIC_STANDARD();
1995 #endif /* HAS_LOCALECONV */
2000 setlocale(category, locale = 0)
2006 #ifdef USE_LOCALE_NUMERIC
2007 /* A 0 (or NULL) locale means only query what the current one is. We
2008 * have the LC_NUMERIC name saved, because we are normally switched
2009 * into the C locale for it. Switch back so an LC_ALL query will yield
2010 * the correct results; all other categories don't require special
2013 if (category == LC_NUMERIC) {
2014 XSRETURN_PV(PL_numeric_name);
2017 else if (category == LC_ALL) {
2018 SET_NUMERIC_LOCAL();
2023 #ifdef WIN32 /* Use wrapper on Windows */
2024 retval = Perl_my_setlocale(aTHX_ category, locale);
2026 retval = setlocale(category, locale);
2029 /* Should never happen that a query would return an error, but be
2030 * sure and reset to C locale */
2032 SET_NUMERIC_STANDARD();
2037 /* Save retval since subsequent setlocale() calls may overwrite it. */
2038 retval = savepv(retval);
2040 /* For locale == 0, we may have switched to NUMERIC_LOCAL. Switch back
2043 SET_NUMERIC_STANDARD();
2044 XSRETURN_PV(retval);
2048 #ifdef USE_LOCALE_CTYPE
2049 if (category == LC_CTYPE
2051 || category == LC_ALL
2057 if (category == LC_ALL)
2058 newctype = setlocale(LC_CTYPE, NULL);
2062 new_ctype(newctype);
2064 #endif /* USE_LOCALE_CTYPE */
2065 #ifdef USE_LOCALE_COLLATE
2066 if (category == LC_COLLATE
2068 || category == LC_ALL
2074 if (category == LC_ALL)
2075 newcoll = setlocale(LC_COLLATE, NULL);
2079 new_collate(newcoll);
2081 #endif /* USE_LOCALE_COLLATE */
2082 #ifdef USE_LOCALE_NUMERIC
2083 if (category == LC_NUMERIC
2085 || category == LC_ALL
2091 if (category == LC_ALL)
2092 newnum = setlocale(LC_NUMERIC, NULL);
2096 new_numeric(newnum);
2098 #endif /* USE_LOCALE_NUMERIC */
2143 RETVAL = Perl_acos(x); /* C89 math */
2147 RETVAL = c99_acosh(x);
2153 RETVAL = Perl_asin(x); /* C89 math */
2157 RETVAL = c99_asinh(x);
2163 RETVAL = Perl_atan(x); /* C89 math */
2167 RETVAL = c99_atanh(x);
2174 RETVAL = c99_cbrt(x);
2180 RETVAL = Perl_ceil(x); /* C89 math */
2183 RETVAL = Perl_cosh(x); /* C89 math */
2187 RETVAL = c99_erf(x);
2194 RETVAL = c99_erfc(x);
2201 RETVAL = c99_exp2(x);
2208 RETVAL = c99_expm1(x);
2214 RETVAL = Perl_floor(x); /* C89 math */
2218 RETVAL = bessel_j0(x);
2225 RETVAL = bessel_j1(x);
2231 /* XXX Note: the lgamma modifies a global variable (signgam),
2232 * which is evil. Some platforms have lgamma_r, which has
2233 * extra output parameter instead of the global variable. */
2235 RETVAL = c99_lgamma(x);
2241 RETVAL = log10(x); /* C89 math */
2245 RETVAL = c99_log1p(x);
2252 RETVAL = c99_log2(x);
2259 RETVAL = c99_logb(x);
2265 #ifdef c99_nearbyint
2266 RETVAL = c99_nearbyint(x);
2268 not_here("nearbyint");
2273 RETVAL = c99_rint(x);
2280 RETVAL = c99_round(x);
2286 RETVAL = Perl_sinh(x); /* C89 math */
2289 RETVAL = Perl_tan(x); /* C89 math */
2292 RETVAL = Perl_tanh(x); /* C89 math */
2296 RETVAL = c99_tgamma(x);
2303 RETVAL = c99_trunc(x);
2310 RETVAL = bessel_y0(x);
2318 RETVAL = bessel_y1(x);
2329 #ifdef HAS_FEGETROUND
2330 RETVAL = my_fegetround();
2333 not_here("fegetround");
2342 #ifdef HAS_FEGETROUND /* canary for fesetround */
2343 RETVAL = fesetround(x);
2344 #elif defined(HAS_FPGETROUND) /* canary for fpsetround */
2346 case FE_TONEAREST: RETVAL = fpsetround(FP_RN); break;
2347 case FE_TOWARDZERO: RETVAL = fpsetround(FP_RZ); break;
2348 case FE_DOWNWARD: RETVAL = fpsetround(FP_RM); break;
2349 case FE_UPWARD: RETVAL = fpsetround(FP_RP); break;
2350 default: RETVAL = -1; break;
2352 #elif defined(__osf__) /* Tru64 */
2354 case FE_TONEAREST: RETVAL = write_rnd(FP_RND_RN); break;
2355 case FE_TOWARDZERO: RETVAL = write_rnd(FP_RND_RZ); break;
2356 case FE_DOWNWARD: RETVAL = write_rnd(FP_RND_RM); break;
2357 case FE_UPWARD: RETVAL = write_rnd(FP_RND_RP); break;
2358 default: RETVAL = -1; break;
2362 not_here("fesetround");
2383 #ifdef c99_fpclassify
2384 RETVAL = c99_fpclassify(x);
2386 not_here("fpclassify");
2391 RETVAL = c99_ilogb(x);
2397 RETVAL = Perl_isfinite(x);
2400 RETVAL = Perl_isinf(x);
2403 RETVAL = Perl_isnan(x);
2407 RETVAL = c99_isnormal(x);
2409 not_here("isnormal");
2414 RETVAL = c99_lrint(x);
2421 RETVAL = c99_lround(x);
2429 RETVAL = Perl_signbit(x);
2431 RETVAL = (x < 0) || (x == -0.0);
2462 RETVAL = c99_copysign(x, y);
2464 not_here("copysign");
2469 RETVAL = c99_fdim(x, y);
2476 RETVAL = c99_fmax(x, y);
2483 RETVAL = c99_fmin(x, y);
2489 RETVAL = Perl_fmod(x, y); /* C89 math */
2493 RETVAL = c99_hypot(x, y);
2499 #ifdef c99_isgreater
2500 RETVAL = c99_isgreater(x, y);
2502 not_here("isgreater");
2506 #ifdef c99_isgreaterequal
2507 RETVAL = c99_isgreaterequal(x, y);
2509 not_here("isgreaterequal");
2514 RETVAL = c99_isless(x, y);
2520 #ifdef c99_islessequal
2521 RETVAL = c99_islessequal(x, y);
2523 not_here("islessequal");
2527 #ifdef c99_islessgreater
2528 RETVAL = c99_islessgreater(x, y);
2530 not_here("islessgreater");
2534 #ifdef c99_isunordered
2535 RETVAL = c99_isunordered(x, y);
2537 not_here("isunordered");
2541 #ifdef c99_nextafter
2542 RETVAL = c99_nextafter(x, y);
2544 not_here("nextafter");
2548 #ifdef c99_nexttoward
2549 RETVAL = c99_nexttoward(x, y);
2551 not_here("nexttoward");
2556 #ifdef c99_remainder
2557 RETVAL = c99_remainder(x, y);
2559 not_here("remainder");
2571 /* (We already know stack is long enough.) */
2572 PUSHs(sv_2mortal(newSVnv(Perl_frexp(x,&expvar)))); /* C89 math */
2573 PUSHs(sv_2mortal(newSViv(expvar)));
2585 /* (We already know stack is long enough.) */
2586 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar)))); /* C89 math */
2587 PUSHs(sv_2mortal(newSVnv(intvar)));
2596 PUSHs(sv_2mortal(newSVnv(c99_remquo(x,y,&intvar))));
2597 PUSHs(sv_2mortal(newSVnv(intvar)));
2608 RETVAL = c99_scalbn(x, y);
2623 RETVAL = c99_fma(x, y, z);
2633 RETVAL = c99_nan(s ? s : "");
2634 #elif defined(NV_NAN)
2636 /* XXX if s != NULL, warn about unused argument,
2637 * or implement the nan payload setting. */
2656 RETVAL = bessel_jn(x, y);
2664 RETVAL = bessel_yn(x, y);
2674 sigaction(sig, optaction, oldaction = 0)
2677 POSIX::SigAction oldaction
2679 #if defined(WIN32) || defined(NETWARE)
2680 RETVAL = not_here("sigaction");
2682 # This code is really grody because we're trying to make the signal
2683 # interface look beautiful, which is hard.
2687 POSIX__SigAction action;
2688 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
2689 struct sigaction act;
2690 struct sigaction oact;
2694 POSIX__SigSet sigset;
2699 croak("Negative signals are not allowed");
2702 if (sig == 0 && SvPOK(ST(0))) {
2703 const char *s = SvPVX_const(ST(0));
2704 int i = whichsig(s);
2706 if (i < 0 && memEQ(s, "SIG", 3))
2707 i = whichsig(s + 3);
2709 if (ckWARN(WARN_SIGNAL))
2710 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2711 "No such signal: SIG%s", s);
2718 if (sig > NSIG) { /* NSIG - 1 is still okay. */
2719 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2720 "No such signal: %d", sig);
2724 sigsvp = hv_fetch(GvHVn(siggv),
2726 strlen(PL_sig_name[sig]),
2729 /* Check optaction and set action */
2730 if(SvTRUE(optaction)) {
2731 if(sv_isa(optaction, "POSIX::SigAction"))
2732 action = (HV*)SvRV(optaction);
2734 croak("action is not of type POSIX::SigAction");
2740 /* sigaction() is supposed to look atomic. In particular, any
2741 * signal handler invoked during a sigaction() call should
2742 * see either the old or the new disposition, and not something
2743 * in between. We use sigprocmask() to make it so.
2746 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
2750 /* Restore signal mask no matter how we exit this block. */
2751 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
2752 SAVEFREESV( osset_sv );
2753 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
2755 RETVAL=-1; /* In case both oldaction and action are 0. */
2757 /* Remember old disposition if desired. */
2759 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
2761 croak("Can't supply an oldaction without a HANDLER");
2762 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
2763 sv_setsv(*svp, *sigsvp);
2766 sv_setpvs(*svp, "DEFAULT");
2768 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
2773 /* Get back the mask. */
2774 svp = hv_fetchs(oldaction, "MASK", TRUE);
2775 if (sv_isa(*svp, "POSIX::SigSet")) {
2776 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2779 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
2783 *sigset = oact.sa_mask;
2785 /* Get back the flags. */
2786 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
2787 sv_setiv(*svp, oact.sa_flags);
2789 /* Get back whether the old handler used safe signals. */
2790 svp = hv_fetchs(oldaction, "SAFE", TRUE);
2792 /* compare incompatible pointers by casting to integer */
2793 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
2797 /* Safe signals use "csighandler", which vectors through the
2798 PL_sighandlerp pointer when it's safe to do so.
2799 (BTW, "csighandler" is very different from "sighandler".) */
2800 svp = hv_fetchs(action, "SAFE", FALSE);
2804 (*svp && SvTRUE(*svp))
2805 ? PL_csighandlerp : PL_sighandlerp
2808 /* Vector new Perl handler through %SIG.
2809 (The core signal handlers read %SIG to dispatch.) */
2810 svp = hv_fetchs(action, "HANDLER", FALSE);
2812 croak("Can't supply an action without a HANDLER");
2813 sv_setsv(*sigsvp, *svp);
2815 /* This call actually calls sigaction() with almost the
2816 right settings, including appropriate interpretation
2817 of DEFAULT and IGNORE. However, why are we doing
2818 this when we're about to do it again just below? XXX */
2819 SvSETMAGIC(*sigsvp);
2821 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
2823 const char *s=SvPVX_const(*svp);
2824 if(strEQ(s,"IGNORE")) {
2825 act.sa_handler = SIG_IGN;
2827 else if(strEQ(s,"DEFAULT")) {
2828 act.sa_handler = SIG_DFL;
2832 /* Set up any desired mask. */
2833 svp = hv_fetchs(action, "MASK", FALSE);
2834 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
2835 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2836 act.sa_mask = *sigset;
2839 sigemptyset(& act.sa_mask);
2841 /* Set up any desired flags. */
2842 svp = hv_fetchs(action, "FLAGS", FALSE);
2843 act.sa_flags = svp ? SvIV(*svp) : 0;
2845 /* Don't worry about cleaning up *sigsvp if this fails,
2846 * because that means we tried to disposition a
2847 * nonblockable signal, in which case *sigsvp is
2848 * essentially meaningless anyway.
2850 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
2865 POSIX::SigSet sigset
2869 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
2876 sigprocmask(how, sigset, oldsigset = 0)
2878 POSIX::SigSet sigset = NO_INIT
2879 POSIX::SigSet oldsigset = NO_INIT
2881 if (! SvOK(ST(1))) {
2883 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
2884 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
2886 croak("sigset is not of type POSIX::SigSet");
2889 if (items < 3 || ! SvOK(ST(2))) {
2891 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
2892 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
2894 croak("oldsigset is not of type POSIX::SigSet");
2907 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
2908 the well known documented POSIX behaviour for a POSIX API.
2909 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
2910 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
2912 RETVAL = dup2(fd1, fd2);
2918 lseek(fd, offset, whence)
2923 Off_t pos = PerlLIO_lseek(fd, offset, whence);
2924 RETVAL = sizeof(Off_t) > sizeof(IV)
2925 ? newSVnv((NV)pos) : newSViv((IV)pos);
2934 if ((incr = nice(incr)) != -1 || errno == 0) {
2936 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
2938 XPUSHs(sv_2mortal(newSViv(incr)));
2945 if (pipe(fds) != -1) {
2947 PUSHs(sv_2mortal(newSViv(fds[0])));
2948 PUSHs(sv_2mortal(newSViv(fds[1])));
2952 read(fd, buffer, nbytes)
2954 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
2958 char * buffer = sv_grow( sv_buffer, nbytes+1 );
2961 SvCUR_set(sv_buffer, RETVAL);
2962 SvPOK_only(sv_buffer);
2963 *SvEND(sv_buffer) = '\0';
2964 SvTAINTED_on(sv_buffer);
2980 tcsetpgrp(fd, pgrp_id)
2989 if (uname(&buf) >= 0) {
2991 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
2992 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
2993 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
2994 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
2995 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
2998 uname((char *) 0); /* A stub to call not_here(). */
3002 write(fd, buffer, nbytes)
3013 RETVAL = newSVpvs("");
3014 SvGROW(RETVAL, L_tmpnam);
3015 /* Yes, we know tmpnam() is bad. So bad that some compilers
3016 * and linkers warn against using it. But it is here for
3017 * completeness. POSIX.pod warns against using it.
3019 * Then again, maybe this should be removed at some point.
3020 * No point in enabling dangerous interfaces. */
3021 if (ckWARN_d(WARN_DEPRECATED)) {
3022 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
3023 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
3024 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Calling POSIX::tmpnam() is deprecated");
3025 hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
3028 len = strlen(tmpnam(SvPV(RETVAL, i)));
3029 SvCUR_set(RETVAL, len);
3042 mbstowcs(s, pwcs, n)
3054 wcstombs(s, pwcs, n)
3076 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3077 num = strtod(str, &unparsed);
3078 PUSHs(sv_2mortal(newSVnv(num)));
3079 if (GIMME == G_ARRAY) {
3082 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3084 PUSHs(&PL_sv_undef);
3086 RESTORE_NUMERIC_STANDARD();
3097 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3098 num = strtold(str, &unparsed);
3099 PUSHs(sv_2mortal(newSVnv(num)));
3100 if (GIMME == G_ARRAY) {
3103 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3105 PUSHs(&PL_sv_undef);
3107 RESTORE_NUMERIC_STANDARD();
3112 strtol(str, base = 0)
3119 num = strtol(str, &unparsed, base);
3120 #if IVSIZE <= LONGSIZE
3121 if (num < IV_MIN || num > IV_MAX)
3122 PUSHs(sv_2mortal(newSVnv((double)num)));
3125 PUSHs(sv_2mortal(newSViv((IV)num)));
3126 if (GIMME == G_ARRAY) {
3129 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3131 PUSHs(&PL_sv_undef);
3135 strtoul(str, base = 0)
3142 num = strtoul(str, &unparsed, base);
3143 #if IVSIZE <= LONGSIZE
3145 PUSHs(sv_2mortal(newSVnv((double)num)));
3148 PUSHs(sv_2mortal(newSViv((IV)num)));
3149 if (GIMME == G_ARRAY) {
3152 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3154 PUSHs(&PL_sv_undef);
3165 char *p = SvPV(src,srclen);
3167 buflen = srclen * 4 + 1;
3168 ST(0) = sv_2mortal(newSV(buflen));
3169 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)buflen);
3170 if (dstlen >= buflen) {
3172 SvGROW(ST(0), dstlen);
3173 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
3176 SvCUR_set(ST(0), dstlen);
3181 mkfifo(filename, mode)
3188 RETVAL = access(filename, mode);
3190 TAINT_PROPER("mkfifo");
3191 RETVAL = mkfifo(filename, mode);
3203 RETVAL = ix == 1 ? close(fd)
3204 : (ix < 1 ? tcdrain(fd) : dup(fd));
3217 RETVAL = ix == 1 ? tcflush(fd, action)
3218 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
3223 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
3239 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
3242 mytm.tm_hour = hour;
3243 mytm.tm_mday = mday;
3245 mytm.tm_year = year;
3246 mytm.tm_wday = wday;
3247 mytm.tm_yday = yday;
3248 mytm.tm_isdst = isdst;
3250 const time_t result = mktime(&mytm);
3251 if (result == (time_t)-1)
3253 else if (result == 0)
3254 sv_setpvn(TARG, "0 but true", 10);
3256 sv_setiv(TARG, (IV)result);
3258 sv_setpv(TARG, asctime(&mytm));
3276 realtime = times( &tms );
3278 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
3279 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
3280 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
3281 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
3282 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
3285 difftime(time1, time2)
3289 #XXX: if $xsubpp::WantOptimize is always the default
3290 # sv_setpv(TARG, ...) could be used rather than
3291 # ST(0) = sv_2mortal(newSVpv(...))
3293 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
3309 /* allowing user-supplied (rather than literal) formats
3310 * is normally frowned upon as a potential security risk;
3311 * but this is part of the API so we have to allow it */
3312 GCC_DIAG_IGNORE(-Wformat-nonliteral);
3313 buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
3315 sv = sv_newmortal();
3317 STRLEN len = strlen(buf);
3318 sv_usepvn_flags(sv, buf, len, SV_HAS_TRAILING_NUL);
3320 || (! is_invariant_string((U8*) buf, len)
3321 && is_utf8_string((U8*) buf, len)
3322 #ifdef USE_LOCALE_TIME
3323 && _is_cur_LC_category_utf8(LC_TIME)
3329 else { /* We can't distinguish between errors and just an empty
3330 * return; in all cases just return an empty string */
3331 SvUPGRADE(sv, SVt_PV);
3332 SvPV_set(sv, (char *) "");
3335 SvLEN_set(sv, 0); /* Won't attempt to free the string when sv
3350 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
3351 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
3357 #ifdef HAS_CTERMID_R
3358 s = (char *) safemalloc((size_t) L_ctermid);
3360 RETVAL = ctermid(s);
3364 #ifdef HAS_CTERMID_R
3373 RETVAL = cuserid(s);
3376 not_here("cuserid");
3387 pathconf(filename, name)
3398 unsigned int seconds
3400 RETVAL = PerlProc_sleep(seconds);
3426 XSprePUSH; PUSHTARG;
3430 lchown(uid, gid, path)
3436 /* yes, the order of arguments is different,
3437 * but consistent with CORE::chown() */
3438 RETVAL = lchown(path, uid, gid);
3440 RETVAL = not_here("lchown");