10 * Ideally this should be somewhere down in the includes
11 * but putting it in other places is giving compiler errors.
12 * Also here I am unable to check for HAS_UNAME since it wouldn't have
13 * yet come into the file at this stage - sgp 18th Oct 2000
15 #include <sys/utsname.h>
18 #define PERL_NO_GET_CONTEXT
21 #define PERLIO_NOT_STDIO 1
24 #if defined(PERL_IMPLICIT_SYS)
28 # define open PerlLIO_open3
31 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
58 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
59 metaconfig for future extension writers. We don't use them in POSIX.
60 (This is really sneaky :-) --AD
62 #if defined(I_TERMIOS)
70 #include <sys/types.h>
75 #ifdef MACOS_TRADITIONAL
81 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE)
82 extern char *tzname[];
85 #if !defined(WIN32) || (defined(__MINGW32__) && !defined(tzname))
86 char *tzname[] = { "" , "" };
90 #if defined(__VMS) && !defined(__POSIX_SOURCE)
91 # include <libdef.h> /* LIB$_INVARG constant */
92 # include <lib$routines.h> /* prototype for lib$ediv() */
93 # include <starlet.h> /* prototype for sys$gettim() */
94 # if DECC_VERSION < 50000000
95 # define pid_t int /* old versions of DECC miss this in types.h */
99 # define mkfifo(a,b) (not_here("mkfifo"),-1)
100 # define tzset() not_here("tzset")
102 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
103 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
104 # include <utsname.h>
105 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
107 /* The POSIX notion of ttyname() is better served by getname() under VMS */
108 static char ttnambuf[64];
109 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
111 /* The non-POSIX CRTL times() has void return type, so we just get the
112 current time directly */
113 clock_t vms_times(struct tms *bufptr) {
116 /* Get wall time and convert to 10 ms intervals to
117 * produce the return value that the POSIX standard expects */
118 # if defined(__DECC) && defined (__ALPHA)
121 _ckvmssts(sys$gettim(&vmstime));
123 retval = vmstime & 0x7fffffff;
125 /* (Older hw or ccs don't have an atomic 64-bit type, so we
126 * juggle 32-bit ints (and a float) to produce a time_t result
127 * with minimal loss of information.) */
128 long int vmstime[2],remainder,divisor = 100000;
129 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
130 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
131 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
133 /* Fill in the struct tms using the CRTL routine . . .*/
134 times((tbuffer_t *)bufptr);
135 return (clock_t) retval;
137 # define times(t) vms_times(t)
139 #if defined (__CYGWIN__)
140 # define tzname _tzname
142 #if defined (WIN32) || defined (NETWARE)
144 # define mkfifo(a,b) not_here("mkfifo")
145 # define ttyname(a) (char*)not_here("ttyname")
146 # define sigset_t long
149 # define tzname _tzname
152 # define mode_t short
155 # define mode_t short
157 # define tzset() not_here("tzset")
159 # ifndef _POSIX_OPEN_MAX
160 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
163 # define sigaction(a,b,c) not_here("sigaction")
164 # define sigpending(a) not_here("sigpending")
165 # define sigprocmask(a,b,c) not_here("sigprocmask")
166 # define sigsuspend(a) not_here("sigsuspend")
167 # define sigemptyset(a) not_here("sigemptyset")
168 # define sigaddset(a,b) not_here("sigaddset")
169 # define sigdelset(a,b) not_here("sigdelset")
170 # define sigfillset(a) not_here("sigfillset")
171 # define sigismember(a,b) not_here("sigismember")
175 # define setuid(a) not_here("setuid")
176 # define setgid(a) not_here("setgid")
181 # if defined(OS2) || defined(MACOS_TRADITIONAL)
182 # define mkfifo(a,b) not_here("mkfifo")
183 # else /* !( defined OS2 ) */
185 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
188 # endif /* !HAS_MKFIFO */
190 # ifdef MACOS_TRADITIONAL
191 # define ttyname(a) (char*)not_here("ttyname")
192 # define tzset() not_here("tzset")
195 # include <sys/times.h>
197 # include <sys/utsname.h>
199 # include <sys/wait.h>
204 #endif /* WIN32 || NETWARE */
208 typedef long SysRetLong;
209 typedef sigset_t* POSIX__SigSet;
210 typedef HV* POSIX__SigAction;
212 typedef struct termios* POSIX__Termios;
213 #else /* Define termios types to int, and call not_here for the functions.*/
214 #define POSIX__Termios int
218 #define cfgetispeed(x) not_here("cfgetispeed")
219 #define cfgetospeed(x) not_here("cfgetospeed")
220 #define tcdrain(x) not_here("tcdrain")
221 #define tcflush(x,y) not_here("tcflush")
222 #define tcsendbreak(x,y) not_here("tcsendbreak")
223 #define cfsetispeed(x,y) not_here("cfsetispeed")
224 #define cfsetospeed(x,y) not_here("cfsetospeed")
225 #define ctermid(x) (char *) not_here("ctermid")
226 #define tcflow(x,y) not_here("tcflow")
227 #define tcgetattr(x,y) not_here("tcgetattr")
228 #define tcsetattr(x,y,z) not_here("tcsetattr")
231 /* Possibly needed prototypes */
232 char *cuserid (char *);
234 double strtod (const char *, char **);
235 long strtol (const char *, char **, int);
236 unsigned long strtoul (const char *, char **, int);
240 #define cuserid(a) (char *) not_here("cuserid")
244 #define difftime(a,b) not_here("difftime")
247 #ifndef HAS_FPATHCONF
248 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
251 #define mktime(a) not_here("mktime")
254 #define nice(a) not_here("nice")
257 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
260 #define sysconf(n) (SysRetLong) not_here("sysconf")
263 #define readlink(a,b,c) not_here("readlink")
266 #define setpgid(a,b) not_here("setpgid")
269 #define setsid() not_here("setsid")
272 #define strcoll(s1,s2) not_here("strcoll")
275 #define strtod(s1,s2) not_here("strtod")
278 #define strtol(s1,s2,b) not_here("strtol")
281 #define strtoul(s1,s2,b) not_here("strtoul")
284 #define strxfrm(s1,s2,n) not_here("strxfrm")
286 #ifndef HAS_TCGETPGRP
287 #define tcgetpgrp(a) not_here("tcgetpgrp")
289 #ifndef HAS_TCSETPGRP
290 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
294 #define times(a) not_here("times")
298 #define uname(a) not_here("uname")
301 #define waitpid(a,b,c) not_here("waitpid")
306 #define mblen(a,b) not_here("mblen")
310 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
313 #define mbtowc(pwc, s, n) not_here("mbtowc")
316 #define wcstombs(s, pwcs, n) not_here("wcstombs")
319 #define wctomb(s, wchar) not_here("wcstombs")
321 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
322 /* If we don't have these functions, then we wouldn't have gotten a typedef
323 for wchar_t, the wide character type. Defining wchar_t allows the
324 functions referencing it to compile. Its actual type is then meaningless,
325 since without the above functions, all sections using it end up calling
326 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
332 #ifndef HAS_LOCALECONV
333 #define localeconv() not_here("localeconv")
336 #ifdef HAS_LONG_DOUBLE
337 # if LONG_DOUBLESIZE > NVSIZE
338 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
342 #ifndef HAS_LONG_DOUBLE
357 croak("POSIX::%s not implemented on this architecture", s);
361 #include "constants.c"
363 /* These were implemented in the old "constant" subroutine. They are actually
364 macros that take an integer argument and return an integer result. */
366 int_macro_int (const char *name, STRLEN len, IV *arg_result) {
367 /* Initially switch on the length of the name. */
368 /* This code has been edited from a "constant" function generated by:
370 use ExtUtils::Constant qw (constant_types C_constant XS_constant);
372 my $types = {map {($_, 1)} qw(IV)};
373 my @names = (qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS WIFEXITED
374 WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
376 print constant_types(); # macro defs
377 foreach (C_constant ("POSIX", 'int_macro_int', 'IV', $types, undef, 5, @names) ) {
378 print $_, "\n"; # C constant subs
380 print "#### XS Section:\n";
381 print XS_constant ("POSIX", $types);
387 /* Names all of length 7. */
388 /* S_ISBLK S_ISCHR S_ISDIR S_ISREG */
389 /* Offset 5 gives the best switch position. */
392 if (memEQ(name, "S_ISREG", 7)) {
395 *arg_result = S_ISREG(*arg_result);
396 return PERL_constant_ISIV;
398 return PERL_constant_NOTDEF;
403 if (memEQ(name, "S_ISCHR", 7)) {
406 *arg_result = S_ISCHR(*arg_result);
407 return PERL_constant_ISIV;
409 return PERL_constant_NOTDEF;
414 if (memEQ(name, "S_ISDIR", 7)) {
417 *arg_result = S_ISDIR(*arg_result);
418 return PERL_constant_ISIV;
420 return PERL_constant_NOTDEF;
425 if (memEQ(name, "S_ISBLK", 7)) {
428 *arg_result = S_ISBLK(*arg_result);
429 return PERL_constant_ISIV;
431 return PERL_constant_NOTDEF;
438 /* Names all of length 8. */
439 /* S_ISFIFO WSTOPSIG WTERMSIG */
440 /* Offset 3 gives the best switch position. */
443 if (memEQ(name, "WSTOPSIG", 8)) {
446 *arg_result = WSTOPSIG(*arg_result);
447 return PERL_constant_ISIV;
449 return PERL_constant_NOTDEF;
454 if (memEQ(name, "WTERMSIG", 8)) {
457 *arg_result = WTERMSIG(*arg_result);
458 return PERL_constant_ISIV;
460 return PERL_constant_NOTDEF;
465 if (memEQ(name, "S_ISFIFO", 8)) {
468 *arg_result = S_ISFIFO(*arg_result);
469 return PERL_constant_ISIV;
471 return PERL_constant_NOTDEF;
478 if (memEQ(name, "WIFEXITED", 9)) {
480 *arg_result = WIFEXITED(*arg_result);
481 return PERL_constant_ISIV;
483 return PERL_constant_NOTDEF;
488 if (memEQ(name, "WIFSTOPPED", 10)) {
490 *arg_result = WIFSTOPPED(*arg_result);
491 return PERL_constant_ISIV;
493 return PERL_constant_NOTDEF;
498 /* Names all of length 11. */
499 /* WEXITSTATUS WIFSIGNALED */
500 /* Offset 1 gives the best switch position. */
503 if (memEQ(name, "WEXITSTATUS", 11)) {
506 *arg_result = WEXITSTATUS(*arg_result);
507 return PERL_constant_ISIV;
509 return PERL_constant_NOTDEF;
514 if (memEQ(name, "WIFSIGNALED", 11)) {
517 *arg_result = WIFSIGNALED(*arg_result);
518 return PERL_constant_ISIV;
520 return PERL_constant_NOTDEF;
527 return PERL_constant_NOTFOUND;
531 restore_sigmask(pTHX_ SV *osset_sv)
533 /* Fortunately, restoring the signal mask can't fail, because
534 * there's nothing we can do about it if it does -- we're not
535 * supposed to return -1 from sigaction unless the disposition
538 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
539 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
542 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
545 new(packname = "POSIX::SigSet", ...)
550 New(0, RETVAL, 1, sigset_t);
552 for (i = 1; i < items; i++)
553 sigaddset(RETVAL, SvIV(ST(i)));
565 sigaddset(sigset, sig)
570 sigdelset(sigset, sig)
583 sigismember(sigset, sig)
588 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
591 new(packname = "POSIX::Termios", ...)
596 New(0, RETVAL, 1, struct termios);
607 POSIX::Termios termios_ref
610 Safefree(termios_ref);
616 getattr(termios_ref, fd = 0)
617 POSIX::Termios termios_ref
620 RETVAL = tcgetattr(fd, termios_ref);
625 setattr(termios_ref, fd = 0, optional_actions = 0)
626 POSIX::Termios termios_ref
630 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
635 cfgetispeed(termios_ref)
636 POSIX::Termios termios_ref
639 cfgetospeed(termios_ref)
640 POSIX::Termios termios_ref
643 getiflag(termios_ref)
644 POSIX::Termios termios_ref
646 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
647 RETVAL = termios_ref->c_iflag;
649 not_here("getiflag");
656 getoflag(termios_ref)
657 POSIX::Termios termios_ref
659 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
660 RETVAL = termios_ref->c_oflag;
662 not_here("getoflag");
669 getcflag(termios_ref)
670 POSIX::Termios termios_ref
672 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
673 RETVAL = termios_ref->c_cflag;
675 not_here("getcflag");
682 getlflag(termios_ref)
683 POSIX::Termios termios_ref
685 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
686 RETVAL = termios_ref->c_lflag;
688 not_here("getlflag");
695 getcc(termios_ref, ccix)
696 POSIX::Termios termios_ref
699 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
701 croak("Bad getcc subscript");
702 RETVAL = termios_ref->c_cc[ccix];
711 cfsetispeed(termios_ref, speed)
712 POSIX::Termios termios_ref
716 cfsetospeed(termios_ref, speed)
717 POSIX::Termios termios_ref
721 setiflag(termios_ref, iflag)
722 POSIX::Termios termios_ref
725 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
726 termios_ref->c_iflag = iflag;
728 not_here("setiflag");
732 setoflag(termios_ref, oflag)
733 POSIX::Termios termios_ref
736 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
737 termios_ref->c_oflag = oflag;
739 not_here("setoflag");
743 setcflag(termios_ref, cflag)
744 POSIX::Termios termios_ref
747 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
748 termios_ref->c_cflag = cflag;
750 not_here("setcflag");
754 setlflag(termios_ref, lflag)
755 POSIX::Termios termios_ref
758 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
759 termios_ref->c_lflag = lflag;
761 not_here("setlflag");
765 setcc(termios_ref, ccix, cc)
766 POSIX::Termios termios_ref
770 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
772 croak("Bad setcc subscript");
773 termios_ref->c_cc[ccix] = cc;
779 MODULE = POSIX PACKAGE = POSIX
781 INCLUDE: constants.xs
784 int_macro_int(sv, iv)
791 const char * s = SvPV(sv, len);
794 /* Change this to int_macro_int(s, len, &iv, &nv);
795 if you need to return both NVs and IVs */
796 type = int_macro_int(s, len, &iv);
797 /* Return 1 or 2 items. First is error message, or undef if no error.
798 Second, if present, is found value */
800 case PERL_constant_NOTFOUND:
801 sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s));
806 case PERL_constant_NOTDEF:
807 sv = sv_2mortal(newSVpvf(
808 "Your vendor has not defined POSIX macro %s, used", s));
813 case PERL_constant_ISIV:
817 sv = sv_2mortal(newSVpvf(
818 "Unexpected return type %d while processing POSIX macro %s, used",
827 unsigned char * charstring
829 unsigned char *s = charstring;
830 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
831 for (RETVAL = 1; RETVAL && s < e; s++)
839 unsigned char * charstring
841 unsigned char *s = charstring;
842 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
843 for (RETVAL = 1; RETVAL && s < e; s++)
851 unsigned char * charstring
853 unsigned char *s = charstring;
854 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
855 for (RETVAL = 1; RETVAL && s < e; s++)
863 unsigned char * charstring
865 unsigned char *s = charstring;
866 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
867 for (RETVAL = 1; RETVAL && s < e; s++)
875 unsigned char * charstring
877 unsigned char *s = charstring;
878 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
879 for (RETVAL = 1; RETVAL && s < e; s++)
887 unsigned char * charstring
889 unsigned char *s = charstring;
890 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
891 for (RETVAL = 1; RETVAL && s < e; s++)
899 unsigned char * charstring
901 unsigned char *s = charstring;
902 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
903 for (RETVAL = 1; RETVAL && s < e; s++)
911 unsigned char * charstring
913 unsigned char *s = charstring;
914 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
915 for (RETVAL = 1; RETVAL && s < e; s++)
923 unsigned char * charstring
925 unsigned char *s = charstring;
926 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
927 for (RETVAL = 1; RETVAL && s < e; s++)
935 unsigned char * charstring
937 unsigned char *s = charstring;
938 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
939 for (RETVAL = 1; RETVAL && s < e; s++)
947 unsigned char * charstring
949 unsigned char *s = charstring;
950 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
951 for (RETVAL = 1; RETVAL && s < e; s++)
958 open(filename, flags = O_RDONLY, mode = 0666)
963 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
964 TAINT_PROPER("open");
965 RETVAL = open(filename, flags, mode);
973 #ifdef HAS_LOCALECONV
976 if ((lcbuf = localeconv())) {
978 if (lcbuf->decimal_point && *lcbuf->decimal_point)
979 hv_store(RETVAL, "decimal_point", 13,
980 newSVpv(lcbuf->decimal_point, 0), 0);
981 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
982 hv_store(RETVAL, "thousands_sep", 13,
983 newSVpv(lcbuf->thousands_sep, 0), 0);
984 #ifndef NO_LOCALECONV_GROUPING
985 if (lcbuf->grouping && *lcbuf->grouping)
986 hv_store(RETVAL, "grouping", 8,
987 newSVpv(lcbuf->grouping, 0), 0);
989 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
990 hv_store(RETVAL, "int_curr_symbol", 15,
991 newSVpv(lcbuf->int_curr_symbol, 0), 0);
992 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
993 hv_store(RETVAL, "currency_symbol", 15,
994 newSVpv(lcbuf->currency_symbol, 0), 0);
995 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
996 hv_store(RETVAL, "mon_decimal_point", 17,
997 newSVpv(lcbuf->mon_decimal_point, 0), 0);
998 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
999 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
1000 hv_store(RETVAL, "mon_thousands_sep", 17,
1001 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
1003 #ifndef NO_LOCALECONV_MON_GROUPING
1004 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
1005 hv_store(RETVAL, "mon_grouping", 12,
1006 newSVpv(lcbuf->mon_grouping, 0), 0);
1008 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1009 hv_store(RETVAL, "positive_sign", 13,
1010 newSVpv(lcbuf->positive_sign, 0), 0);
1011 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1012 hv_store(RETVAL, "negative_sign", 13,
1013 newSVpv(lcbuf->negative_sign, 0), 0);
1015 if (lcbuf->int_frac_digits != CHAR_MAX)
1016 hv_store(RETVAL, "int_frac_digits", 15,
1017 newSViv(lcbuf->int_frac_digits), 0);
1018 if (lcbuf->frac_digits != CHAR_MAX)
1019 hv_store(RETVAL, "frac_digits", 11,
1020 newSViv(lcbuf->frac_digits), 0);
1021 if (lcbuf->p_cs_precedes != CHAR_MAX)
1022 hv_store(RETVAL, "p_cs_precedes", 13,
1023 newSViv(lcbuf->p_cs_precedes), 0);
1024 if (lcbuf->p_sep_by_space != CHAR_MAX)
1025 hv_store(RETVAL, "p_sep_by_space", 14,
1026 newSViv(lcbuf->p_sep_by_space), 0);
1027 if (lcbuf->n_cs_precedes != CHAR_MAX)
1028 hv_store(RETVAL, "n_cs_precedes", 13,
1029 newSViv(lcbuf->n_cs_precedes), 0);
1030 if (lcbuf->n_sep_by_space != CHAR_MAX)
1031 hv_store(RETVAL, "n_sep_by_space", 14,
1032 newSViv(lcbuf->n_sep_by_space), 0);
1033 if (lcbuf->p_sign_posn != CHAR_MAX)
1034 hv_store(RETVAL, "p_sign_posn", 11,
1035 newSViv(lcbuf->p_sign_posn), 0);
1036 if (lcbuf->n_sign_posn != CHAR_MAX)
1037 hv_store(RETVAL, "n_sign_posn", 11,
1038 newSViv(lcbuf->n_sign_posn), 0);
1041 localeconv(); /* A stub to call not_here(). */
1047 setlocale(category, locale = 0)
1051 RETVAL = setlocale(category, locale);
1053 #ifdef USE_LOCALE_CTYPE
1054 if (category == LC_CTYPE
1056 || category == LC_ALL
1062 if (category == LC_ALL)
1063 newctype = setlocale(LC_CTYPE, NULL);
1067 new_ctype(newctype);
1069 #endif /* USE_LOCALE_CTYPE */
1070 #ifdef USE_LOCALE_COLLATE
1071 if (category == LC_COLLATE
1073 || category == LC_ALL
1079 if (category == LC_ALL)
1080 newcoll = setlocale(LC_COLLATE, NULL);
1084 new_collate(newcoll);
1086 #endif /* USE_LOCALE_COLLATE */
1087 #ifdef USE_LOCALE_NUMERIC
1088 if (category == LC_NUMERIC
1090 || category == LC_ALL
1096 if (category == LC_ALL)
1097 newnum = setlocale(LC_NUMERIC, NULL);
1101 new_numeric(newnum);
1103 #endif /* USE_LOCALE_NUMERIC */
1143 /* (We already know stack is long enough.) */
1144 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1145 PUSHs(sv_2mortal(newSViv(expvar)));
1161 /* (We already know stack is long enough.) */
1162 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1163 PUSHs(sv_2mortal(newSVnv(intvar)));
1178 sigaction(sig, optaction, oldaction = 0)
1181 POSIX::SigAction oldaction
1183 #if defined(WIN32) || defined(NETWARE)
1184 RETVAL = not_here("sigaction");
1186 # This code is really grody because we're trying to make the signal
1187 # interface look beautiful, which is hard.
1190 POSIX__SigAction action;
1191 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1192 struct sigaction act;
1193 struct sigaction oact;
1197 POSIX__SigSet sigset;
1199 SV** sigsvp = hv_fetch(GvHVn(siggv),
1201 strlen(PL_sig_name[sig]),
1204 /* Check optaction and set action */
1205 if(SvTRUE(optaction)) {
1206 if(sv_isa(optaction, "POSIX::SigAction"))
1207 action = (HV*)SvRV(optaction);
1209 croak("action is not of type POSIX::SigAction");
1215 /* sigaction() is supposed to look atomic. In particular, any
1216 * signal handler invoked during a sigaction() call should
1217 * see either the old or the new disposition, and not something
1218 * in between. We use sigprocmask() to make it so.
1221 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1225 /* Restore signal mask no matter how we exit this block. */
1226 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1227 SAVEFREESV( osset_sv );
1228 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1230 RETVAL=-1; /* In case both oldaction and action are 0. */
1232 /* Remember old disposition if desired. */
1234 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
1236 croak("Can't supply an oldaction without a HANDLER");
1237 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1238 sv_setsv(*svp, *sigsvp);
1241 sv_setpv(*svp, "DEFAULT");
1243 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1246 /* Get back the mask. */
1247 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
1248 if (sv_isa(*svp, "POSIX::SigSet")) {
1249 IV tmp = SvIV((SV*)SvRV(*svp));
1250 sigset = INT2PTR(sigset_t*, tmp);
1253 New(0, sigset, 1, sigset_t);
1254 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1256 *sigset = oact.sa_mask;
1258 /* Get back the flags. */
1259 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
1260 sv_setiv(*svp, oact.sa_flags);
1264 /* Vector new handler through %SIG. (We always use sighandler
1265 for the C signal handler, which reads %SIG to dispatch.) */
1266 svp = hv_fetch(action, "HANDLER", 7, FALSE);
1268 croak("Can't supply an action without a HANDLER");
1269 sv_setsv(*sigsvp, *svp);
1270 mg_set(*sigsvp); /* handles DEFAULT and IGNORE */
1272 char *s=SvPVX(*svp);
1273 if(strEQ(s,"IGNORE")) {
1274 act.sa_handler = SIG_IGN;
1276 else if(strEQ(s,"DEFAULT")) {
1277 act.sa_handler = SIG_DFL;
1280 act.sa_handler = PL_sighandlerp;
1284 act.sa_handler = PL_sighandlerp;
1287 /* Set up any desired mask. */
1288 svp = hv_fetch(action, "MASK", 4, FALSE);
1289 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1290 IV tmp = SvIV((SV*)SvRV(*svp));
1291 sigset = INT2PTR(sigset_t*, tmp);
1292 act.sa_mask = *sigset;
1295 sigemptyset(& act.sa_mask);
1297 /* Set up any desired flags. */
1298 svp = hv_fetch(action, "FLAGS", 5, FALSE);
1299 act.sa_flags = svp ? SvIV(*svp) : 0;
1301 /* Don't worry about cleaning up *sigsvp if this fails,
1302 * because that means we tried to disposition a
1303 * nonblockable signal, in which case *sigsvp is
1304 * essentially meaningless anyway.
1306 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1319 POSIX::SigSet sigset
1322 sigprocmask(how, sigset, oldsigset = 0)
1324 POSIX::SigSet sigset
1325 POSIX::SigSet oldsigset = NO_INIT
1330 else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
1331 IV tmp = SvIV((SV*)SvRV(ST(2)));
1332 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1335 New(0, oldsigset, 1, sigset_t);
1336 sigemptyset(oldsigset);
1337 sv_setref_pv(ST(2), "POSIX::SigSet", (void*)oldsigset);
1341 sigsuspend(signal_mask)
1342 POSIX::SigSet signal_mask
1362 lseek(fd, offset, whence)
1375 if (pipe(fds) != -1) {
1377 PUSHs(sv_2mortal(newSViv(fds[0])));
1378 PUSHs(sv_2mortal(newSViv(fds[1])));
1382 read(fd, buffer, nbytes)
1384 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1388 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1391 SvCUR(sv_buffer) = RETVAL;
1392 SvPOK_only(sv_buffer);
1393 *SvEND(sv_buffer) = '\0';
1394 SvTAINTED_on(sv_buffer);
1410 tcsetpgrp(fd, pgrp_id)
1419 if (uname(&buf) >= 0) {
1421 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1422 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1423 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1424 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1425 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1428 uname((char *) 0); /* A stub to call not_here(). */
1432 write(fd, buffer, nbytes)
1443 RETVAL = newSVpvn("", 0);
1444 SvGROW(RETVAL, L_tmpnam);
1445 len = strlen(tmpnam(SvPV(RETVAL, i)));
1446 SvCUR_set(RETVAL, len);
1459 mbstowcs(s, pwcs, n)
1471 wcstombs(s, pwcs, n)
1493 SET_NUMERIC_LOCAL();
1494 num = strtod(str, &unparsed);
1495 PUSHs(sv_2mortal(newSVnv(num)));
1496 if (GIMME == G_ARRAY) {
1499 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1501 PUSHs(&PL_sv_undef);
1505 strtol(str, base = 0)
1512 num = strtol(str, &unparsed, base);
1513 #if IVSIZE <= LONGSIZE
1514 if (num < IV_MIN || num > IV_MAX)
1515 PUSHs(sv_2mortal(newSVnv((double)num)));
1518 PUSHs(sv_2mortal(newSViv((IV)num)));
1519 if (GIMME == G_ARRAY) {
1522 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1524 PUSHs(&PL_sv_undef);
1528 strtoul(str, base = 0)
1535 num = strtoul(str, &unparsed, base);
1537 PUSHs(sv_2mortal(newSViv((IV)num)));
1539 PUSHs(sv_2mortal(newSVnv((double)num)));
1540 if (GIMME == G_ARRAY) {
1543 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1545 PUSHs(&PL_sv_undef);
1555 char *p = SvPV(src,srclen);
1557 ST(0) = sv_2mortal(NEWSV(800,srclen));
1558 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1559 if (dstlen > srclen) {
1561 SvGROW(ST(0), dstlen);
1562 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1565 SvCUR(ST(0)) = dstlen;
1570 mkfifo(filename, mode)
1574 TAINT_PROPER("mkfifo");
1575 RETVAL = mkfifo(filename, mode);
1591 tcflush(fd, queue_selector)
1596 tcsendbreak(fd, duration)
1601 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1614 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1617 mytm.tm_hour = hour;
1618 mytm.tm_mday = mday;
1620 mytm.tm_year = year;
1621 mytm.tm_wday = wday;
1622 mytm.tm_yday = yday;
1623 mytm.tm_isdst = isdst;
1624 RETVAL = asctime(&mytm);
1641 realtime = times( &tms );
1643 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1644 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1645 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1646 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1647 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1650 difftime(time1, time2)
1655 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1668 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1671 mytm.tm_hour = hour;
1672 mytm.tm_mday = mday;
1674 mytm.tm_year = year;
1675 mytm.tm_wday = wday;
1676 mytm.tm_yday = yday;
1677 mytm.tm_isdst = isdst;
1678 RETVAL = mktime(&mytm);
1683 #XXX: if $xsubpp::WantOptimize is always the default
1684 # sv_setpv(TARG, ...) could be used rather than
1685 # ST(0) = sv_2mortal(newSVpv(...))
1687 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1700 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1702 ST(0) = sv_2mortal(newSVpv(buf, 0));
1714 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1715 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1718 access(filename, mode)
1736 pathconf(filename, name)
1765 XSprePUSH; PUSHTARG;