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 = (int)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 #ifndef USE_LONG_DOUBLE
1138 # define strtold(s1,s2) not_here("strtold")
1139 #endif /* USE_LONG_DOUBLE */
1144 # define mkfifo(a,b) not_here("mkfifo")
1145 # else /* !( defined OS2 ) */
1147 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
1150 # endif /* !HAS_MKFIFO */
1155 # include <sys/times.h>
1157 # include <sys/utsname.h>
1159 # include <sys/wait.h>
1163 #endif /* WIN32 || NETWARE */
1167 typedef long SysRetLong;
1168 typedef sigset_t* POSIX__SigSet;
1169 typedef HV* POSIX__SigAction;
1171 typedef struct termios* POSIX__Termios;
1172 #else /* Define termios types to int, and call not_here for the functions.*/
1173 #define POSIX__Termios int
1175 #define tcflag_t int
1177 #define cfgetispeed(x) not_here("cfgetispeed")
1178 #define cfgetospeed(x) not_here("cfgetospeed")
1179 #define tcdrain(x) not_here("tcdrain")
1180 #define tcflush(x,y) not_here("tcflush")
1181 #define tcsendbreak(x,y) not_here("tcsendbreak")
1182 #define cfsetispeed(x,y) not_here("cfsetispeed")
1183 #define cfsetospeed(x,y) not_here("cfsetospeed")
1184 #define ctermid(x) (char *) not_here("ctermid")
1185 #define tcflow(x,y) not_here("tcflow")
1186 #define tcgetattr(x,y) not_here("tcgetattr")
1187 #define tcsetattr(x,y,z) not_here("tcsetattr")
1190 /* Possibly needed prototypes */
1193 double strtod (const char *, char **);
1194 long strtol (const char *, char **, int);
1195 unsigned long strtoul (const char *, char **, int);
1197 long double strtold (const char *, char **);
1202 #ifndef HAS_DIFFTIME
1204 #define difftime(a,b) not_here("difftime")
1207 #ifndef HAS_FPATHCONF
1208 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
1211 #define mktime(a) not_here("mktime")
1214 #define nice(a) not_here("nice")
1216 #ifndef HAS_PATHCONF
1217 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
1220 #define sysconf(n) (SysRetLong) not_here("sysconf")
1222 #ifndef HAS_READLINK
1223 #define readlink(a,b,c) not_here("readlink")
1226 #define setpgid(a,b) not_here("setpgid")
1229 #define setsid() not_here("setsid")
1232 #define strcoll(s1,s2) not_here("strcoll")
1235 #define strtod(s1,s2) not_here("strtod")
1238 #define strtold(s1,s2) not_here("strtold")
1241 #define strtol(s1,s2,b) not_here("strtol")
1244 #define strtoul(s1,s2,b) not_here("strtoul")
1247 #define strxfrm(s1,s2,n) not_here("strxfrm")
1249 #ifndef HAS_TCGETPGRP
1250 #define tcgetpgrp(a) not_here("tcgetpgrp")
1252 #ifndef HAS_TCSETPGRP
1253 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
1257 #define times(a) not_here("times")
1258 #endif /* NETWARE */
1261 #define uname(a) not_here("uname")
1264 #define waitpid(a,b,c) not_here("waitpid")
1269 #define mblen(a,b) not_here("mblen")
1272 #ifndef HAS_MBSTOWCS
1273 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
1276 #define mbtowc(pwc, s, n) not_here("mbtowc")
1278 #ifndef HAS_WCSTOMBS
1279 #define wcstombs(s, pwcs, n) not_here("wcstombs")
1282 #define wctomb(s, wchar) not_here("wcstombs")
1284 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
1285 /* If we don't have these functions, then we wouldn't have gotten a typedef
1286 for wchar_t, the wide character type. Defining wchar_t allows the
1287 functions referencing it to compile. Its actual type is then meaningless,
1288 since without the above functions, all sections using it end up calling
1289 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
1291 #define wchar_t char
1295 #ifndef HAS_LOCALECONV
1296 # define localeconv() not_here("localeconv")
1298 struct lconv_offset {
1303 const struct lconv_offset lconv_strings[] = {
1304 #ifdef USE_LOCALE_NUMERIC
1305 {"decimal_point", STRUCT_OFFSET(struct lconv, decimal_point)},
1306 {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)},
1307 # ifndef NO_LOCALECONV_GROUPING
1308 {"grouping", STRUCT_OFFSET(struct lconv, grouping)},
1311 #ifdef USE_LOCALE_MONETARY
1312 {"int_curr_symbol", STRUCT_OFFSET(struct lconv, int_curr_symbol)},
1313 {"currency_symbol", STRUCT_OFFSET(struct lconv, currency_symbol)},
1314 {"mon_decimal_point", STRUCT_OFFSET(struct lconv, mon_decimal_point)},
1315 # ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1316 {"mon_thousands_sep", STRUCT_OFFSET(struct lconv, mon_thousands_sep)},
1318 # ifndef NO_LOCALECONV_MON_GROUPING
1319 {"mon_grouping", STRUCT_OFFSET(struct lconv, mon_grouping)},
1321 {"positive_sign", STRUCT_OFFSET(struct lconv, positive_sign)},
1322 {"negative_sign", STRUCT_OFFSET(struct lconv, negative_sign)},
1327 #ifdef USE_LOCALE_NUMERIC
1329 /* The Linux man pages say these are the field names for the structure
1330 * components that are LC_NUMERIC; the rest being LC_MONETARY */
1331 # define isLC_NUMERIC_STRING(name) (strcmp(name, "decimal_point") \
1332 || strcmp(name, "thousands_sep") \
1334 /* There should be no harm done \
1335 * checking for this, even if \
1336 * NO_LOCALECONV_GROUPING */ \
1337 || strcmp(name, "grouping"))
1339 # define isLC_NUMERIC_STRING(name) (0)
1342 const struct lconv_offset lconv_integers[] = {
1343 #ifdef USE_LOCALE_MONETARY
1344 {"int_frac_digits", STRUCT_OFFSET(struct lconv, int_frac_digits)},
1345 {"frac_digits", STRUCT_OFFSET(struct lconv, frac_digits)},
1346 {"p_cs_precedes", STRUCT_OFFSET(struct lconv, p_cs_precedes)},
1347 {"p_sep_by_space", STRUCT_OFFSET(struct lconv, p_sep_by_space)},
1348 {"n_cs_precedes", STRUCT_OFFSET(struct lconv, n_cs_precedes)},
1349 {"n_sep_by_space", STRUCT_OFFSET(struct lconv, n_sep_by_space)},
1350 {"p_sign_posn", STRUCT_OFFSET(struct lconv, p_sign_posn)},
1351 {"n_sign_posn", STRUCT_OFFSET(struct lconv, n_sign_posn)},
1352 #ifdef HAS_LC_MONETARY_2008
1353 {"int_p_cs_precedes", STRUCT_OFFSET(struct lconv, int_p_cs_precedes)},
1354 {"int_p_sep_by_space", STRUCT_OFFSET(struct lconv, int_p_sep_by_space)},
1355 {"int_n_cs_precedes", STRUCT_OFFSET(struct lconv, int_n_cs_precedes)},
1356 {"int_n_sep_by_space", STRUCT_OFFSET(struct lconv, int_n_sep_by_space)},
1357 {"int_p_sign_posn", STRUCT_OFFSET(struct lconv, int_p_sign_posn)},
1358 {"int_n_sign_posn", STRUCT_OFFSET(struct lconv, int_n_sign_posn)},
1364 #endif /* HAS_LOCALECONV */
1366 #ifdef HAS_LONG_DOUBLE
1367 # if LONG_DOUBLESIZE > NVSIZE
1368 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
1372 #ifndef HAS_LONG_DOUBLE
1384 /* Background: in most systems the low byte of the wait status
1385 * is the signal (the lowest 7 bits) and the coredump flag is
1386 * the eight bit, and the second lowest byte is the exit status.
1387 * BeOS bucks the trend and has the bytes in different order.
1388 * See beos/beos.c for how the reality is bent even in BeOS
1389 * to follow the traditional. However, to make the POSIX
1390 * wait W*() macros to work in BeOS, we need to unbend the
1391 * reality back in place. --jhi */
1392 /* In actual fact the code below is to blame here. Perl has an internal
1393 * representation of the exit status ($?), which it re-composes from the
1394 * OS's representation using the W*() POSIX macros. The code below
1395 * incorrectly uses the W*() macros on the internal representation,
1396 * which fails for OSs that have a different representation (namely BeOS
1397 * and Haiku). WMUNGE() is a hack that converts the internal
1398 * representation into the OS specific one, so that the W*() macros work
1399 * as expected. The better solution would be not to use the W*() macros
1400 * in the first place, though. -- Ingo Weinhold
1402 #if defined(__HAIKU__)
1403 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
1405 # define WMUNGE(x) (x)
1409 not_here(const char *s)
1411 croak("POSIX::%s not implemented on this architecture", s);
1415 #include "const-c.inc"
1418 restore_sigmask(pTHX_ SV *osset_sv)
1420 /* Fortunately, restoring the signal mask can't fail, because
1421 * there's nothing we can do about it if it does -- we're not
1422 * supposed to return -1 from sigaction unless the disposition
1425 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
1426 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
1430 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
1431 SV *const t = newSVrv(rv, packname);
1432 void *const p = sv_grow(t, size + 1);
1442 * (1) The CRT maintains its own copy of the environment, separate from
1443 * the Win32API copy.
1445 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
1446 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
1449 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
1450 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
1453 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
1454 * calls CRT tzset(), but only the first time it is called, and in turn
1455 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
1456 * local copy of the environment and hence gets the original setting as
1457 * perl never updates the CRT copy when assigning to $ENV{TZ}.
1459 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
1460 * putenv() to update the CRT copy of the environment (if it is different)
1461 * whenever we're about to call tzset().
1463 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
1466 * (a) Each interpreter has its own copy of the environment inside the
1467 * perlhost structure. That allows applications that host multiple
1468 * independent Perl interpreters to isolate environment changes from
1469 * each other. (This is similar to how the perlhost mechanism keeps a
1470 * separate working directory for each Perl interpreter, so that calling
1471 * chdir() will not affect other interpreters.)
1473 * (b) Only the first Perl interpreter instantiated within a process will
1474 * "write through" environment changes to the process environment.
1476 * (c) Even the primary Perl interpreter won't update the CRT copy of the
1477 * the environment, only the Win32API copy (it calls win32_putenv()).
1479 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
1480 * sense to only update the process environment when inside the main
1481 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
1482 * from here so we'll just have to check PL_curinterp instead.
1484 * Therefore, we can simply #undef getenv() and putenv() so that those names
1485 * always refer to the CRT functions, and explicitly call win32_getenv() to
1486 * access perl's %ENV.
1488 * We also #undef malloc() and free() to be sure we are using the CRT
1489 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
1490 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
1491 * when the Perl interpreter is being destroyed so we'd end up with a pointer
1492 * into deallocated memory in environ[] if a program embedding a Perl
1493 * interpreter continues to operate even after the main Perl interpreter has
1496 * Note that we don't free() the malloc()ed memory unless and until we call
1497 * malloc() again ourselves because the CRT putenv() function simply puts its
1498 * pointer argument into the environ[] array (it doesn't make a copy of it)
1499 * so this memory must otherwise be leaked.
1508 fix_win32_tzenv(void)
1510 static char* oldenv = NULL;
1512 const char* perl_tz_env = win32_getenv("TZ");
1513 const char* crt_tz_env = getenv("TZ");
1514 if (perl_tz_env == NULL)
1516 if (crt_tz_env == NULL)
1518 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
1519 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
1520 if (newenv != NULL) {
1521 sprintf(newenv, "TZ=%s", perl_tz_env);
1533 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
1534 * This code is duplicated in the Time-Piece module, so any changes made here
1535 * should be made there too.
1541 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
1542 if (PL_curinterp == aTHX)
1549 typedef int (*isfunc_t)(int);
1550 typedef void (*any_dptr_t)(void *);
1552 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
1554 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
1555 static XSPROTO(is_common)
1560 croak_xs_usage(cv, "charstring");
1565 /*int RETVAL = 0; YYY means uncomment this to return false on an
1566 * empty string input */
1568 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
1569 unsigned char *e = s + len;
1570 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
1572 if (ckWARN_d(WARN_DEPRECATED)) {
1574 /* Warn exactly once for each lexical place this function is
1575 * called. See thread at
1576 * http://markmail.org/thread/jhqcag5njmx7jpyu */
1578 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
1579 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
1580 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
1581 "Calling POSIX::%"HEKf"() is deprecated",
1582 HEKfARG(GvNAME_HEK(CvGV(cv))));
1583 (void)hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
1587 /*if (e > s) { YYY */
1588 for (RETVAL = 1; RETVAL && s < e; s++)
1598 MODULE = POSIX PACKAGE = POSIX
1603 const char *file = __FILE__;
1606 /* silence compiler warning about not_here() defined but not used */
1607 if (0) not_here("");
1609 /* Ensure we get the function, not a macro implementation. Like the C89
1610 standard says we can... */
1612 cv = newXS("POSIX::isalnum", is_common, file);
1613 XSANY.any_dptr = (any_dptr_t) &isalnum;
1615 cv = newXS("POSIX::isalpha", is_common, file);
1616 XSANY.any_dptr = (any_dptr_t) &isalpha;
1618 cv = newXS("POSIX::iscntrl", is_common, file);
1619 XSANY.any_dptr = (any_dptr_t) &iscntrl;
1621 cv = newXS("POSIX::isdigit", is_common, file);
1622 XSANY.any_dptr = (any_dptr_t) &isdigit;
1624 cv = newXS("POSIX::isgraph", is_common, file);
1625 XSANY.any_dptr = (any_dptr_t) &isgraph;
1627 cv = newXS("POSIX::islower", is_common, file);
1628 XSANY.any_dptr = (any_dptr_t) &islower;
1630 cv = newXS("POSIX::isprint", is_common, file);
1631 XSANY.any_dptr = (any_dptr_t) &isprint;
1633 cv = newXS("POSIX::ispunct", is_common, file);
1634 XSANY.any_dptr = (any_dptr_t) &ispunct;
1636 cv = newXS("POSIX::isspace", is_common, file);
1637 XSANY.any_dptr = (any_dptr_t) &isspace;
1639 cv = newXS("POSIX::isupper", is_common, file);
1640 XSANY.any_dptr = (any_dptr_t) &isupper;
1642 cv = newXS("POSIX::isxdigit", is_common, file);
1643 XSANY.any_dptr = (any_dptr_t) &isxdigit;
1646 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
1649 new(packname = "POSIX::SigSet", ...)
1650 const char * packname
1655 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1659 for (i = 1; i < items; i++)
1660 sigaddset(s, SvIV(ST(i)));
1666 POSIX::SigSet sigset
1671 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
1677 POSIX::SigSet sigset
1681 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
1686 sigismember(sigset, sig)
1687 POSIX::SigSet sigset
1690 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
1693 new(packname = "POSIX::Termios", ...)
1694 const char * packname
1698 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1699 sizeof(struct termios), packname);
1700 /* The previous implementation stored a pointer to an uninitialised
1701 struct termios. Seems safer to initialise it, particularly as
1702 this implementation exposes the struct to prying from perl-space.
1704 memset(p, 0, 1 + sizeof(struct termios));
1707 not_here("termios");
1712 getattr(termios_ref, fd = 0)
1713 POSIX::Termios termios_ref
1716 RETVAL = tcgetattr(fd, termios_ref);
1720 # If we define TCSANOW here then both a found and not found constant sub
1721 # are created causing a Constant subroutine TCSANOW redefined warning
1723 # define DEF_SETATTR_ACTION 0
1725 # define DEF_SETATTR_ACTION TCSANOW
1728 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
1729 POSIX::Termios termios_ref
1731 int optional_actions
1733 /* The second argument to the call is mandatory, but we'd like to give
1734 it a useful default. 0 isn't valid on all operating systems - on
1735 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
1736 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
1737 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
1742 getispeed(termios_ref)
1743 POSIX::Termios termios_ref
1747 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
1752 getiflag(termios_ref)
1753 POSIX::Termios termios_ref
1759 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1762 RETVAL = termios_ref->c_iflag;
1765 RETVAL = termios_ref->c_oflag;
1768 RETVAL = termios_ref->c_cflag;
1771 RETVAL = termios_ref->c_lflag;
1774 RETVAL = 0; /* silence compiler warning */
1777 not_here(GvNAME(CvGV(cv)));
1784 getcc(termios_ref, ccix)
1785 POSIX::Termios termios_ref
1788 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1790 croak("Bad getcc subscript");
1791 RETVAL = termios_ref->c_cc[ccix];
1800 setispeed(termios_ref, speed)
1801 POSIX::Termios termios_ref
1807 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
1812 setiflag(termios_ref, flag)
1813 POSIX::Termios termios_ref
1820 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1823 termios_ref->c_iflag = flag;
1826 termios_ref->c_oflag = flag;
1829 termios_ref->c_cflag = flag;
1832 termios_ref->c_lflag = flag;
1836 not_here(GvNAME(CvGV(cv)));
1840 setcc(termios_ref, ccix, cc)
1841 POSIX::Termios termios_ref
1845 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1847 croak("Bad setcc subscript");
1848 termios_ref->c_cc[ccix] = cc;
1854 MODULE = POSIX PACKAGE = POSIX
1856 INCLUDE: const-xs.inc
1862 POSIX::WIFEXITED = 1
1863 POSIX::WIFSIGNALED = 2
1864 POSIX::WIFSTOPPED = 3
1868 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
1869 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
1870 RETVAL = 0; /* Silence compilers that notice this, but don't realise
1871 that not_here() can't return. */
1876 RETVAL = WEXITSTATUS(WMUNGE(status));
1878 not_here("WEXITSTATUS");
1883 RETVAL = WIFEXITED(WMUNGE(status));
1885 not_here("WIFEXITED");
1890 RETVAL = WIFSIGNALED(WMUNGE(status));
1892 not_here("WIFSIGNALED");
1897 RETVAL = WIFSTOPPED(WMUNGE(status));
1899 not_here("WIFSTOPPED");
1904 RETVAL = WSTOPSIG(WMUNGE(status));
1906 not_here("WSTOPSIG");
1911 RETVAL = WTERMSIG(WMUNGE(status));
1913 not_here("WTERMSIG");
1917 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
1923 open(filename, flags = O_RDONLY, mode = 0666)
1928 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1929 TAINT_PROPER("open");
1930 RETVAL = open(filename, flags, mode);
1938 #ifndef HAS_LOCALECONV
1939 localeconv(); /* A stub to call not_here(). */
1941 struct lconv *lcbuf;
1943 /* localeconv() deals with both LC_NUMERIC and LC_MONETARY, but
1944 * LC_MONETARY is already in the correct locale */
1945 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
1948 sv_2mortal((SV*)RETVAL);
1949 if ((lcbuf = localeconv())) {
1950 const struct lconv_offset *strings = lconv_strings;
1951 const struct lconv_offset *integers = lconv_integers;
1952 const char *ptr = (const char *) lcbuf;
1955 /* This string may be controlled by either LC_NUMERIC, or
1958 #if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY)
1959 = _is_cur_LC_category_utf8((isLC_NUMERIC_STRING(strings->name))
1962 #elif defined(USE_LOCALE_NUMERIC)
1963 = _is_cur_LC_category_utf8(LC_NUMERIC);
1964 #elif defined(USE_LOCALE_MONETARY)
1965 = _is_cur_LC_category_utf8(LC_MONETARY);
1970 const char *value = *((const char **)(ptr + strings->offset));
1972 if (value && *value) {
1973 (void) hv_store(RETVAL,
1975 strlen(strings->name),
1976 newSVpvn_utf8(value,
1979 /* We mark it as UTF-8 if a utf8 locale
1980 * and is valid and variant under UTF-8 */
1982 && ! is_invariant_string((U8 *) value, 0)
1983 && is_utf8_string((U8 *) value, 0)),
1986 } while ((++strings)->name);
1989 const char value = *((const char *)(ptr + integers->offset));
1991 if (value != CHAR_MAX)
1992 (void) hv_store(RETVAL, integers->name,
1993 strlen(integers->name), newSViv(value), 0);
1994 } while ((++integers)->name);
1996 RESTORE_NUMERIC_STANDARD();
1997 #endif /* HAS_LOCALECONV */
2002 setlocale(category, locale = 0)
2008 #ifdef USE_LOCALE_NUMERIC
2009 /* A 0 (or NULL) locale means only query what the current one is. We
2010 * have the LC_NUMERIC name saved, because we are normally switched
2011 * into the C locale for it. Switch back so an LC_ALL query will yield
2012 * the correct results; all other categories don't require special
2015 if (category == LC_NUMERIC) {
2016 XSRETURN_PV(PL_numeric_name);
2019 else if (category == LC_ALL) {
2020 SET_NUMERIC_LOCAL();
2025 #ifdef WIN32 /* Use wrapper on Windows */
2026 retval = Perl_my_setlocale(aTHX_ category, locale);
2028 retval = setlocale(category, locale);
2031 /* Should never happen that a query would return an error, but be
2032 * sure and reset to C locale */
2034 SET_NUMERIC_STANDARD();
2039 /* Save retval since subsequent setlocale() calls may overwrite it. */
2040 retval = savepv(retval);
2042 /* For locale == 0, we may have switched to NUMERIC_LOCAL. Switch back
2045 SET_NUMERIC_STANDARD();
2046 XSRETURN_PV(retval);
2050 #ifdef USE_LOCALE_CTYPE
2051 if (category == LC_CTYPE
2053 || category == LC_ALL
2059 if (category == LC_ALL)
2060 newctype = setlocale(LC_CTYPE, NULL);
2064 new_ctype(newctype);
2066 #endif /* USE_LOCALE_CTYPE */
2067 #ifdef USE_LOCALE_COLLATE
2068 if (category == LC_COLLATE
2070 || category == LC_ALL
2076 if (category == LC_ALL)
2077 newcoll = setlocale(LC_COLLATE, NULL);
2081 new_collate(newcoll);
2083 #endif /* USE_LOCALE_COLLATE */
2084 #ifdef USE_LOCALE_NUMERIC
2085 if (category == LC_NUMERIC
2087 || category == LC_ALL
2093 if (category == LC_ALL)
2094 newnum = setlocale(LC_NUMERIC, NULL);
2098 new_numeric(newnum);
2100 #endif /* USE_LOCALE_NUMERIC */
2146 RETVAL = Perl_acos(x); /* C89 math */
2150 RETVAL = c99_acosh(x);
2156 RETVAL = Perl_asin(x); /* C89 math */
2160 RETVAL = c99_asinh(x);
2166 RETVAL = Perl_atan(x); /* C89 math */
2170 RETVAL = c99_atanh(x);
2177 RETVAL = c99_cbrt(x);
2183 RETVAL = Perl_ceil(x); /* C89 math */
2186 RETVAL = Perl_cosh(x); /* C89 math */
2190 RETVAL = c99_erf(x);
2197 RETVAL = c99_erfc(x);
2204 RETVAL = c99_exp2(x);
2211 RETVAL = c99_expm1(x);
2217 RETVAL = Perl_floor(x); /* C89 math */
2221 RETVAL = bessel_j0(x);
2228 RETVAL = bessel_j1(x);
2234 /* XXX Note: the lgamma modifies a global variable (signgam),
2235 * which is evil. Some platforms have lgamma_r, which has
2236 * extra output parameter instead of the global variable. */
2238 RETVAL = c99_lgamma(x);
2244 RETVAL = log10(x); /* C89 math */
2248 RETVAL = c99_log1p(x);
2255 RETVAL = c99_log2(x);
2262 RETVAL = c99_logb(x);
2268 #ifdef c99_nearbyint
2269 RETVAL = c99_nearbyint(x);
2271 not_here("nearbyint");
2276 RETVAL = c99_rint(x);
2283 RETVAL = c99_round(x);
2289 RETVAL = Perl_sinh(x); /* C89 math */
2292 RETVAL = Perl_tan(x); /* C89 math */
2295 RETVAL = Perl_tanh(x); /* C89 math */
2299 RETVAL = c99_tgamma(x);
2306 RETVAL = c99_trunc(x);
2313 RETVAL = bessel_y0(x);
2321 RETVAL = bessel_y1(x);
2332 #ifdef HAS_FEGETROUND
2333 RETVAL = my_fegetround();
2336 not_here("fegetround");
2345 #ifdef HAS_FEGETROUND /* canary for fesetround */
2346 RETVAL = fesetround(x);
2347 #elif defined(HAS_FPGETROUND) /* canary for fpsetround */
2349 case FE_TONEAREST: RETVAL = fpsetround(FP_RN); break;
2350 case FE_TOWARDZERO: RETVAL = fpsetround(FP_RZ); break;
2351 case FE_DOWNWARD: RETVAL = fpsetround(FP_RM); break;
2352 case FE_UPWARD: RETVAL = fpsetround(FP_RP); break;
2353 default: RETVAL = -1; break;
2355 #elif defined(__osf__) /* Tru64 */
2357 case FE_TONEAREST: RETVAL = write_rnd(FP_RND_RN); break;
2358 case FE_TOWARDZERO: RETVAL = write_rnd(FP_RND_RZ); break;
2359 case FE_DOWNWARD: RETVAL = write_rnd(FP_RND_RM); break;
2360 case FE_UPWARD: RETVAL = write_rnd(FP_RND_RP); break;
2361 default: RETVAL = -1; break;
2366 not_here("fesetround");
2388 #ifdef c99_fpclassify
2389 RETVAL = c99_fpclassify(x);
2391 not_here("fpclassify");
2396 RETVAL = c99_ilogb(x);
2402 RETVAL = Perl_isfinite(x);
2405 RETVAL = Perl_isinf(x);
2408 RETVAL = Perl_isnan(x);
2412 RETVAL = c99_isnormal(x);
2414 not_here("isnormal");
2419 RETVAL = c99_lrint(x);
2426 RETVAL = c99_lround(x);
2434 RETVAL = Perl_signbit(x);
2436 RETVAL = (x < 0) || (x == -0.0);
2469 RETVAL = c99_copysign(x, y);
2471 not_here("copysign");
2476 RETVAL = c99_fdim(x, y);
2483 RETVAL = c99_fmax(x, y);
2490 RETVAL = c99_fmin(x, y);
2496 RETVAL = Perl_fmod(x, y); /* C89 math */
2500 RETVAL = c99_hypot(x, y);
2506 #ifdef c99_isgreater
2507 RETVAL = c99_isgreater(x, y);
2509 not_here("isgreater");
2513 #ifdef c99_isgreaterequal
2514 RETVAL = c99_isgreaterequal(x, y);
2516 not_here("isgreaterequal");
2521 RETVAL = c99_isless(x, y);
2527 #ifdef c99_islessequal
2528 RETVAL = c99_islessequal(x, y);
2530 not_here("islessequal");
2534 #ifdef c99_islessgreater
2535 RETVAL = c99_islessgreater(x, y);
2537 not_here("islessgreater");
2541 #ifdef c99_isunordered
2542 RETVAL = c99_isunordered(x, y);
2544 not_here("isunordered");
2548 #ifdef c99_nextafter
2549 RETVAL = c99_nextafter(x, y);
2551 not_here("nextafter");
2555 #ifdef c99_nexttoward
2556 RETVAL = c99_nexttoward(x, y);
2558 not_here("nexttoward");
2563 #ifdef c99_remainder
2564 RETVAL = c99_remainder(x, y);
2566 not_here("remainder");
2578 /* (We already know stack is long enough.) */
2579 PUSHs(sv_2mortal(newSVnv(Perl_frexp(x,&expvar)))); /* C89 math */
2580 PUSHs(sv_2mortal(newSViv(expvar)));
2592 /* (We already know stack is long enough.) */
2593 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar)))); /* C89 math */
2594 PUSHs(sv_2mortal(newSVnv(intvar)));
2603 PUSHs(sv_2mortal(newSVnv(c99_remquo(x,y,&intvar))));
2604 PUSHs(sv_2mortal(newSVnv(intvar)));
2617 RETVAL = c99_scalbn(x, y);
2637 RETVAL = c99_fma(x, y, z);
2648 RETVAL = c99_nan(s ? s : "");
2649 #elif defined(NV_NAN)
2650 /* XXX if s != NULL, warn about unused argument,
2651 * or implement the nan payload setting. */
2672 RETVAL = bessel_jn(x, y);
2680 RETVAL = bessel_yn(x, y);
2690 sigaction(sig, optaction, oldaction = 0)
2693 POSIX::SigAction oldaction
2695 #if defined(WIN32) || defined(NETWARE)
2696 RETVAL = not_here("sigaction");
2698 # This code is really grody because we're trying to make the signal
2699 # interface look beautiful, which is hard.
2703 POSIX__SigAction action;
2704 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
2705 struct sigaction act;
2706 struct sigaction oact;
2710 POSIX__SigSet sigset;
2715 croak("Negative signals are not allowed");
2718 if (sig == 0 && SvPOK(ST(0))) {
2719 const char *s = SvPVX_const(ST(0));
2720 int i = whichsig(s);
2722 if (i < 0 && memEQ(s, "SIG", 3))
2723 i = whichsig(s + 3);
2725 if (ckWARN(WARN_SIGNAL))
2726 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2727 "No such signal: SIG%s", s);
2734 if (sig > NSIG) { /* NSIG - 1 is still okay. */
2735 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2736 "No such signal: %d", sig);
2740 sigsvp = hv_fetch(GvHVn(siggv),
2742 strlen(PL_sig_name[sig]),
2745 /* Check optaction and set action */
2746 if(SvTRUE(optaction)) {
2747 if(sv_isa(optaction, "POSIX::SigAction"))
2748 action = (HV*)SvRV(optaction);
2750 croak("action is not of type POSIX::SigAction");
2756 /* sigaction() is supposed to look atomic. In particular, any
2757 * signal handler invoked during a sigaction() call should
2758 * see either the old or the new disposition, and not something
2759 * in between. We use sigprocmask() to make it so.
2762 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
2766 /* Restore signal mask no matter how we exit this block. */
2767 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
2768 SAVEFREESV( osset_sv );
2769 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
2771 RETVAL=-1; /* In case both oldaction and action are 0. */
2773 /* Remember old disposition if desired. */
2775 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
2777 croak("Can't supply an oldaction without a HANDLER");
2778 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
2779 sv_setsv(*svp, *sigsvp);
2782 sv_setpvs(*svp, "DEFAULT");
2784 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
2789 /* Get back the mask. */
2790 svp = hv_fetchs(oldaction, "MASK", TRUE);
2791 if (sv_isa(*svp, "POSIX::SigSet")) {
2792 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2795 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
2799 *sigset = oact.sa_mask;
2801 /* Get back the flags. */
2802 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
2803 sv_setiv(*svp, oact.sa_flags);
2805 /* Get back whether the old handler used safe signals. */
2806 svp = hv_fetchs(oldaction, "SAFE", TRUE);
2808 /* compare incompatible pointers by casting to integer */
2809 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
2813 /* Safe signals use "csighandler", which vectors through the
2814 PL_sighandlerp pointer when it's safe to do so.
2815 (BTW, "csighandler" is very different from "sighandler".) */
2816 svp = hv_fetchs(action, "SAFE", FALSE);
2820 (*svp && SvTRUE(*svp))
2821 ? PL_csighandlerp : PL_sighandlerp
2824 /* Vector new Perl handler through %SIG.
2825 (The core signal handlers read %SIG to dispatch.) */
2826 svp = hv_fetchs(action, "HANDLER", FALSE);
2828 croak("Can't supply an action without a HANDLER");
2829 sv_setsv(*sigsvp, *svp);
2831 /* This call actually calls sigaction() with almost the
2832 right settings, including appropriate interpretation
2833 of DEFAULT and IGNORE. However, why are we doing
2834 this when we're about to do it again just below? XXX */
2835 SvSETMAGIC(*sigsvp);
2837 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
2839 const char *s=SvPVX_const(*svp);
2840 if(strEQ(s,"IGNORE")) {
2841 act.sa_handler = SIG_IGN;
2843 else if(strEQ(s,"DEFAULT")) {
2844 act.sa_handler = SIG_DFL;
2848 /* Set up any desired mask. */
2849 svp = hv_fetchs(action, "MASK", FALSE);
2850 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
2851 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2852 act.sa_mask = *sigset;
2855 sigemptyset(& act.sa_mask);
2857 /* Set up any desired flags. */
2858 svp = hv_fetchs(action, "FLAGS", FALSE);
2859 act.sa_flags = svp ? SvIV(*svp) : 0;
2861 /* Don't worry about cleaning up *sigsvp if this fails,
2862 * because that means we tried to disposition a
2863 * nonblockable signal, in which case *sigsvp is
2864 * essentially meaningless anyway.
2866 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
2881 POSIX::SigSet sigset
2885 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
2892 sigprocmask(how, sigset, oldsigset = 0)
2894 POSIX::SigSet sigset = NO_INIT
2895 POSIX::SigSet oldsigset = NO_INIT
2897 if (! SvOK(ST(1))) {
2899 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
2900 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
2902 croak("sigset is not of type POSIX::SigSet");
2905 if (items < 3 || ! SvOK(ST(2))) {
2907 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
2908 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
2910 croak("oldsigset is not of type POSIX::SigSet");
2923 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
2924 the well known documented POSIX behaviour for a POSIX API.
2925 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
2926 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
2928 RETVAL = dup2(fd1, fd2);
2934 lseek(fd, offset, whence)
2939 Off_t pos = PerlLIO_lseek(fd, offset, whence);
2940 RETVAL = sizeof(Off_t) > sizeof(IV)
2941 ? newSVnv((NV)pos) : newSViv((IV)pos);
2950 if ((incr = nice(incr)) != -1 || errno == 0) {
2952 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
2954 XPUSHs(sv_2mortal(newSViv(incr)));
2961 if (pipe(fds) != -1) {
2963 PUSHs(sv_2mortal(newSViv(fds[0])));
2964 PUSHs(sv_2mortal(newSViv(fds[1])));
2968 read(fd, buffer, nbytes)
2970 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
2974 char * buffer = sv_grow( sv_buffer, nbytes+1 );
2977 SvCUR_set(sv_buffer, RETVAL);
2978 SvPOK_only(sv_buffer);
2979 *SvEND(sv_buffer) = '\0';
2980 SvTAINTED_on(sv_buffer);
2996 tcsetpgrp(fd, pgrp_id)
3005 if (uname(&buf) >= 0) {
3007 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
3008 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
3009 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
3010 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
3011 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
3014 uname((char *) 0); /* A stub to call not_here(). */
3018 write(fd, buffer, nbytes)
3029 RETVAL = newSVpvs("");
3030 SvGROW(RETVAL, L_tmpnam);
3031 /* Yes, we know tmpnam() is bad. So bad that some compilers
3032 * and linkers warn against using it. But it is here for
3033 * completeness. POSIX.pod warns against using it.
3035 * Then again, maybe this should be removed at some point.
3036 * No point in enabling dangerous interfaces. */
3037 if (ckWARN_d(WARN_DEPRECATED)) {
3038 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
3039 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
3040 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Calling POSIX::tmpnam() is deprecated");
3041 (void)hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
3044 len = strlen(tmpnam(SvPV(RETVAL, i)));
3045 SvCUR_set(RETVAL, len);
3058 mbstowcs(s, pwcs, n)
3070 wcstombs(s, pwcs, n)
3092 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3093 num = strtod(str, &unparsed);
3094 PUSHs(sv_2mortal(newSVnv(num)));
3095 if (GIMME == G_ARRAY) {
3098 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3100 PUSHs(&PL_sv_undef);
3102 RESTORE_NUMERIC_STANDARD();
3113 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3114 num = strtold(str, &unparsed);
3115 PUSHs(sv_2mortal(newSVnv(num)));
3116 if (GIMME == G_ARRAY) {
3119 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3121 PUSHs(&PL_sv_undef);
3123 RESTORE_NUMERIC_STANDARD();
3128 strtol(str, base = 0)
3135 num = strtol(str, &unparsed, base);
3136 #if IVSIZE <= LONGSIZE
3137 if (num < IV_MIN || num > IV_MAX)
3138 PUSHs(sv_2mortal(newSVnv((double)num)));
3141 PUSHs(sv_2mortal(newSViv((IV)num)));
3142 if (GIMME == G_ARRAY) {
3145 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3147 PUSHs(&PL_sv_undef);
3151 strtoul(str, base = 0)
3158 num = strtoul(str, &unparsed, base);
3159 #if IVSIZE <= LONGSIZE
3161 PUSHs(sv_2mortal(newSVnv((double)num)));
3164 PUSHs(sv_2mortal(newSViv((IV)num)));
3165 if (GIMME == G_ARRAY) {
3168 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3170 PUSHs(&PL_sv_undef);
3181 char *p = SvPV(src,srclen);
3183 buflen = srclen * 4 + 1;
3184 ST(0) = sv_2mortal(newSV(buflen));
3185 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)buflen);
3186 if (dstlen >= buflen) {
3188 SvGROW(ST(0), dstlen);
3189 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
3192 SvCUR_set(ST(0), dstlen);
3197 mkfifo(filename, mode)
3204 RETVAL = access(filename, mode);
3206 TAINT_PROPER("mkfifo");
3207 RETVAL = mkfifo(filename, mode);
3219 RETVAL = ix == 1 ? close(fd)
3220 : (ix < 1 ? tcdrain(fd) : dup(fd));
3233 RETVAL = ix == 1 ? tcflush(fd, action)
3234 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
3239 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
3255 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
3258 mytm.tm_hour = hour;
3259 mytm.tm_mday = mday;
3261 mytm.tm_year = year;
3262 mytm.tm_wday = wday;
3263 mytm.tm_yday = yday;
3264 mytm.tm_isdst = isdst;
3266 const time_t result = mktime(&mytm);
3267 if (result == (time_t)-1)
3269 else if (result == 0)
3270 sv_setpvn(TARG, "0 but true", 10);
3272 sv_setiv(TARG, (IV)result);
3274 sv_setpv(TARG, asctime(&mytm));
3292 realtime = times( &tms );
3294 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
3295 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
3296 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
3297 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
3298 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
3301 difftime(time1, time2)
3305 #XXX: if $xsubpp::WantOptimize is always the default
3306 # sv_setpv(TARG, ...) could be used rather than
3307 # ST(0) = sv_2mortal(newSVpv(...))
3309 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
3325 /* allowing user-supplied (rather than literal) formats
3326 * is normally frowned upon as a potential security risk;
3327 * but this is part of the API so we have to allow it */
3328 GCC_DIAG_IGNORE(-Wformat-nonliteral);
3329 buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
3331 sv = sv_newmortal();
3333 STRLEN len = strlen(buf);
3334 sv_usepvn_flags(sv, buf, len, SV_HAS_TRAILING_NUL);
3336 || (! is_invariant_string((U8*) buf, len)
3337 && is_utf8_string((U8*) buf, len)
3338 #ifdef USE_LOCALE_TIME
3339 && _is_cur_LC_category_utf8(LC_TIME)
3345 else { /* We can't distinguish between errors and just an empty
3346 * return; in all cases just return an empty string */
3347 SvUPGRADE(sv, SVt_PV);
3348 SvPV_set(sv, (char *) "");
3351 SvLEN_set(sv, 0); /* Won't attempt to free the string when sv
3366 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
3367 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
3373 #ifdef HAS_CTERMID_R
3374 s = (char *) safemalloc((size_t) L_ctermid);
3376 RETVAL = ctermid(s);
3380 #ifdef HAS_CTERMID_R
3389 RETVAL = cuserid(s);
3393 not_here("cuserid");
3404 pathconf(filename, name)
3415 unsigned int seconds
3417 RETVAL = PerlProc_sleep(seconds);
3443 XSprePUSH; PUSHTARG;
3447 lchown(uid, gid, path)
3453 /* yes, the order of arguments is different,
3454 * but consistent with CORE::chown() */
3455 RETVAL = lchown(path, uid, gid);
3457 PERL_UNUSED_VAR(uid);
3458 PERL_UNUSED_VAR(gid);
3459 PERL_UNUSED_VAR(path);
3460 RETVAL = not_here("lchown");