8 * Ideally this should be somewhere down in the includes
9 * but putting it in other places is giving compiler errors.
10 * Also here I am unable to check for HAS_UNAME since it wouldn't have
11 * yet come into the file at this stage - sgp 18th Oct 2000
13 #include <sys/utsname.h>
16 #define PERL_NO_GET_CONTEXT
19 #define PERLIO_NOT_STDIO 1
22 #if defined(PERL_IMPLICIT_SYS)
26 # define open PerlLIO_open3
29 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
56 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
57 metaconfig for future extension writers. We don't use them in POSIX.
58 (This is really sneaky :-) --AD
60 #if defined(I_TERMIOS)
68 #include <sys/types.h>
73 #ifdef MACOS_TRADITIONAL
79 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE)
80 extern char *tzname[];
83 #if !defined(WIN32) || (defined(__MINGW32__) && !defined(tzname))
84 char *tzname[] = { "" , "" };
88 #if defined(__VMS) && !defined(__POSIX_SOURCE)
89 # include <libdef.h> /* LIB$_INVARG constant */
90 # include <lib$routines.h> /* prototype for lib$ediv() */
91 # include <starlet.h> /* prototype for sys$gettim() */
92 # if DECC_VERSION < 50000000
93 # define pid_t int /* old versions of DECC miss this in types.h */
97 # define mkfifo(a,b) (not_here("mkfifo"),-1)
98 # define tzset() not_here("tzset")
100 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
101 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
102 # include <utsname.h>
103 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
105 /* The POSIX notion of ttyname() is better served by getname() under VMS */
106 static char ttnambuf[64];
107 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
109 /* The non-POSIX CRTL times() has void return type, so we just get the
110 current time directly */
111 clock_t vms_times(struct tms *bufptr) {
114 /* Get wall time and convert to 10 ms intervals to
115 * produce the return value that the POSIX standard expects */
116 # if defined(__DECC) && defined (__ALPHA)
119 _ckvmssts(sys$gettim(&vmstime));
121 retval = vmstime & 0x7fffffff;
123 /* (Older hw or ccs don't have an atomic 64-bit type, so we
124 * juggle 32-bit ints (and a float) to produce a time_t result
125 * with minimal loss of information.) */
126 long int vmstime[2],remainder,divisor = 100000;
127 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
128 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
129 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
131 /* Fill in the struct tms using the CRTL routine . . .*/
132 times((tbuffer_t *)bufptr);
133 return (clock_t) retval;
135 # define times(t) vms_times(t)
137 #if defined (__CYGWIN__)
138 # define tzname _tzname
140 #if defined (WIN32) || defined (NETWARE)
142 # define mkfifo(a,b) not_here("mkfifo")
143 # define ttyname(a) (char*)not_here("ttyname")
144 # define sigset_t long
147 # define tzname _tzname
150 # define mode_t short
153 # define mode_t short
155 # define tzset() not_here("tzset")
157 # ifndef _POSIX_OPEN_MAX
158 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
161 # define sigaction(a,b,c) not_here("sigaction")
162 # define sigpending(a) not_here("sigpending")
163 # define sigprocmask(a,b,c) not_here("sigprocmask")
164 # define sigsuspend(a) not_here("sigsuspend")
165 # define sigemptyset(a) not_here("sigemptyset")
166 # define sigaddset(a,b) not_here("sigaddset")
167 # define sigdelset(a,b) not_here("sigdelset")
168 # define sigfillset(a) not_here("sigfillset")
169 # define sigismember(a,b) not_here("sigismember")
171 # define setuid(a) not_here("setuid")
172 # define setgid(a) not_here("setgid")
177 # if defined(OS2) || defined(MACOS_TRADITIONAL)
178 # define mkfifo(a,b) not_here("mkfifo")
179 # else /* !( defined OS2 ) */
181 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
184 # endif /* !HAS_MKFIFO */
186 # ifdef MACOS_TRADITIONAL
187 # define ttyname(a) (char*)not_here("ttyname")
188 # define tzset() not_here("tzset")
191 # include <sys/times.h>
193 # include <sys/utsname.h>
195 # include <sys/wait.h>
200 #endif /* WIN32 || NETWARE */
204 typedef long SysRetLong;
205 typedef sigset_t* POSIX__SigSet;
206 typedef HV* POSIX__SigAction;
208 typedef struct termios* POSIX__Termios;
209 #else /* Define termios types to int, and call not_here for the functions.*/
210 #define POSIX__Termios int
214 #define cfgetispeed(x) not_here("cfgetispeed")
215 #define cfgetospeed(x) not_here("cfgetospeed")
216 #define tcdrain(x) not_here("tcdrain")
217 #define tcflush(x,y) not_here("tcflush")
218 #define tcsendbreak(x,y) not_here("tcsendbreak")
219 #define cfsetispeed(x,y) not_here("cfsetispeed")
220 #define cfsetospeed(x,y) not_here("cfsetospeed")
221 #define ctermid(x) (char *) not_here("ctermid")
222 #define tcflow(x,y) not_here("tcflow")
223 #define tcgetattr(x,y) not_here("tcgetattr")
224 #define tcsetattr(x,y,z) not_here("tcsetattr")
227 /* Possibly needed prototypes */
228 char *cuserid (char *);
229 double strtod (const char *, char **);
230 long strtol (const char *, char **, int);
231 unsigned long strtoul (const char *, char **, int);
234 #define cuserid(a) (char *) not_here("cuserid")
238 #define difftime(a,b) not_here("difftime")
241 #ifndef HAS_FPATHCONF
242 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
245 #define mktime(a) not_here("mktime")
248 #define nice(a) not_here("nice")
251 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
254 #define sysconf(n) (SysRetLong) not_here("sysconf")
257 #define readlink(a,b,c) not_here("readlink")
260 #define setpgid(a,b) not_here("setpgid")
263 #define setsid() not_here("setsid")
266 #define strcoll(s1,s2) not_here("strcoll")
269 #define strtod(s1,s2) not_here("strtod")
272 #define strtol(s1,s2,b) not_here("strtol")
275 #define strtoul(s1,s2,b) not_here("strtoul")
278 #define strxfrm(s1,s2,n) not_here("strxfrm")
280 #ifndef HAS_TCGETPGRP
281 #define tcgetpgrp(a) not_here("tcgetpgrp")
283 #ifndef HAS_TCSETPGRP
284 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
288 #define times(a) not_here("times")
292 #define uname(a) not_here("uname")
295 #define waitpid(a,b,c) not_here("waitpid")
300 #define mblen(a,b) not_here("mblen")
304 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
307 #define mbtowc(pwc, s, n) not_here("mbtowc")
310 #define wcstombs(s, pwcs, n) not_here("wcstombs")
313 #define wctomb(s, wchar) not_here("wcstombs")
315 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
316 /* If we don't have these functions, then we wouldn't have gotten a typedef
317 for wchar_t, the wide character type. Defining wchar_t allows the
318 functions referencing it to compile. Its actual type is then meaningless,
319 since without the above functions, all sections using it end up calling
320 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
326 #ifndef HAS_LOCALECONV
327 #define localeconv() not_here("localeconv")
330 #ifdef HAS_LONG_DOUBLE
331 # if LONG_DOUBLESIZE > NVSIZE
332 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
336 #ifndef HAS_LONG_DOUBLE
351 croak("POSIX::%s not implemented on this architecture", s);
355 #include "constants.c"
357 /* These were implemented in the old "constant" subroutine. They are actually
358 macros that take an integer argument and return an integer result. */
360 int_macro_int (const char *name, STRLEN len, IV *arg_result) {
361 /* Initially switch on the length of the name. */
362 /* This code has been edited from a "constant" function generated by:
364 use ExtUtils::Constant qw (constant_types C_constant XS_constant);
366 my $types = {map {($_, 1)} qw(IV)};
367 my @names = (qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS WIFEXITED
368 WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
370 print constant_types(); # macro defs
371 foreach (C_constant ("POSIX", 'int_macro_int', 'IV', $types, undef, 5, @names) ) {
372 print $_, "\n"; # C constant subs
374 print "#### XS Section:\n";
375 print XS_constant ("POSIX", $types);
381 /* Names all of length 7. */
382 /* S_ISBLK S_ISCHR S_ISDIR S_ISREG */
383 /* Offset 5 gives the best switch position. */
386 if (memEQ(name, "S_ISREG", 7)) {
389 *arg_result = S_ISREG(*arg_result);
390 return PERL_constant_ISIV;
392 return PERL_constant_NOTDEF;
397 if (memEQ(name, "S_ISCHR", 7)) {
400 *arg_result = S_ISCHR(*arg_result);
401 return PERL_constant_ISIV;
403 return PERL_constant_NOTDEF;
408 if (memEQ(name, "S_ISDIR", 7)) {
411 *arg_result = S_ISDIR(*arg_result);
412 return PERL_constant_ISIV;
414 return PERL_constant_NOTDEF;
419 if (memEQ(name, "S_ISBLK", 7)) {
422 *arg_result = S_ISBLK(*arg_result);
423 return PERL_constant_ISIV;
425 return PERL_constant_NOTDEF;
432 /* Names all of length 8. */
433 /* S_ISFIFO WSTOPSIG WTERMSIG */
434 /* Offset 3 gives the best switch position. */
437 if (memEQ(name, "WSTOPSIG", 8)) {
440 *arg_result = WSTOPSIG(*arg_result);
441 return PERL_constant_ISIV;
443 return PERL_constant_NOTDEF;
448 if (memEQ(name, "WTERMSIG", 8)) {
451 *arg_result = WTERMSIG(*arg_result);
452 return PERL_constant_ISIV;
454 return PERL_constant_NOTDEF;
459 if (memEQ(name, "S_ISFIFO", 8)) {
462 *arg_result = S_ISFIFO(*arg_result);
463 return PERL_constant_ISIV;
465 return PERL_constant_NOTDEF;
472 if (memEQ(name, "WIFEXITED", 9)) {
474 *arg_result = WIFEXITED(*arg_result);
475 return PERL_constant_ISIV;
477 return PERL_constant_NOTDEF;
482 if (memEQ(name, "WIFSTOPPED", 10)) {
484 *arg_result = WIFSTOPPED(*arg_result);
485 return PERL_constant_ISIV;
487 return PERL_constant_NOTDEF;
492 /* Names all of length 11. */
493 /* WEXITSTATUS WIFSIGNALED */
494 /* Offset 1 gives the best switch position. */
497 if (memEQ(name, "WEXITSTATUS", 11)) {
500 *arg_result = WEXITSTATUS(*arg_result);
501 return PERL_constant_ISIV;
503 return PERL_constant_NOTDEF;
508 if (memEQ(name, "WIFSIGNALED", 11)) {
511 *arg_result = WIFSIGNALED(*arg_result);
512 return PERL_constant_ISIV;
514 return PERL_constant_NOTDEF;
521 return PERL_constant_NOTFOUND;
525 restore_sigmask(pTHX_ SV *osset_sv)
527 /* Fortunately, restoring the signal mask can't fail, because
528 * there's nothing we can do about it if it does -- we're not
529 * supposed to return -1 from sigaction unless the disposition
532 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
533 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
536 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
539 new(packname = "POSIX::SigSet", ...)
544 New(0, RETVAL, 1, sigset_t);
546 for (i = 1; i < items; i++)
547 sigaddset(RETVAL, SvIV(ST(i)));
559 sigaddset(sigset, sig)
564 sigdelset(sigset, sig)
577 sigismember(sigset, sig)
582 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
585 new(packname = "POSIX::Termios", ...)
590 New(0, RETVAL, 1, struct termios);
601 POSIX::Termios termios_ref
604 Safefree(termios_ref);
610 getattr(termios_ref, fd = 0)
611 POSIX::Termios termios_ref
614 RETVAL = tcgetattr(fd, termios_ref);
619 setattr(termios_ref, fd = 0, optional_actions = 0)
620 POSIX::Termios termios_ref
624 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
629 cfgetispeed(termios_ref)
630 POSIX::Termios termios_ref
633 cfgetospeed(termios_ref)
634 POSIX::Termios termios_ref
637 getiflag(termios_ref)
638 POSIX::Termios termios_ref
640 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
641 RETVAL = termios_ref->c_iflag;
643 not_here("getiflag");
650 getoflag(termios_ref)
651 POSIX::Termios termios_ref
653 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
654 RETVAL = termios_ref->c_oflag;
656 not_here("getoflag");
663 getcflag(termios_ref)
664 POSIX::Termios termios_ref
666 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
667 RETVAL = termios_ref->c_cflag;
669 not_here("getcflag");
676 getlflag(termios_ref)
677 POSIX::Termios termios_ref
679 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
680 RETVAL = termios_ref->c_lflag;
682 not_here("getlflag");
689 getcc(termios_ref, ccix)
690 POSIX::Termios termios_ref
693 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
695 croak("Bad getcc subscript");
696 RETVAL = termios_ref->c_cc[ccix];
705 cfsetispeed(termios_ref, speed)
706 POSIX::Termios termios_ref
710 cfsetospeed(termios_ref, speed)
711 POSIX::Termios termios_ref
715 setiflag(termios_ref, iflag)
716 POSIX::Termios termios_ref
719 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
720 termios_ref->c_iflag = iflag;
722 not_here("setiflag");
726 setoflag(termios_ref, oflag)
727 POSIX::Termios termios_ref
730 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
731 termios_ref->c_oflag = oflag;
733 not_here("setoflag");
737 setcflag(termios_ref, cflag)
738 POSIX::Termios termios_ref
741 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
742 termios_ref->c_cflag = cflag;
744 not_here("setcflag");
748 setlflag(termios_ref, lflag)
749 POSIX::Termios termios_ref
752 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
753 termios_ref->c_lflag = lflag;
755 not_here("setlflag");
759 setcc(termios_ref, ccix, cc)
760 POSIX::Termios termios_ref
764 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
766 croak("Bad setcc subscript");
767 termios_ref->c_cc[ccix] = cc;
773 MODULE = POSIX PACKAGE = POSIX
775 INCLUDE: constants.xs
778 int_macro_int(sv, iv)
785 const char * s = SvPV(sv, len);
788 /* Change this to int_macro_int(s, len, &iv, &nv);
789 if you need to return both NVs and IVs */
790 type = int_macro_int(s, len, &iv);
791 /* Return 1 or 2 items. First is error message, or undef if no error.
792 Second, if present, is found value */
794 case PERL_constant_NOTFOUND:
795 sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s));
800 case PERL_constant_NOTDEF:
801 sv = sv_2mortal(newSVpvf(
802 "Your vendor has not defined POSIX macro %s, used", s));
807 case PERL_constant_ISIV:
811 sv = sv_2mortal(newSVpvf(
812 "Unexpected return type %d while processing POSIX macro %s, used",
821 unsigned char * charstring
823 unsigned char *s = charstring;
824 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
825 for (RETVAL = 1; RETVAL && s < e; s++)
833 unsigned char * charstring
835 unsigned char *s = charstring;
836 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
837 for (RETVAL = 1; RETVAL && s < e; s++)
845 unsigned char * charstring
847 unsigned char *s = charstring;
848 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
849 for (RETVAL = 1; RETVAL && s < e; s++)
857 unsigned char * charstring
859 unsigned char *s = charstring;
860 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
861 for (RETVAL = 1; RETVAL && s < e; s++)
869 unsigned char * charstring
871 unsigned char *s = charstring;
872 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
873 for (RETVAL = 1; RETVAL && s < e; s++)
881 unsigned char * charstring
883 unsigned char *s = charstring;
884 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
885 for (RETVAL = 1; RETVAL && s < e; s++)
893 unsigned char * charstring
895 unsigned char *s = charstring;
896 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
897 for (RETVAL = 1; RETVAL && s < e; s++)
905 unsigned char * charstring
907 unsigned char *s = charstring;
908 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
909 for (RETVAL = 1; RETVAL && s < e; s++)
917 unsigned char * charstring
919 unsigned char *s = charstring;
920 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
921 for (RETVAL = 1; RETVAL && s < e; s++)
929 unsigned char * charstring
931 unsigned char *s = charstring;
932 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
933 for (RETVAL = 1; RETVAL && s < e; s++)
941 unsigned char * charstring
943 unsigned char *s = charstring;
944 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
945 for (RETVAL = 1; RETVAL && s < e; s++)
952 open(filename, flags = O_RDONLY, mode = 0666)
957 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
958 TAINT_PROPER("open");
959 RETVAL = open(filename, flags, mode);
967 #ifdef HAS_LOCALECONV
970 if ((lcbuf = localeconv())) {
972 if (lcbuf->decimal_point && *lcbuf->decimal_point)
973 hv_store(RETVAL, "decimal_point", 13,
974 newSVpv(lcbuf->decimal_point, 0), 0);
975 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
976 hv_store(RETVAL, "thousands_sep", 13,
977 newSVpv(lcbuf->thousands_sep, 0), 0);
978 #ifndef NO_LOCALECONV_GROUPING
979 if (lcbuf->grouping && *lcbuf->grouping)
980 hv_store(RETVAL, "grouping", 8,
981 newSVpv(lcbuf->grouping, 0), 0);
983 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
984 hv_store(RETVAL, "int_curr_symbol", 15,
985 newSVpv(lcbuf->int_curr_symbol, 0), 0);
986 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
987 hv_store(RETVAL, "currency_symbol", 15,
988 newSVpv(lcbuf->currency_symbol, 0), 0);
989 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
990 hv_store(RETVAL, "mon_decimal_point", 17,
991 newSVpv(lcbuf->mon_decimal_point, 0), 0);
992 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
993 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
994 hv_store(RETVAL, "mon_thousands_sep", 17,
995 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
997 #ifndef NO_LOCALECONV_MON_GROUPING
998 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
999 hv_store(RETVAL, "mon_grouping", 12,
1000 newSVpv(lcbuf->mon_grouping, 0), 0);
1002 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1003 hv_store(RETVAL, "positive_sign", 13,
1004 newSVpv(lcbuf->positive_sign, 0), 0);
1005 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1006 hv_store(RETVAL, "negative_sign", 13,
1007 newSVpv(lcbuf->negative_sign, 0), 0);
1009 if (lcbuf->int_frac_digits != CHAR_MAX)
1010 hv_store(RETVAL, "int_frac_digits", 15,
1011 newSViv(lcbuf->int_frac_digits), 0);
1012 if (lcbuf->frac_digits != CHAR_MAX)
1013 hv_store(RETVAL, "frac_digits", 11,
1014 newSViv(lcbuf->frac_digits), 0);
1015 if (lcbuf->p_cs_precedes != CHAR_MAX)
1016 hv_store(RETVAL, "p_cs_precedes", 13,
1017 newSViv(lcbuf->p_cs_precedes), 0);
1018 if (lcbuf->p_sep_by_space != CHAR_MAX)
1019 hv_store(RETVAL, "p_sep_by_space", 14,
1020 newSViv(lcbuf->p_sep_by_space), 0);
1021 if (lcbuf->n_cs_precedes != CHAR_MAX)
1022 hv_store(RETVAL, "n_cs_precedes", 13,
1023 newSViv(lcbuf->n_cs_precedes), 0);
1024 if (lcbuf->n_sep_by_space != CHAR_MAX)
1025 hv_store(RETVAL, "n_sep_by_space", 14,
1026 newSViv(lcbuf->n_sep_by_space), 0);
1027 if (lcbuf->p_sign_posn != CHAR_MAX)
1028 hv_store(RETVAL, "p_sign_posn", 11,
1029 newSViv(lcbuf->p_sign_posn), 0);
1030 if (lcbuf->n_sign_posn != CHAR_MAX)
1031 hv_store(RETVAL, "n_sign_posn", 11,
1032 newSViv(lcbuf->n_sign_posn), 0);
1035 localeconv(); /* A stub to call not_here(). */
1041 setlocale(category, locale = 0)
1045 RETVAL = setlocale(category, locale);
1047 #ifdef USE_LOCALE_CTYPE
1048 if (category == LC_CTYPE
1050 || category == LC_ALL
1056 if (category == LC_ALL)
1057 newctype = setlocale(LC_CTYPE, NULL);
1061 new_ctype(newctype);
1063 #endif /* USE_LOCALE_CTYPE */
1064 #ifdef USE_LOCALE_COLLATE
1065 if (category == LC_COLLATE
1067 || category == LC_ALL
1073 if (category == LC_ALL)
1074 newcoll = setlocale(LC_COLLATE, NULL);
1078 new_collate(newcoll);
1080 #endif /* USE_LOCALE_COLLATE */
1081 #ifdef USE_LOCALE_NUMERIC
1082 if (category == LC_NUMERIC
1084 || category == LC_ALL
1090 if (category == LC_ALL)
1091 newnum = setlocale(LC_NUMERIC, NULL);
1095 new_numeric(newnum);
1097 #endif /* USE_LOCALE_NUMERIC */
1137 /* (We already know stack is long enough.) */
1138 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1139 PUSHs(sv_2mortal(newSViv(expvar)));
1155 /* (We already know stack is long enough.) */
1156 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1157 PUSHs(sv_2mortal(newSVnv(intvar)));
1172 sigaction(sig, optaction, oldaction = 0)
1175 POSIX::SigAction oldaction
1177 #if defined(WIN32) || defined(NETWARE)
1178 RETVAL = not_here("sigaction");
1180 # This code is really grody because we're trying to make the signal
1181 # interface look beautiful, which is hard.
1184 POSIX__SigAction action;
1185 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1186 struct sigaction act;
1187 struct sigaction oact;
1191 POSIX__SigSet sigset;
1193 SV** sigsvp = hv_fetch(GvHVn(siggv),
1195 strlen(PL_sig_name[sig]),
1198 /* Check optaction and set action */
1199 if(SvTRUE(optaction)) {
1200 if(sv_isa(optaction, "POSIX::SigAction"))
1201 action = (HV*)SvRV(optaction);
1203 croak("action is not of type POSIX::SigAction");
1209 /* sigaction() is supposed to look atomic. In particular, any
1210 * signal handler invoked during a sigaction() call should
1211 * see either the old or the new disposition, and not something
1212 * in between. We use sigprocmask() to make it so.
1215 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1219 /* Restore signal mask no matter how we exit this block. */
1220 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1221 SAVEFREESV( osset_sv );
1222 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1224 RETVAL=-1; /* In case both oldaction and action are 0. */
1226 /* Remember old disposition if desired. */
1228 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
1230 croak("Can't supply an oldaction without a HANDLER");
1231 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1232 sv_setsv(*svp, *sigsvp);
1235 sv_setpv(*svp, "DEFAULT");
1237 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1240 /* Get back the mask. */
1241 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
1242 if (sv_isa(*svp, "POSIX::SigSet")) {
1243 IV tmp = SvIV((SV*)SvRV(*svp));
1244 sigset = INT2PTR(sigset_t*, tmp);
1247 New(0, sigset, 1, sigset_t);
1248 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1250 *sigset = oact.sa_mask;
1252 /* Get back the flags. */
1253 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
1254 sv_setiv(*svp, oact.sa_flags);
1258 /* Vector new handler through %SIG. (We always use sighandler
1259 for the C signal handler, which reads %SIG to dispatch.) */
1260 svp = hv_fetch(action, "HANDLER", 7, FALSE);
1262 croak("Can't supply an action without a HANDLER");
1263 sv_setsv(*sigsvp, *svp);
1264 mg_set(*sigsvp); /* handles DEFAULT and IGNORE */
1266 char *s=SvPVX(*svp);
1267 if(strEQ(s,"IGNORE")) {
1268 act.sa_handler = SIG_IGN;
1270 else if(strEQ(s,"DEFAULT")) {
1271 act.sa_handler = SIG_DFL;
1274 act.sa_handler = PL_sighandlerp;
1278 act.sa_handler = PL_sighandlerp;
1281 /* Set up any desired mask. */
1282 svp = hv_fetch(action, "MASK", 4, FALSE);
1283 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1284 IV tmp = SvIV((SV*)SvRV(*svp));
1285 sigset = INT2PTR(sigset_t*, tmp);
1286 act.sa_mask = *sigset;
1289 sigemptyset(& act.sa_mask);
1291 /* Set up any desired flags. */
1292 svp = hv_fetch(action, "FLAGS", 5, FALSE);
1293 act.sa_flags = svp ? SvIV(*svp) : 0;
1295 /* Don't worry about cleaning up *sigsvp if this fails,
1296 * because that means we tried to disposition a
1297 * nonblockable signal, in which case *sigsvp is
1298 * essentially meaningless anyway.
1300 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1313 POSIX::SigSet sigset
1316 sigprocmask(how, sigset, oldsigset = 0)
1318 POSIX::SigSet sigset
1319 POSIX::SigSet oldsigset = NO_INIT
1324 else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
1325 IV tmp = SvIV((SV*)SvRV(ST(2)));
1326 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1329 New(0, oldsigset, 1, sigset_t);
1330 sigemptyset(oldsigset);
1331 sv_setref_pv(ST(2), "POSIX::SigSet", (void*)oldsigset);
1335 sigsuspend(signal_mask)
1336 POSIX::SigSet signal_mask
1356 lseek(fd, offset, whence)
1369 if (pipe(fds) != -1) {
1371 PUSHs(sv_2mortal(newSViv(fds[0])));
1372 PUSHs(sv_2mortal(newSViv(fds[1])));
1376 read(fd, buffer, nbytes)
1378 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1382 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1385 SvCUR(sv_buffer) = RETVAL;
1386 SvPOK_only(sv_buffer);
1387 *SvEND(sv_buffer) = '\0';
1388 SvTAINTED_on(sv_buffer);
1404 tcsetpgrp(fd, pgrp_id)
1413 if (uname(&buf) >= 0) {
1415 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1416 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1417 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1418 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1419 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1422 uname((char *) 0); /* A stub to call not_here(). */
1426 write(fd, buffer, nbytes)
1437 RETVAL = newSVpvn("", 0);
1438 SvGROW(RETVAL, L_tmpnam);
1439 len = strlen(tmpnam(SvPV(RETVAL, i)));
1440 SvCUR_set(RETVAL, len);
1453 mbstowcs(s, pwcs, n)
1465 wcstombs(s, pwcs, n)
1487 SET_NUMERIC_LOCAL();
1488 num = strtod(str, &unparsed);
1489 PUSHs(sv_2mortal(newSVnv(num)));
1490 if (GIMME == G_ARRAY) {
1493 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1495 PUSHs(&PL_sv_undef);
1499 strtol(str, base = 0)
1506 num = strtol(str, &unparsed, base);
1507 #if IVSIZE <= LONGSIZE
1508 if (num < IV_MIN || num > IV_MAX)
1509 PUSHs(sv_2mortal(newSVnv((double)num)));
1512 PUSHs(sv_2mortal(newSViv((IV)num)));
1513 if (GIMME == G_ARRAY) {
1516 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1518 PUSHs(&PL_sv_undef);
1522 strtoul(str, base = 0)
1529 num = strtoul(str, &unparsed, base);
1531 PUSHs(sv_2mortal(newSViv((IV)num)));
1533 PUSHs(sv_2mortal(newSVnv((double)num)));
1534 if (GIMME == G_ARRAY) {
1537 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1539 PUSHs(&PL_sv_undef);
1549 char *p = SvPV(src,srclen);
1551 ST(0) = sv_2mortal(NEWSV(800,srclen));
1552 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1553 if (dstlen > srclen) {
1555 SvGROW(ST(0), dstlen);
1556 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1559 SvCUR(ST(0)) = dstlen;
1564 mkfifo(filename, mode)
1568 TAINT_PROPER("mkfifo");
1569 RETVAL = mkfifo(filename, mode);
1585 tcflush(fd, queue_selector)
1590 tcsendbreak(fd, duration)
1595 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1608 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1611 mytm.tm_hour = hour;
1612 mytm.tm_mday = mday;
1614 mytm.tm_year = year;
1615 mytm.tm_wday = wday;
1616 mytm.tm_yday = yday;
1617 mytm.tm_isdst = isdst;
1618 RETVAL = asctime(&mytm);
1635 realtime = times( &tms );
1637 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1638 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1639 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1640 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1641 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1644 difftime(time1, time2)
1649 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1662 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1665 mytm.tm_hour = hour;
1666 mytm.tm_mday = mday;
1668 mytm.tm_year = year;
1669 mytm.tm_wday = wday;
1670 mytm.tm_yday = yday;
1671 mytm.tm_isdst = isdst;
1672 RETVAL = mktime(&mytm);
1677 #XXX: if $xsubpp::WantOptimize is always the default
1678 # sv_setpv(TARG, ...) could be used rather than
1679 # ST(0) = sv_2mortal(newSVpv(...))
1681 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1694 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1696 ST(0) = sv_2mortal(newSVpv(buf, 0));
1708 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1709 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1712 access(filename, mode)
1730 pathconf(filename, name)
1759 XSprePUSH; PUSHTARG;