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 http://www.johndcook.com/cpp_gamma.html,
733 * code placed in public domain.
735 * Note that these implementations (neither the johndcook originals
736 * nor these) do NOT set the global signgam variable. This is not
737 * necessarily a bad thing. */
739 /* Note that tgamma() and lgamma() depend on each other. */
740 #if !defined(c99_tgamma) || !defined(c99_lgamma)
741 static NV my_tgamma(NV x);
742 static NV my_lgamma(NV x);
745 #if !defined(c99_tgamma) || !defined(c99_lgamma)
746 static NV my_tgamma(NV x)
748 const NV gamma = 0.577215664901532860606512090; /* Euler's gamma constant. */
749 if (Perl_isnan(x) || x < 0.0)
751 if (x == 0.0 || x == NV_INF)
752 return x == -0.0 ? -NV_INF : NV_INF;
754 /* The function domain is split into three intervals:
755 * (0, 0.001), [0.001, 12), and (12, infinity) */
757 /* First interval: (0, 0.001)
758 * For small values, 1/tgamma(x) has power series x + gamma x^2,
759 * so in this range, 1/tgamma(x) = x + gamma x^2 with error on the order of x^3.
760 * The relative error over this interval is less than 6e-7. */
762 return 1.0 / (x * (1.0 + gamma * x));
764 /* Second interval: [0.001, 12) */
766 double y = x; /* Working copy. */
768 /* Numerator coefficients for approximation over the interval (1,2) */
769 static const NV p[] = {
770 -1.71618513886549492533811E+0,
771 2.47656508055759199108314E+1,
772 -3.79804256470945635097577E+2,
773 6.29331155312818442661052E+2,
774 8.66966202790413211295064E+2,
775 -3.14512729688483675254357E+4,
776 -3.61444134186911729807069E+4,
777 6.64561438202405440627855E+4
779 /* Denominator coefficients for approximation over the interval (1, 2) */
780 static const NV q[] = {
781 -3.08402300119738975254353E+1,
782 3.15350626979604161529144E+2,
783 -1.01515636749021914166146E+3,
784 -3.10777167157231109440444E+3,
785 2.25381184209801510330112E+4,
786 4.75584627752788110767815E+3,
787 -1.34659959864969306392456E+5,
788 -1.15132259675553483497211E+5
799 n = Perl_floor(y) - 1;
803 for (i = 0; i < 8; i++) {
804 num = (num + p[i]) * z;
805 den = den * z + q[i];
807 result = num / den + 1.0;
810 /* Use the identity tgamma(z) = tgamma(z+1)/z
811 * The variable "result" now holds tgamma of the original y + 1
812 * Thus we use y - 1 to get back the original y. */
816 /* Use the identity tgamma(z+n) = z*(z+1)* ... *(z+n-1)*tgamma(z) */
817 for (i = 0; i < n; i++)
824 /* Third interval: [12, +Inf) */
825 if (x > 171.624) { /* XXX Too low for quad precision */
829 return Perl_exp(my_lgamma(x));
832 # define c99_tgamma my_tgamma
836 #if !defined(c99_lgamma) || !defined(c99_tgamma)
837 static NV my_lgamma(NV x)
841 if (x <= 0 || x == NV_INF)
843 if (x == 1.0 || x == 2.0)
846 return Perl_log(PERL_ABS(my_tgamma(x)));
847 /* Abramowitz and Stegun 6.1.41
848 * Asymptotic series should be good to at least 11 or 12 figures
849 * For error analysis, see Whittiker and Watson
850 * A Course in Modern Analysis (1927), page 252 */
852 static const NV c[8] = {
862 NV z = 1.0 / (x * x);
864 static const NV half_log_of_two_pi =
865 0.91893853320467274178032973640562;
868 for (i = 6; i >= 0; i--) {
873 return (x - 0.5) * Perl_log(x) - x + half_log_of_two_pi + series;
877 # define c99_lgamma my_lgamma
882 static NV my_log1p(NV x)
884 /* http://www.johndcook.com/cpp_log_one_plus_x.html -- public domain.
885 * Taylor series, the first four terms (the last term quartic). */
890 if (PERL_ABS(x) > 1e-4)
891 return Perl_log(1.0 + x);
893 /* Probably not enough for long doubles. */
894 return x * (1.0 + x * (-1/2.0 + x * (1/3.0 - x/4.0)));
896 # define c99_log1p my_log1p
900 static NV my_log2(NV x)
902 return Perl_log(x) * M_LOG2E;
904 # define c99_log2 my_log2
911 static int my_fegetround()
913 #ifdef HAS_FEGETROUND
915 #elif defined(HAS_FPGETROUND)
916 switch (fpgetround()) {
917 case FP_RN: return FE_TONEAREST;
918 case FP_RZ: return FE_TOWARDZERO;
919 case FP_RM: return FE_DOWNWARD;
920 case FP_RP: return FE_UPWARD;
923 #elif defined(FLT_ROUNDS)
924 switch (FLT_ROUNDS) {
925 case 0: return FE_TOWARDZERO;
926 case 1: return FE_TONEAREST;
927 case 2: return FE_UPWARD;
928 case 3: return FE_DOWNWARD;
931 #elif defined(__osf__) /* Tru64 */
932 switch (read_rnd()) {
933 case FP_RND_RN: return FE_TONEAREST;
934 case FP_RND_RZ: return FE_TOWARDZERO;
935 case FP_RND_RM: return FE_DOWNWARD;
936 case FP_RND_RP: return FE_UPWARD;
944 /* Toward closest integer. */
945 #define MY_ROUND_NEAREST(x) ((NV)((IV)((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)))
948 #define MY_ROUND_TRUNC(x) ((NV)((IV)(x)))
950 /* Toward minus infinity. */
951 #define MY_ROUND_DOWN(x) ((NV)((IV)((x) >= 0.0 ? (x) : (x) - 0.5)))
953 /* Toward plus infinity. */
954 #define MY_ROUND_UP(x) ((NV)((IV)((x) >= 0.0 ? (x) + 0.5 : (x))))
956 #if (!defined(c99_nearbyint) || !defined(c99_lrint)) && defined(FE_TONEAREST)
957 static NV my_rint(NV x)
960 switch (my_fegetround()) {
961 case FE_TONEAREST: return MY_ROUND_NEAREST(x);
962 case FE_TOWARDZERO: return MY_ROUND_TRUNC(x);
963 case FE_DOWNWARD: return MY_ROUND_DOWN(x);
964 case FE_UPWARD: return MY_ROUND_UP(x);
965 default: return NV_NAN;
967 #elif defined(HAS_FPGETROUND)
968 switch (fpgetround()) {
969 case FP_RN: return MY_ROUND_NEAREST(x);
970 case FP_RZ: return MY_ROUND_TRUNC(x);
971 case FP_RM: return MY_ROUND_DOWN(x);
972 case FE_RP: return MY_ROUND_UP(x);
973 default: return NV_NAN;
981 /* XXX nearbyint() and rint() are not really identical -- but the difference
982 * is messy: nearbyint is defined NOT to raise FE_INEXACT floating point
983 * exceptions, while rint() is defined to MAYBE raise them. At the moment
984 * Perl is blissfully unaware of such fine detail of floating point. */
985 #ifndef c99_nearbyint
987 # define c99_nearbyrint my_rint
993 static IV my_lrint(NV x)
995 return (IV)my_rint(x);
997 # define c99_lrint my_lrint
1002 static IV my_lround(NV x)
1004 return (IV)MY_ROUND_NEAREST(x);
1006 # define c99_lround my_lround
1014 # ifdef FE_TONEAREST
1015 # define c99_rint my_rint
1020 static NV my_round(NV x)
1022 return MY_ROUND_NEAREST(x);
1024 # define c99_round my_round
1028 # if defined(Perl_ldexp) && FLT_RADIX == 2
1029 static NV my_scalbn(NV x, int y)
1031 return Perl_ldexp(x, y);
1033 # define c99_scalbn my_scalbn
1037 /* XXX sinh (though c89) */
1039 /* tgamma -- see lgamma */
1041 /* XXX tanh (though c89) */
1044 static NV my_trunc(NV x)
1046 return MY_ROUND_TRUNC(x);
1048 # define c99_trunc my_trunc
1051 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
1052 metaconfig for future extension writers. We don't use them in POSIX.
1053 (This is really sneaky :-) --AD
1055 #if defined(I_TERMIOS)
1056 #include <termios.h>
1064 #include <sys/stat.h>
1065 #include <sys/types.h>
1073 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
1074 extern char *tzname[];
1077 #if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
1078 char *tzname[] = { "" , "" };
1082 #if defined(__VMS) && !defined(__POSIX_SOURCE)
1084 # include <utsname.h>
1087 # define mkfifo(a,b) (not_here("mkfifo"),-1)
1089 /* The POSIX notion of ttyname() is better served by getname() under VMS */
1090 static char ttnambuf[64];
1091 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
1094 #if defined (__CYGWIN__)
1095 # define tzname _tzname
1097 #if defined (WIN32) || defined (NETWARE)
1099 # define mkfifo(a,b) not_here("mkfifo")
1100 # define ttyname(a) (char*)not_here("ttyname")
1101 # define sigset_t long
1104 # define mode_t short
1107 # define mode_t short
1109 # define tzset() not_here("tzset")
1111 # ifndef _POSIX_OPEN_MAX
1112 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
1115 # define sigaction(a,b,c) not_here("sigaction")
1116 # define sigpending(a) not_here("sigpending")
1117 # define sigprocmask(a,b,c) not_here("sigprocmask")
1118 # define sigsuspend(a) not_here("sigsuspend")
1119 # define sigemptyset(a) not_here("sigemptyset")
1120 # define sigaddset(a,b) not_here("sigaddset")
1121 # define sigdelset(a,b) not_here("sigdelset")
1122 # define sigfillset(a) not_here("sigfillset")
1123 # define sigismember(a,b) not_here("sigismember")
1127 # define setuid(a) not_here("setuid")
1128 # define setgid(a) not_here("setgid")
1129 #endif /* NETWARE */
1130 # define strtold(s1,s2) not_here("strtold")
1135 # define mkfifo(a,b) not_here("mkfifo")
1136 # else /* !( defined OS2 ) */
1138 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
1141 # endif /* !HAS_MKFIFO */
1146 # include <sys/times.h>
1148 # include <sys/utsname.h>
1150 # include <sys/wait.h>
1154 #endif /* WIN32 || NETWARE */
1158 typedef long SysRetLong;
1159 typedef sigset_t* POSIX__SigSet;
1160 typedef HV* POSIX__SigAction;
1162 typedef struct termios* POSIX__Termios;
1163 #else /* Define termios types to int, and call not_here for the functions.*/
1164 #define POSIX__Termios int
1166 #define tcflag_t int
1168 #define cfgetispeed(x) not_here("cfgetispeed")
1169 #define cfgetospeed(x) not_here("cfgetospeed")
1170 #define tcdrain(x) not_here("tcdrain")
1171 #define tcflush(x,y) not_here("tcflush")
1172 #define tcsendbreak(x,y) not_here("tcsendbreak")
1173 #define cfsetispeed(x,y) not_here("cfsetispeed")
1174 #define cfsetospeed(x,y) not_here("cfsetospeed")
1175 #define ctermid(x) (char *) not_here("ctermid")
1176 #define tcflow(x,y) not_here("tcflow")
1177 #define tcgetattr(x,y) not_here("tcgetattr")
1178 #define tcsetattr(x,y,z) not_here("tcsetattr")
1181 /* Possibly needed prototypes */
1184 double strtod (const char *, char **);
1185 long strtol (const char *, char **, int);
1186 unsigned long strtoul (const char *, char **, int);
1188 long double strtold (const char *, char **);
1193 #ifndef HAS_DIFFTIME
1195 #define difftime(a,b) not_here("difftime")
1198 #ifndef HAS_FPATHCONF
1199 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
1202 #define mktime(a) not_here("mktime")
1205 #define nice(a) not_here("nice")
1207 #ifndef HAS_PATHCONF
1208 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
1211 #define sysconf(n) (SysRetLong) not_here("sysconf")
1213 #ifndef HAS_READLINK
1214 #define readlink(a,b,c) not_here("readlink")
1217 #define setpgid(a,b) not_here("setpgid")
1220 #define setsid() not_here("setsid")
1223 #define strcoll(s1,s2) not_here("strcoll")
1226 #define strtod(s1,s2) not_here("strtod")
1229 #define strtold(s1,s2) not_here("strtold")
1232 #define strtol(s1,s2,b) not_here("strtol")
1235 #define strtoul(s1,s2,b) not_here("strtoul")
1238 #define strxfrm(s1,s2,n) not_here("strxfrm")
1240 #ifndef HAS_TCGETPGRP
1241 #define tcgetpgrp(a) not_here("tcgetpgrp")
1243 #ifndef HAS_TCSETPGRP
1244 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
1248 #define times(a) not_here("times")
1249 #endif /* NETWARE */
1252 #define uname(a) not_here("uname")
1255 #define waitpid(a,b,c) not_here("waitpid")
1260 #define mblen(a,b) not_here("mblen")
1263 #ifndef HAS_MBSTOWCS
1264 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
1267 #define mbtowc(pwc, s, n) not_here("mbtowc")
1269 #ifndef HAS_WCSTOMBS
1270 #define wcstombs(s, pwcs, n) not_here("wcstombs")
1273 #define wctomb(s, wchar) not_here("wcstombs")
1275 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
1276 /* If we don't have these functions, then we wouldn't have gotten a typedef
1277 for wchar_t, the wide character type. Defining wchar_t allows the
1278 functions referencing it to compile. Its actual type is then meaningless,
1279 since without the above functions, all sections using it end up calling
1280 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
1282 #define wchar_t char
1286 #ifndef HAS_LOCALECONV
1287 # define localeconv() not_here("localeconv")
1289 struct lconv_offset {
1294 const struct lconv_offset lconv_strings[] = {
1295 #ifdef USE_LOCALE_NUMERIC
1296 {"decimal_point", STRUCT_OFFSET(struct lconv, decimal_point)},
1297 {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)},
1298 # ifndef NO_LOCALECONV_GROUPING
1299 {"grouping", STRUCT_OFFSET(struct lconv, grouping)},
1302 #ifdef USE_LOCALE_MONETARY
1303 {"int_curr_symbol", STRUCT_OFFSET(struct lconv, int_curr_symbol)},
1304 {"currency_symbol", STRUCT_OFFSET(struct lconv, currency_symbol)},
1305 {"mon_decimal_point", STRUCT_OFFSET(struct lconv, mon_decimal_point)},
1306 # ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1307 {"mon_thousands_sep", STRUCT_OFFSET(struct lconv, mon_thousands_sep)},
1309 # ifndef NO_LOCALECONV_MON_GROUPING
1310 {"mon_grouping", STRUCT_OFFSET(struct lconv, mon_grouping)},
1312 {"positive_sign", STRUCT_OFFSET(struct lconv, positive_sign)},
1313 {"negative_sign", STRUCT_OFFSET(struct lconv, negative_sign)},
1318 #ifdef USE_LOCALE_NUMERIC
1320 /* The Linux man pages say these are the field names for the structure
1321 * components that are LC_NUMERIC; the rest being LC_MONETARY */
1322 # define isLC_NUMERIC_STRING(name) (strcmp(name, "decimal_point") \
1323 || strcmp(name, "thousands_sep") \
1325 /* There should be no harm done \
1326 * checking for this, even if \
1327 * NO_LOCALECONV_GROUPING */ \
1328 || strcmp(name, "grouping"))
1330 # define isLC_NUMERIC_STRING(name) (0)
1333 const struct lconv_offset lconv_integers[] = {
1334 #ifdef USE_LOCALE_MONETARY
1335 {"int_frac_digits", STRUCT_OFFSET(struct lconv, int_frac_digits)},
1336 {"frac_digits", STRUCT_OFFSET(struct lconv, frac_digits)},
1337 {"p_cs_precedes", STRUCT_OFFSET(struct lconv, p_cs_precedes)},
1338 {"p_sep_by_space", STRUCT_OFFSET(struct lconv, p_sep_by_space)},
1339 {"n_cs_precedes", STRUCT_OFFSET(struct lconv, n_cs_precedes)},
1340 {"n_sep_by_space", STRUCT_OFFSET(struct lconv, n_sep_by_space)},
1341 {"p_sign_posn", STRUCT_OFFSET(struct lconv, p_sign_posn)},
1342 {"n_sign_posn", STRUCT_OFFSET(struct lconv, n_sign_posn)},
1343 #ifdef HAS_LC_MONETARY_2008
1344 {"int_p_cs_precedes", STRUCT_OFFSET(struct lconv, int_p_cs_precedes)},
1345 {"int_p_sep_by_space", STRUCT_OFFSET(struct lconv, int_p_sep_by_space)},
1346 {"int_n_cs_precedes", STRUCT_OFFSET(struct lconv, int_n_cs_precedes)},
1347 {"int_n_sep_by_space", STRUCT_OFFSET(struct lconv, int_n_sep_by_space)},
1348 {"int_p_sign_posn", STRUCT_OFFSET(struct lconv, int_p_sign_posn)},
1349 {"int_n_sign_posn", STRUCT_OFFSET(struct lconv, int_n_sign_posn)},
1355 #endif /* HAS_LOCALECONV */
1357 #ifdef HAS_LONG_DOUBLE
1358 # if LONG_DOUBLESIZE > NVSIZE
1359 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
1363 #ifndef HAS_LONG_DOUBLE
1375 /* Background: in most systems the low byte of the wait status
1376 * is the signal (the lowest 7 bits) and the coredump flag is
1377 * the eight bit, and the second lowest byte is the exit status.
1378 * BeOS bucks the trend and has the bytes in different order.
1379 * See beos/beos.c for how the reality is bent even in BeOS
1380 * to follow the traditional. However, to make the POSIX
1381 * wait W*() macros to work in BeOS, we need to unbend the
1382 * reality back in place. --jhi */
1383 /* In actual fact the code below is to blame here. Perl has an internal
1384 * representation of the exit status ($?), which it re-composes from the
1385 * OS's representation using the W*() POSIX macros. The code below
1386 * incorrectly uses the W*() macros on the internal representation,
1387 * which fails for OSs that have a different representation (namely BeOS
1388 * and Haiku). WMUNGE() is a hack that converts the internal
1389 * representation into the OS specific one, so that the W*() macros work
1390 * as expected. The better solution would be not to use the W*() macros
1391 * in the first place, though. -- Ingo Weinhold
1393 #if defined(__HAIKU__)
1394 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
1396 # define WMUNGE(x) (x)
1400 not_here(const char *s)
1402 croak("POSIX::%s not implemented on this architecture", s);
1406 #include "const-c.inc"
1409 restore_sigmask(pTHX_ SV *osset_sv)
1411 /* Fortunately, restoring the signal mask can't fail, because
1412 * there's nothing we can do about it if it does -- we're not
1413 * supposed to return -1 from sigaction unless the disposition
1416 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
1417 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
1421 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
1422 SV *const t = newSVrv(rv, packname);
1423 void *const p = sv_grow(t, size + 1);
1433 * (1) The CRT maintains its own copy of the environment, separate from
1434 * the Win32API copy.
1436 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
1437 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
1440 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
1441 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
1444 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
1445 * calls CRT tzset(), but only the first time it is called, and in turn
1446 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
1447 * local copy of the environment and hence gets the original setting as
1448 * perl never updates the CRT copy when assigning to $ENV{TZ}.
1450 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
1451 * putenv() to update the CRT copy of the environment (if it is different)
1452 * whenever we're about to call tzset().
1454 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
1457 * (a) Each interpreter has its own copy of the environment inside the
1458 * perlhost structure. That allows applications that host multiple
1459 * independent Perl interpreters to isolate environment changes from
1460 * each other. (This is similar to how the perlhost mechanism keeps a
1461 * separate working directory for each Perl interpreter, so that calling
1462 * chdir() will not affect other interpreters.)
1464 * (b) Only the first Perl interpreter instantiated within a process will
1465 * "write through" environment changes to the process environment.
1467 * (c) Even the primary Perl interpreter won't update the CRT copy of the
1468 * the environment, only the Win32API copy (it calls win32_putenv()).
1470 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
1471 * sense to only update the process environment when inside the main
1472 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
1473 * from here so we'll just have to check PL_curinterp instead.
1475 * Therefore, we can simply #undef getenv() and putenv() so that those names
1476 * always refer to the CRT functions, and explicitly call win32_getenv() to
1477 * access perl's %ENV.
1479 * We also #undef malloc() and free() to be sure we are using the CRT
1480 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
1481 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
1482 * when the Perl interpreter is being destroyed so we'd end up with a pointer
1483 * into deallocated memory in environ[] if a program embedding a Perl
1484 * interpreter continues to operate even after the main Perl interpreter has
1487 * Note that we don't free() the malloc()ed memory unless and until we call
1488 * malloc() again ourselves because the CRT putenv() function simply puts its
1489 * pointer argument into the environ[] array (it doesn't make a copy of it)
1490 * so this memory must otherwise be leaked.
1499 fix_win32_tzenv(void)
1501 static char* oldenv = NULL;
1503 const char* perl_tz_env = win32_getenv("TZ");
1504 const char* crt_tz_env = getenv("TZ");
1505 if (perl_tz_env == NULL)
1507 if (crt_tz_env == NULL)
1509 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
1510 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
1511 if (newenv != NULL) {
1512 sprintf(newenv, "TZ=%s", perl_tz_env);
1524 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
1525 * This code is duplicated in the Time-Piece module, so any changes made here
1526 * should be made there too.
1532 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
1533 if (PL_curinterp == aTHX)
1540 typedef int (*isfunc_t)(int);
1541 typedef void (*any_dptr_t)(void *);
1543 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
1545 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
1546 static XSPROTO(is_common)
1551 croak_xs_usage(cv, "charstring");
1556 /*int RETVAL = 0; YYY means uncomment this to return false on an
1557 * empty string input */
1559 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
1560 unsigned char *e = s + len;
1561 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
1563 if (ckWARN_d(WARN_DEPRECATED)) {
1565 /* Warn exactly once for each lexical place this function is
1566 * called. See thread at
1567 * http://markmail.org/thread/jhqcag5njmx7jpyu */
1569 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
1570 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
1571 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
1572 "Calling POSIX::%"HEKf"() is deprecated",
1573 HEKfARG(GvNAME_HEK(CvGV(cv))));
1574 hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
1578 /*if (e > s) { YYY */
1579 for (RETVAL = 1; RETVAL && s < e; s++)
1589 MODULE = POSIX PACKAGE = POSIX
1594 const char *file = __FILE__;
1597 /* silence compiler warning about not_here() defined but not used */
1598 if (0) not_here("");
1600 /* Ensure we get the function, not a macro implementation. Like the C89
1601 standard says we can... */
1603 cv = newXS("POSIX::isalnum", is_common, file);
1604 XSANY.any_dptr = (any_dptr_t) &isalnum;
1606 cv = newXS("POSIX::isalpha", is_common, file);
1607 XSANY.any_dptr = (any_dptr_t) &isalpha;
1609 cv = newXS("POSIX::iscntrl", is_common, file);
1610 XSANY.any_dptr = (any_dptr_t) &iscntrl;
1612 cv = newXS("POSIX::isdigit", is_common, file);
1613 XSANY.any_dptr = (any_dptr_t) &isdigit;
1615 cv = newXS("POSIX::isgraph", is_common, file);
1616 XSANY.any_dptr = (any_dptr_t) &isgraph;
1618 cv = newXS("POSIX::islower", is_common, file);
1619 XSANY.any_dptr = (any_dptr_t) &islower;
1621 cv = newXS("POSIX::isprint", is_common, file);
1622 XSANY.any_dptr = (any_dptr_t) &isprint;
1624 cv = newXS("POSIX::ispunct", is_common, file);
1625 XSANY.any_dptr = (any_dptr_t) &ispunct;
1627 cv = newXS("POSIX::isspace", is_common, file);
1628 XSANY.any_dptr = (any_dptr_t) &isspace;
1630 cv = newXS("POSIX::isupper", is_common, file);
1631 XSANY.any_dptr = (any_dptr_t) &isupper;
1633 cv = newXS("POSIX::isxdigit", is_common, file);
1634 XSANY.any_dptr = (any_dptr_t) &isxdigit;
1637 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
1640 new(packname = "POSIX::SigSet", ...)
1641 const char * packname
1646 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1650 for (i = 1; i < items; i++)
1651 sigaddset(s, SvIV(ST(i)));
1657 POSIX::SigSet sigset
1662 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
1668 POSIX::SigSet sigset
1672 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
1677 sigismember(sigset, sig)
1678 POSIX::SigSet sigset
1681 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
1684 new(packname = "POSIX::Termios", ...)
1685 const char * packname
1689 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
1690 sizeof(struct termios), packname);
1691 /* The previous implementation stored a pointer to an uninitialised
1692 struct termios. Seems safer to initialise it, particularly as
1693 this implementation exposes the struct to prying from perl-space.
1695 memset(p, 0, 1 + sizeof(struct termios));
1698 not_here("termios");
1703 getattr(termios_ref, fd = 0)
1704 POSIX::Termios termios_ref
1707 RETVAL = tcgetattr(fd, termios_ref);
1711 # If we define TCSANOW here then both a found and not found constant sub
1712 # are created causing a Constant subroutine TCSANOW redefined warning
1714 # define DEF_SETATTR_ACTION 0
1716 # define DEF_SETATTR_ACTION TCSANOW
1719 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
1720 POSIX::Termios termios_ref
1722 int optional_actions
1724 /* The second argument to the call is mandatory, but we'd like to give
1725 it a useful default. 0 isn't valid on all operating systems - on
1726 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
1727 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
1728 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
1733 getispeed(termios_ref)
1734 POSIX::Termios termios_ref
1738 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
1743 getiflag(termios_ref)
1744 POSIX::Termios termios_ref
1750 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1753 RETVAL = termios_ref->c_iflag;
1756 RETVAL = termios_ref->c_oflag;
1759 RETVAL = termios_ref->c_cflag;
1762 RETVAL = termios_ref->c_lflag;
1765 RETVAL = 0; /* silence compiler warning */
1768 not_here(GvNAME(CvGV(cv)));
1775 getcc(termios_ref, ccix)
1776 POSIX::Termios termios_ref
1779 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1781 croak("Bad getcc subscript");
1782 RETVAL = termios_ref->c_cc[ccix];
1791 setispeed(termios_ref, speed)
1792 POSIX::Termios termios_ref
1798 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
1803 setiflag(termios_ref, flag)
1804 POSIX::Termios termios_ref
1811 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1814 termios_ref->c_iflag = flag;
1817 termios_ref->c_oflag = flag;
1820 termios_ref->c_cflag = flag;
1823 termios_ref->c_lflag = flag;
1827 not_here(GvNAME(CvGV(cv)));
1831 setcc(termios_ref, ccix, cc)
1832 POSIX::Termios termios_ref
1836 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
1838 croak("Bad setcc subscript");
1839 termios_ref->c_cc[ccix] = cc;
1845 MODULE = POSIX PACKAGE = POSIX
1847 INCLUDE: const-xs.inc
1853 POSIX::WIFEXITED = 1
1854 POSIX::WIFSIGNALED = 2
1855 POSIX::WIFSTOPPED = 3
1859 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
1860 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
1861 RETVAL = 0; /* Silence compilers that notice this, but don't realise
1862 that not_here() can't return. */
1867 RETVAL = WEXITSTATUS(WMUNGE(status));
1869 not_here("WEXITSTATUS");
1874 RETVAL = WIFEXITED(WMUNGE(status));
1876 not_here("WIFEXITED");
1881 RETVAL = WIFSIGNALED(WMUNGE(status));
1883 not_here("WIFSIGNALED");
1888 RETVAL = WIFSTOPPED(WMUNGE(status));
1890 not_here("WIFSTOPPED");
1895 RETVAL = WSTOPSIG(WMUNGE(status));
1897 not_here("WSTOPSIG");
1902 RETVAL = WTERMSIG(WMUNGE(status));
1904 not_here("WTERMSIG");
1908 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
1914 open(filename, flags = O_RDONLY, mode = 0666)
1919 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1920 TAINT_PROPER("open");
1921 RETVAL = open(filename, flags, mode);
1929 #ifndef HAS_LOCALECONV
1930 localeconv(); /* A stub to call not_here(). */
1932 struct lconv *lcbuf;
1934 /* localeconv() deals with both LC_NUMERIC and LC_MONETARY, but
1935 * LC_MONETARY is already in the correct locale */
1936 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
1939 sv_2mortal((SV*)RETVAL);
1940 if ((lcbuf = localeconv())) {
1941 const struct lconv_offset *strings = lconv_strings;
1942 const struct lconv_offset *integers = lconv_integers;
1943 const char *ptr = (const char *) lcbuf;
1946 /* This string may be controlled by either LC_NUMERIC, or
1949 #if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY)
1950 = _is_cur_LC_category_utf8((isLC_NUMERIC_STRING(strings->name))
1953 #elif defined(USE_LOCALE_NUMERIC)
1954 = _is_cur_LC_category_utf8(LC_NUMERIC);
1955 #elif defined(USE_LOCALE_MONETARY)
1956 = _is_cur_LC_category_utf8(LC_MONETARY);
1961 const char *value = *((const char **)(ptr + strings->offset));
1963 if (value && *value) {
1964 (void) hv_store(RETVAL,
1966 strlen(strings->name),
1967 newSVpvn_utf8(value,
1970 /* We mark it as UTF-8 if a utf8 locale
1971 * and is valid, non-ascii UTF-8 */
1973 && ! is_ascii_string((U8 *) value, 0)
1974 && is_utf8_string((U8 *) value, 0)),
1977 } while ((++strings)->name);
1980 const char value = *((const char *)(ptr + integers->offset));
1982 if (value != CHAR_MAX)
1983 (void) hv_store(RETVAL, integers->name,
1984 strlen(integers->name), newSViv(value), 0);
1985 } while ((++integers)->name);
1987 RESTORE_NUMERIC_STANDARD();
1988 #endif /* HAS_LOCALECONV */
1993 setlocale(category, locale = 0)
1999 #ifdef USE_LOCALE_NUMERIC
2000 /* A 0 (or NULL) locale means only query what the current one is. We
2001 * have the LC_NUMERIC name saved, because we are normally switched
2002 * into the C locale for it. Switch back so an LC_ALL query will yield
2003 * the correct results; all other categories don't require special
2006 if (category == LC_NUMERIC) {
2007 XSRETURN_PV(PL_numeric_name);
2010 else if (category == LC_ALL) {
2011 SET_NUMERIC_LOCAL();
2016 #ifdef WIN32 /* Use wrapper on Windows */
2017 retval = Perl_my_setlocale(aTHX_ category, locale);
2019 retval = setlocale(category, locale);
2022 /* Should never happen that a query would return an error, but be
2023 * sure and reset to C locale */
2025 SET_NUMERIC_STANDARD();
2030 /* Save retval since subsequent setlocale() calls may overwrite it. */
2031 retval = savepv(retval);
2033 /* For locale == 0, we may have switched to NUMERIC_LOCAL. Switch back
2036 SET_NUMERIC_STANDARD();
2037 XSRETURN_PV(retval);
2041 #ifdef USE_LOCALE_CTYPE
2042 if (category == LC_CTYPE
2044 || category == LC_ALL
2050 if (category == LC_ALL)
2051 newctype = setlocale(LC_CTYPE, NULL);
2055 new_ctype(newctype);
2057 #endif /* USE_LOCALE_CTYPE */
2058 #ifdef USE_LOCALE_COLLATE
2059 if (category == LC_COLLATE
2061 || category == LC_ALL
2067 if (category == LC_ALL)
2068 newcoll = setlocale(LC_COLLATE, NULL);
2072 new_collate(newcoll);
2074 #endif /* USE_LOCALE_COLLATE */
2075 #ifdef USE_LOCALE_NUMERIC
2076 if (category == LC_NUMERIC
2078 || category == LC_ALL
2084 if (category == LC_ALL)
2085 newnum = setlocale(LC_NUMERIC, NULL);
2089 new_numeric(newnum);
2091 #endif /* USE_LOCALE_NUMERIC */
2136 RETVAL = Perl_acos(x); /* C89 math */
2140 RETVAL = c99_acosh(x);
2146 RETVAL = Perl_asin(x); /* C89 math */
2150 RETVAL = c99_asinh(x);
2156 RETVAL = Perl_atan(x); /* C89 math */
2160 RETVAL = c99_atanh(x);
2167 RETVAL = c99_cbrt(x);
2173 RETVAL = Perl_ceil(x); /* C89 math */
2176 RETVAL = Perl_cosh(x); /* C89 math */
2180 RETVAL = c99_erf(x);
2187 RETVAL = c99_erfc(x);
2194 RETVAL = c99_exp2(x);
2201 RETVAL = c99_expm1(x);
2207 RETVAL = Perl_floor(x); /* C89 math */
2211 RETVAL = bessel_j0(x);
2218 RETVAL = bessel_j1(x);
2224 /* XXX Note: the lgamma modifies a global variable (signgam),
2225 * which is evil. Some platforms have lgamma_r, which has
2226 * extra output parameter instead of the global variable. */
2228 RETVAL = c99_lgamma(x);
2234 RETVAL = log10(x); /* C89 math */
2238 RETVAL = c99_log1p(x);
2245 RETVAL = c99_log2(x);
2252 RETVAL = c99_logb(x);
2258 #ifdef c99_nearbyint
2259 RETVAL = c99_nearbyint(x);
2261 not_here("nearbyint");
2266 RETVAL = c99_rint(x);
2273 RETVAL = c99_round(x);
2279 RETVAL = Perl_sinh(x); /* C89 math */
2282 RETVAL = Perl_tan(x); /* C89 math */
2285 RETVAL = Perl_tanh(x); /* C89 math */
2289 RETVAL = c99_tgamma(x);
2296 RETVAL = c99_trunc(x);
2303 RETVAL = bessel_y0(x);
2311 RETVAL = bessel_y1(x);
2322 #ifdef HAS_FEGETROUND
2323 RETVAL = my_fegetround();
2326 not_here("fegetround");
2335 #ifdef HAS_FEGETROUND /* canary for fesetround */
2336 RETVAL = fesetround(x);
2337 #elif defined(HAS_FPGETROUND) /* canary for fpsetround */
2339 case FE_TONEAREST: RETVAL = fpsetround(FP_RN); break;
2340 case FE_TOWARDZERO: RETVAL = fpsetround(FP_RZ); break;
2341 case FE_DOWNWARD: RETVAL = fpsetround(FP_RM); break;
2342 case FE_UPWARD: RETVAL = fpsetround(FP_RP); break;
2343 default: RETVAL = -1; break;
2345 #elif defined(__osf__) /* Tru64 */
2347 case FE_TONEAREST: RETVAL = write_rnd(FP_RND_RN); break;
2348 case FE_TOWARDZERO: RETVAL = write_rnd(FP_RND_RZ); break;
2349 case FE_DOWNWARD: RETVAL = write_rnd(FP_RND_RM); break;
2350 case FE_UPWARD: RETVAL = write_rnd(FP_RND_RP); break;
2351 default: RETVAL = -1; break;
2355 not_here("fesetround");
2376 #ifdef c99_fpclassify
2377 RETVAL = c99_fpclassify(x);
2379 not_here("fpclassify");
2384 RETVAL = c99_ilogb(x);
2390 RETVAL = Perl_isfinite(x);
2393 RETVAL = Perl_isinf(x);
2396 RETVAL = Perl_isnan(x);
2400 RETVAL = c99_isnormal(x);
2402 not_here("isnormal");
2407 RETVAL = c99_lrint(x);
2414 RETVAL = c99_lround(x);
2422 RETVAL = Perl_signbit(x);
2424 RETVAL = (x < 0) || (x == -0.0);
2455 RETVAL = c99_copysign(x, y);
2457 not_here("copysign");
2462 RETVAL = c99_fdim(x, y);
2469 RETVAL = c99_fmax(x, y);
2476 RETVAL = c99_fmin(x, y);
2482 RETVAL = Perl_fmod(x, y); /* C89 math */
2486 RETVAL = c99_hypot(x, y);
2492 #ifdef c99_isgreater
2493 RETVAL = c99_isgreater(x, y);
2495 not_here("isgreater");
2499 #ifdef c99_isgreaterequal
2500 RETVAL = c99_isgreaterequal(x, y);
2502 not_here("isgreaterequal");
2507 RETVAL = c99_isless(x, y);
2513 #ifdef c99_islessequal
2514 RETVAL = c99_islessequal(x, y);
2516 not_here("islessequal");
2520 #ifdef c99_islessgreater
2521 RETVAL = c99_islessgreater(x, y);
2523 not_here("islessgreater");
2527 #ifdef c99_isunordered
2528 RETVAL = c99_isunordered(x, y);
2530 not_here("isunordered");
2534 #ifdef c99_nextafter
2535 RETVAL = c99_nextafter(x, y);
2537 not_here("nextafter");
2541 #ifdef c99_nexttoward
2542 RETVAL = c99_nexttoward(x, y);
2544 not_here("nexttoward");
2549 #ifdef c99_remainder
2550 RETVAL = c99_remainder(x, y);
2552 not_here("remainder");
2564 /* (We already know stack is long enough.) */
2565 PUSHs(sv_2mortal(newSVnv(Perl_frexp(x,&expvar)))); /* C89 math */
2566 PUSHs(sv_2mortal(newSViv(expvar)));
2578 /* (We already know stack is long enough.) */
2579 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar)))); /* C89 math */
2580 PUSHs(sv_2mortal(newSVnv(intvar)));
2589 PUSHs(sv_2mortal(newSVnv(c99_remquo(x,y,&intvar))));
2590 PUSHs(sv_2mortal(newSVnv(intvar)));
2601 RETVAL = c99_scalbn(x, y);
2616 RETVAL = c99_fma(x, y, z);
2626 RETVAL = c99_nan(s ? s : "");
2627 #elif defined(NV_NAN)
2628 /* XXX if s != NULL, warn about unused argument,
2629 * or implement the nan payload setting. */
2648 RETVAL = bessel_jn(x, y);
2656 RETVAL = bessel_yn(x, y);
2666 sigaction(sig, optaction, oldaction = 0)
2669 POSIX::SigAction oldaction
2671 #if defined(WIN32) || defined(NETWARE)
2672 RETVAL = not_here("sigaction");
2674 # This code is really grody because we're trying to make the signal
2675 # interface look beautiful, which is hard.
2679 POSIX__SigAction action;
2680 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
2681 struct sigaction act;
2682 struct sigaction oact;
2686 POSIX__SigSet sigset;
2691 croak("Negative signals are not allowed");
2694 if (sig == 0 && SvPOK(ST(0))) {
2695 const char *s = SvPVX_const(ST(0));
2696 int i = whichsig(s);
2698 if (i < 0 && memEQ(s, "SIG", 3))
2699 i = whichsig(s + 3);
2701 if (ckWARN(WARN_SIGNAL))
2702 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2703 "No such signal: SIG%s", s);
2710 if (sig > NSIG) { /* NSIG - 1 is still okay. */
2711 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
2712 "No such signal: %d", sig);
2716 sigsvp = hv_fetch(GvHVn(siggv),
2718 strlen(PL_sig_name[sig]),
2721 /* Check optaction and set action */
2722 if(SvTRUE(optaction)) {
2723 if(sv_isa(optaction, "POSIX::SigAction"))
2724 action = (HV*)SvRV(optaction);
2726 croak("action is not of type POSIX::SigAction");
2732 /* sigaction() is supposed to look atomic. In particular, any
2733 * signal handler invoked during a sigaction() call should
2734 * see either the old or the new disposition, and not something
2735 * in between. We use sigprocmask() to make it so.
2738 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
2742 /* Restore signal mask no matter how we exit this block. */
2743 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
2744 SAVEFREESV( osset_sv );
2745 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
2747 RETVAL=-1; /* In case both oldaction and action are 0. */
2749 /* Remember old disposition if desired. */
2751 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
2753 croak("Can't supply an oldaction without a HANDLER");
2754 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
2755 sv_setsv(*svp, *sigsvp);
2758 sv_setpvs(*svp, "DEFAULT");
2760 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
2765 /* Get back the mask. */
2766 svp = hv_fetchs(oldaction, "MASK", TRUE);
2767 if (sv_isa(*svp, "POSIX::SigSet")) {
2768 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2771 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
2775 *sigset = oact.sa_mask;
2777 /* Get back the flags. */
2778 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
2779 sv_setiv(*svp, oact.sa_flags);
2781 /* Get back whether the old handler used safe signals. */
2782 svp = hv_fetchs(oldaction, "SAFE", TRUE);
2784 /* compare incompatible pointers by casting to integer */
2785 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
2789 /* Safe signals use "csighandler", which vectors through the
2790 PL_sighandlerp pointer when it's safe to do so.
2791 (BTW, "csighandler" is very different from "sighandler".) */
2792 svp = hv_fetchs(action, "SAFE", FALSE);
2796 (*svp && SvTRUE(*svp))
2797 ? PL_csighandlerp : PL_sighandlerp
2800 /* Vector new Perl handler through %SIG.
2801 (The core signal handlers read %SIG to dispatch.) */
2802 svp = hv_fetchs(action, "HANDLER", FALSE);
2804 croak("Can't supply an action without a HANDLER");
2805 sv_setsv(*sigsvp, *svp);
2807 /* This call actually calls sigaction() with almost the
2808 right settings, including appropriate interpretation
2809 of DEFAULT and IGNORE. However, why are we doing
2810 this when we're about to do it again just below? XXX */
2811 SvSETMAGIC(*sigsvp);
2813 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
2815 const char *s=SvPVX_const(*svp);
2816 if(strEQ(s,"IGNORE")) {
2817 act.sa_handler = SIG_IGN;
2819 else if(strEQ(s,"DEFAULT")) {
2820 act.sa_handler = SIG_DFL;
2824 /* Set up any desired mask. */
2825 svp = hv_fetchs(action, "MASK", FALSE);
2826 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
2827 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
2828 act.sa_mask = *sigset;
2831 sigemptyset(& act.sa_mask);
2833 /* Set up any desired flags. */
2834 svp = hv_fetchs(action, "FLAGS", FALSE);
2835 act.sa_flags = svp ? SvIV(*svp) : 0;
2837 /* Don't worry about cleaning up *sigsvp if this fails,
2838 * because that means we tried to disposition a
2839 * nonblockable signal, in which case *sigsvp is
2840 * essentially meaningless anyway.
2842 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
2857 POSIX::SigSet sigset
2861 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
2868 sigprocmask(how, sigset, oldsigset = 0)
2870 POSIX::SigSet sigset = NO_INIT
2871 POSIX::SigSet oldsigset = NO_INIT
2873 if (! SvOK(ST(1))) {
2875 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
2876 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
2878 croak("sigset is not of type POSIX::SigSet");
2881 if (items < 3 || ! SvOK(ST(2))) {
2883 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
2884 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
2886 croak("oldsigset is not of type POSIX::SigSet");
2899 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
2900 the well known documented POSIX behaviour for a POSIX API.
2901 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
2902 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
2904 RETVAL = dup2(fd1, fd2);
2910 lseek(fd, offset, whence)
2915 Off_t pos = PerlLIO_lseek(fd, offset, whence);
2916 RETVAL = sizeof(Off_t) > sizeof(IV)
2917 ? newSVnv((NV)pos) : newSViv((IV)pos);
2926 if ((incr = nice(incr)) != -1 || errno == 0) {
2928 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
2930 XPUSHs(sv_2mortal(newSViv(incr)));
2937 if (pipe(fds) != -1) {
2939 PUSHs(sv_2mortal(newSViv(fds[0])));
2940 PUSHs(sv_2mortal(newSViv(fds[1])));
2944 read(fd, buffer, nbytes)
2946 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
2950 char * buffer = sv_grow( sv_buffer, nbytes+1 );
2953 SvCUR_set(sv_buffer, RETVAL);
2954 SvPOK_only(sv_buffer);
2955 *SvEND(sv_buffer) = '\0';
2956 SvTAINTED_on(sv_buffer);
2972 tcsetpgrp(fd, pgrp_id)
2981 if (uname(&buf) >= 0) {
2983 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
2984 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
2985 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
2986 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
2987 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
2990 uname((char *) 0); /* A stub to call not_here(). */
2994 write(fd, buffer, nbytes)
3005 RETVAL = newSVpvs("");
3006 SvGROW(RETVAL, L_tmpnam);
3007 /* Yes, we know tmpnam() is bad. So bad that some compilers
3008 * and linkers warn against using it. But it is here for
3009 * completeness. POSIX.pod warns against using it.
3011 * Then again, maybe this should be removed at some point.
3012 * No point in enabling dangerous interfaces. */
3013 if (ckWARN_d(WARN_DEPRECATED)) {
3014 HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
3015 if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
3016 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Calling POSIX::tmpnam() is deprecated");
3017 hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
3020 len = strlen(tmpnam(SvPV(RETVAL, i)));
3021 SvCUR_set(RETVAL, len);
3034 mbstowcs(s, pwcs, n)
3046 wcstombs(s, pwcs, n)
3068 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3069 num = strtod(str, &unparsed);
3070 PUSHs(sv_2mortal(newSVnv(num)));
3071 if (GIMME == G_ARRAY) {
3074 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3076 PUSHs(&PL_sv_undef);
3078 RESTORE_NUMERIC_STANDARD();
3089 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
3090 num = strtold(str, &unparsed);
3091 PUSHs(sv_2mortal(newSVnv(num)));
3092 if (GIMME == G_ARRAY) {
3095 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3097 PUSHs(&PL_sv_undef);
3099 RESTORE_NUMERIC_STANDARD();
3104 strtol(str, base = 0)
3111 num = strtol(str, &unparsed, base);
3112 #if IVSIZE <= LONGSIZE
3113 if (num < IV_MIN || num > IV_MAX)
3114 PUSHs(sv_2mortal(newSVnv((double)num)));
3117 PUSHs(sv_2mortal(newSViv((IV)num)));
3118 if (GIMME == G_ARRAY) {
3121 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3123 PUSHs(&PL_sv_undef);
3127 strtoul(str, base = 0)
3134 num = strtoul(str, &unparsed, base);
3135 #if IVSIZE <= LONGSIZE
3137 PUSHs(sv_2mortal(newSVnv((double)num)));
3140 PUSHs(sv_2mortal(newSViv((IV)num)));
3141 if (GIMME == G_ARRAY) {
3144 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3146 PUSHs(&PL_sv_undef);
3157 char *p = SvPV(src,srclen);
3159 buflen = srclen * 4 + 1;
3160 ST(0) = sv_2mortal(newSV(buflen));
3161 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)buflen);
3162 if (dstlen >= buflen) {
3164 SvGROW(ST(0), dstlen);
3165 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
3168 SvCUR_set(ST(0), dstlen);
3173 mkfifo(filename, mode)
3180 RETVAL = access(filename, mode);
3182 TAINT_PROPER("mkfifo");
3183 RETVAL = mkfifo(filename, mode);
3195 RETVAL = ix == 1 ? close(fd)
3196 : (ix < 1 ? tcdrain(fd) : dup(fd));
3209 RETVAL = ix == 1 ? tcflush(fd, action)
3210 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
3215 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
3231 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
3234 mytm.tm_hour = hour;
3235 mytm.tm_mday = mday;
3237 mytm.tm_year = year;
3238 mytm.tm_wday = wday;
3239 mytm.tm_yday = yday;
3240 mytm.tm_isdst = isdst;
3242 const time_t result = mktime(&mytm);
3243 if (result == (time_t)-1)
3245 else if (result == 0)
3246 sv_setpvn(TARG, "0 but true", 10);
3248 sv_setiv(TARG, (IV)result);
3250 sv_setpv(TARG, asctime(&mytm));
3268 realtime = times( &tms );
3270 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
3271 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
3272 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
3273 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
3274 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
3277 difftime(time1, time2)
3281 #XXX: if $xsubpp::WantOptimize is always the default
3282 # sv_setpv(TARG, ...) could be used rather than
3283 # ST(0) = sv_2mortal(newSVpv(...))
3285 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
3301 /* allowing user-supplied (rather than literal) formats
3302 * is normally frowned upon as a potential security risk;
3303 * but this is part of the API so we have to allow it */
3304 GCC_DIAG_IGNORE(-Wformat-nonliteral);
3305 buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
3307 sv = sv_newmortal();
3309 STRLEN len = strlen(buf);
3310 sv_usepvn_flags(sv, buf, len, SV_HAS_TRAILING_NUL);
3312 || (! is_ascii_string((U8*) buf, len)
3313 && is_utf8_string((U8*) buf, len)
3314 #ifdef USE_LOCALE_TIME
3315 && _is_cur_LC_category_utf8(LC_TIME)
3321 else { /* We can't distinguish between errors and just an empty
3322 * return; in all cases just return an empty string */
3323 SvUPGRADE(sv, SVt_PV);
3324 SvPV_set(sv, (char *) "");
3327 SvLEN_set(sv, 0); /* Won't attempt to free the string when sv
3342 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
3343 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
3349 #ifdef HAS_CTERMID_R
3350 s = (char *) safemalloc((size_t) L_ctermid);
3352 RETVAL = ctermid(s);
3356 #ifdef HAS_CTERMID_R
3365 RETVAL = cuserid(s);
3368 not_here("cuserid");
3379 pathconf(filename, name)
3390 unsigned int seconds
3392 RETVAL = PerlProc_sleep(seconds);
3418 XSprePUSH; PUSHTARG;
3422 lchown(uid, gid, path)
3428 /* yes, the order of arguments is different,
3429 * but consistent with CORE::chown() */
3430 RETVAL = lchown(path, uid, gid);
3432 RETVAL = not_here("lchown");