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_OBJECT) || defined(PERL_CAPI) || 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(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
533 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
534 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
537 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
540 new(packname = "POSIX::SigSet", ...)
545 New(0, RETVAL, 1, sigset_t);
547 for (i = 1; i < items; i++)
548 sigaddset(RETVAL, SvIV(ST(i)));
560 sigaddset(sigset, sig)
565 sigdelset(sigset, sig)
578 sigismember(sigset, sig)
583 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
586 new(packname = "POSIX::Termios", ...)
591 New(0, RETVAL, 1, struct termios);
602 POSIX::Termios termios_ref
605 Safefree(termios_ref);
611 getattr(termios_ref, fd = 0)
612 POSIX::Termios termios_ref
615 RETVAL = tcgetattr(fd, termios_ref);
620 setattr(termios_ref, fd = 0, optional_actions = 0)
621 POSIX::Termios termios_ref
625 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
630 cfgetispeed(termios_ref)
631 POSIX::Termios termios_ref
634 cfgetospeed(termios_ref)
635 POSIX::Termios termios_ref
638 getiflag(termios_ref)
639 POSIX::Termios termios_ref
641 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
642 RETVAL = termios_ref->c_iflag;
644 not_here("getiflag");
651 getoflag(termios_ref)
652 POSIX::Termios termios_ref
654 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
655 RETVAL = termios_ref->c_oflag;
657 not_here("getoflag");
664 getcflag(termios_ref)
665 POSIX::Termios termios_ref
667 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
668 RETVAL = termios_ref->c_cflag;
670 not_here("getcflag");
677 getlflag(termios_ref)
678 POSIX::Termios termios_ref
680 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
681 RETVAL = termios_ref->c_lflag;
683 not_here("getlflag");
690 getcc(termios_ref, ccix)
691 POSIX::Termios termios_ref
694 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
696 croak("Bad getcc subscript");
697 RETVAL = termios_ref->c_cc[ccix];
706 cfsetispeed(termios_ref, speed)
707 POSIX::Termios termios_ref
711 cfsetospeed(termios_ref, speed)
712 POSIX::Termios termios_ref
716 setiflag(termios_ref, iflag)
717 POSIX::Termios termios_ref
720 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
721 termios_ref->c_iflag = iflag;
723 not_here("setiflag");
727 setoflag(termios_ref, oflag)
728 POSIX::Termios termios_ref
731 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
732 termios_ref->c_oflag = oflag;
734 not_here("setoflag");
738 setcflag(termios_ref, cflag)
739 POSIX::Termios termios_ref
742 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
743 termios_ref->c_cflag = cflag;
745 not_here("setcflag");
749 setlflag(termios_ref, lflag)
750 POSIX::Termios termios_ref
753 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
754 termios_ref->c_lflag = lflag;
756 not_here("setlflag");
760 setcc(termios_ref, ccix, cc)
761 POSIX::Termios termios_ref
765 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
767 croak("Bad setcc subscript");
768 termios_ref->c_cc[ccix] = cc;
774 MODULE = POSIX PACKAGE = POSIX
776 INCLUDE: constants.xs
779 int_macro_int(sv, iv)
786 const char * s = SvPV(sv, len);
789 /* Change this to int_macro_int(s, len, &iv, &nv);
790 if you need to return both NVs and IVs */
791 type = int_macro_int(s, len, &iv);
792 /* Return 1 or 2 items. First is error message, or undef if no error.
793 Second, if present, is found value */
795 case PERL_constant_NOTFOUND:
796 sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s));
801 case PERL_constant_NOTDEF:
802 sv = sv_2mortal(newSVpvf(
803 "Your vendor has not defined POSIX macro %s, used", s));
808 case PERL_constant_ISIV:
812 sv = sv_2mortal(newSVpvf(
813 "Unexpected return type %d while processing POSIX macro %s, used",
822 unsigned char * charstring
824 unsigned char *s = charstring;
825 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
826 for (RETVAL = 1; RETVAL && s < e; s++)
834 unsigned char * charstring
836 unsigned char *s = charstring;
837 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
838 for (RETVAL = 1; RETVAL && s < e; s++)
846 unsigned char * charstring
848 unsigned char *s = charstring;
849 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
850 for (RETVAL = 1; RETVAL && s < e; s++)
858 unsigned char * charstring
860 unsigned char *s = charstring;
861 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
862 for (RETVAL = 1; RETVAL && s < e; s++)
870 unsigned char * charstring
872 unsigned char *s = charstring;
873 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
874 for (RETVAL = 1; RETVAL && s < e; s++)
882 unsigned char * charstring
884 unsigned char *s = charstring;
885 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
886 for (RETVAL = 1; RETVAL && s < e; s++)
894 unsigned char * charstring
896 unsigned char *s = charstring;
897 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
898 for (RETVAL = 1; RETVAL && s < e; s++)
906 unsigned char * charstring
908 unsigned char *s = charstring;
909 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
910 for (RETVAL = 1; RETVAL && s < e; s++)
918 unsigned char * charstring
920 unsigned char *s = charstring;
921 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
922 for (RETVAL = 1; RETVAL && s < e; s++)
930 unsigned char * charstring
932 unsigned char *s = charstring;
933 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
934 for (RETVAL = 1; RETVAL && s < e; s++)
942 unsigned char * charstring
944 unsigned char *s = charstring;
945 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
946 for (RETVAL = 1; RETVAL && s < e; s++)
953 open(filename, flags = O_RDONLY, mode = 0666)
958 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
959 TAINT_PROPER("open");
960 RETVAL = open(filename, flags, mode);
968 #ifdef HAS_LOCALECONV
971 if ((lcbuf = localeconv())) {
973 if (lcbuf->decimal_point && *lcbuf->decimal_point)
974 hv_store(RETVAL, "decimal_point", 13,
975 newSVpv(lcbuf->decimal_point, 0), 0);
976 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
977 hv_store(RETVAL, "thousands_sep", 13,
978 newSVpv(lcbuf->thousands_sep, 0), 0);
979 #ifndef NO_LOCALECONV_GROUPING
980 if (lcbuf->grouping && *lcbuf->grouping)
981 hv_store(RETVAL, "grouping", 8,
982 newSVpv(lcbuf->grouping, 0), 0);
984 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
985 hv_store(RETVAL, "int_curr_symbol", 15,
986 newSVpv(lcbuf->int_curr_symbol, 0), 0);
987 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
988 hv_store(RETVAL, "currency_symbol", 15,
989 newSVpv(lcbuf->currency_symbol, 0), 0);
990 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
991 hv_store(RETVAL, "mon_decimal_point", 17,
992 newSVpv(lcbuf->mon_decimal_point, 0), 0);
993 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
994 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
995 hv_store(RETVAL, "mon_thousands_sep", 17,
996 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
998 #ifndef NO_LOCALECONV_MON_GROUPING
999 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
1000 hv_store(RETVAL, "mon_grouping", 12,
1001 newSVpv(lcbuf->mon_grouping, 0), 0);
1003 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1004 hv_store(RETVAL, "positive_sign", 13,
1005 newSVpv(lcbuf->positive_sign, 0), 0);
1006 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1007 hv_store(RETVAL, "negative_sign", 13,
1008 newSVpv(lcbuf->negative_sign, 0), 0);
1010 if (lcbuf->int_frac_digits != CHAR_MAX)
1011 hv_store(RETVAL, "int_frac_digits", 15,
1012 newSViv(lcbuf->int_frac_digits), 0);
1013 if (lcbuf->frac_digits != CHAR_MAX)
1014 hv_store(RETVAL, "frac_digits", 11,
1015 newSViv(lcbuf->frac_digits), 0);
1016 if (lcbuf->p_cs_precedes != CHAR_MAX)
1017 hv_store(RETVAL, "p_cs_precedes", 13,
1018 newSViv(lcbuf->p_cs_precedes), 0);
1019 if (lcbuf->p_sep_by_space != CHAR_MAX)
1020 hv_store(RETVAL, "p_sep_by_space", 14,
1021 newSViv(lcbuf->p_sep_by_space), 0);
1022 if (lcbuf->n_cs_precedes != CHAR_MAX)
1023 hv_store(RETVAL, "n_cs_precedes", 13,
1024 newSViv(lcbuf->n_cs_precedes), 0);
1025 if (lcbuf->n_sep_by_space != CHAR_MAX)
1026 hv_store(RETVAL, "n_sep_by_space", 14,
1027 newSViv(lcbuf->n_sep_by_space), 0);
1028 if (lcbuf->p_sign_posn != CHAR_MAX)
1029 hv_store(RETVAL, "p_sign_posn", 11,
1030 newSViv(lcbuf->p_sign_posn), 0);
1031 if (lcbuf->n_sign_posn != CHAR_MAX)
1032 hv_store(RETVAL, "n_sign_posn", 11,
1033 newSViv(lcbuf->n_sign_posn), 0);
1036 localeconv(); /* A stub to call not_here(). */
1042 setlocale(category, locale = 0)
1046 RETVAL = setlocale(category, locale);
1048 #ifdef USE_LOCALE_CTYPE
1049 if (category == LC_CTYPE
1051 || category == LC_ALL
1057 if (category == LC_ALL)
1058 newctype = setlocale(LC_CTYPE, NULL);
1062 new_ctype(newctype);
1064 #endif /* USE_LOCALE_CTYPE */
1065 #ifdef USE_LOCALE_COLLATE
1066 if (category == LC_COLLATE
1068 || category == LC_ALL
1074 if (category == LC_ALL)
1075 newcoll = setlocale(LC_COLLATE, NULL);
1079 new_collate(newcoll);
1081 #endif /* USE_LOCALE_COLLATE */
1082 #ifdef USE_LOCALE_NUMERIC
1083 if (category == LC_NUMERIC
1085 || category == LC_ALL
1091 if (category == LC_ALL)
1092 newnum = setlocale(LC_NUMERIC, NULL);
1096 new_numeric(newnum);
1098 #endif /* USE_LOCALE_NUMERIC */
1138 /* (We already know stack is long enough.) */
1139 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1140 PUSHs(sv_2mortal(newSViv(expvar)));
1156 /* (We already know stack is long enough.) */
1157 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1158 PUSHs(sv_2mortal(newSVnv(intvar)));
1173 sigaction(sig, optaction, oldaction = 0)
1176 POSIX::SigAction oldaction
1178 #if defined(WIN32) || defined(NETWARE)
1179 RETVAL = not_here("sigaction");
1181 # This code is really grody because we're trying to make the signal
1182 # interface look beautiful, which is hard.
1185 POSIX__SigAction action;
1186 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1187 struct sigaction act;
1188 struct sigaction oact;
1192 POSIX__SigSet sigset;
1194 SV** sigsvp = hv_fetch(GvHVn(siggv),
1196 strlen(PL_sig_name[sig]),
1199 /* Check optaction and set action */
1200 if(SvTRUE(optaction)) {
1201 if(sv_isa(optaction, "POSIX::SigAction"))
1202 action = (HV*)SvRV(optaction);
1204 croak("action is not of type POSIX::SigAction");
1210 /* sigaction() is supposed to look atomic. In particular, any
1211 * signal handler invoked during a sigaction() call should
1212 * see either the old or the new disposition, and not something
1213 * in between. We use sigprocmask() to make it so.
1216 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1220 /* Restore signal mask no matter how we exit this block. */
1221 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1222 SAVEFREESV( osset_sv );
1223 SAVEDESTRUCTOR(restore_sigmask, osset_sv);
1225 RETVAL=-1; /* In case both oldaction and action are 0. */
1227 /* Remember old disposition if desired. */
1229 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
1231 croak("Can't supply an oldaction without a HANDLER");
1232 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1233 sv_setsv(*svp, *sigsvp);
1236 sv_setpv(*svp, "DEFAULT");
1238 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1241 /* Get back the mask. */
1242 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
1243 if (sv_isa(*svp, "POSIX::SigSet")) {
1244 IV tmp = SvIV((SV*)SvRV(*svp));
1245 sigset = INT2PTR(sigset_t*, tmp);
1248 New(0, sigset, 1, sigset_t);
1249 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1251 *sigset = oact.sa_mask;
1253 /* Get back the flags. */
1254 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
1255 sv_setiv(*svp, oact.sa_flags);
1259 /* Vector new handler through %SIG. (We always use sighandler
1260 for the C signal handler, which reads %SIG to dispatch.) */
1261 svp = hv_fetch(action, "HANDLER", 7, FALSE);
1263 croak("Can't supply an action without a HANDLER");
1264 sv_setsv(*sigsvp, *svp);
1265 mg_set(*sigsvp); /* handles DEFAULT and IGNORE */
1267 char *s=SvPVX(*svp);
1268 if(strEQ(s,"IGNORE")) {
1269 act.sa_handler = SIG_IGN;
1271 else if(strEQ(s,"DEFAULT")) {
1272 act.sa_handler = SIG_DFL;
1275 act.sa_handler = PL_sighandlerp;
1279 act.sa_handler = PL_sighandlerp;
1282 /* Set up any desired mask. */
1283 svp = hv_fetch(action, "MASK", 4, FALSE);
1284 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1285 IV tmp = SvIV((SV*)SvRV(*svp));
1286 sigset = INT2PTR(sigset_t*, tmp);
1287 act.sa_mask = *sigset;
1290 sigemptyset(& act.sa_mask);
1292 /* Set up any desired flags. */
1293 svp = hv_fetch(action, "FLAGS", 5, FALSE);
1294 act.sa_flags = svp ? SvIV(*svp) : 0;
1296 /* Don't worry about cleaning up *sigsvp if this fails,
1297 * because that means we tried to disposition a
1298 * nonblockable signal, in which case *sigsvp is
1299 * essentially meaningless anyway.
1301 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1314 POSIX::SigSet sigset
1317 sigprocmask(how, sigset, oldsigset = 0)
1319 POSIX::SigSet sigset
1320 POSIX::SigSet oldsigset = NO_INIT
1325 else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
1326 IV tmp = SvIV((SV*)SvRV(ST(2)));
1327 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1330 New(0, oldsigset, 1, sigset_t);
1331 sigemptyset(oldsigset);
1332 sv_setref_pv(ST(2), "POSIX::SigSet", (void*)oldsigset);
1336 sigsuspend(signal_mask)
1337 POSIX::SigSet signal_mask
1357 lseek(fd, offset, whence)
1370 if (pipe(fds) != -1) {
1372 PUSHs(sv_2mortal(newSViv(fds[0])));
1373 PUSHs(sv_2mortal(newSViv(fds[1])));
1377 read(fd, buffer, nbytes)
1379 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1383 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1386 SvCUR(sv_buffer) = RETVAL;
1387 SvPOK_only(sv_buffer);
1388 *SvEND(sv_buffer) = '\0';
1389 SvTAINTED_on(sv_buffer);
1405 tcsetpgrp(fd, pgrp_id)
1414 if (uname(&buf) >= 0) {
1416 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1417 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1418 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1419 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1420 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1423 uname((char *) 0); /* A stub to call not_here(). */
1427 write(fd, buffer, nbytes)
1438 RETVAL = newSVpvn("", 0);
1439 SvGROW(RETVAL, L_tmpnam);
1440 len = strlen(tmpnam(SvPV(RETVAL, i)));
1441 SvCUR_set(RETVAL, len);
1454 mbstowcs(s, pwcs, n)
1466 wcstombs(s, pwcs, n)
1488 SET_NUMERIC_LOCAL();
1489 num = strtod(str, &unparsed);
1490 PUSHs(sv_2mortal(newSVnv(num)));
1491 if (GIMME == G_ARRAY) {
1494 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1496 PUSHs(&PL_sv_undef);
1500 strtol(str, base = 0)
1507 num = strtol(str, &unparsed, base);
1508 #if IVSIZE <= LONGSIZE
1509 if (num < IV_MIN || num > IV_MAX)
1510 PUSHs(sv_2mortal(newSVnv((double)num)));
1513 PUSHs(sv_2mortal(newSViv((IV)num)));
1514 if (GIMME == G_ARRAY) {
1517 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1519 PUSHs(&PL_sv_undef);
1523 strtoul(str, base = 0)
1530 num = strtoul(str, &unparsed, base);
1532 PUSHs(sv_2mortal(newSViv((IV)num)));
1534 PUSHs(sv_2mortal(newSVnv((double)num)));
1535 if (GIMME == G_ARRAY) {
1538 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1540 PUSHs(&PL_sv_undef);
1550 char *p = SvPV(src,srclen);
1552 ST(0) = sv_2mortal(NEWSV(800,srclen));
1553 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1554 if (dstlen > srclen) {
1556 SvGROW(ST(0), dstlen);
1557 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1560 SvCUR(ST(0)) = dstlen;
1565 mkfifo(filename, mode)
1569 TAINT_PROPER("mkfifo");
1570 RETVAL = mkfifo(filename, mode);
1586 tcflush(fd, queue_selector)
1591 tcsendbreak(fd, duration)
1596 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1609 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1612 mytm.tm_hour = hour;
1613 mytm.tm_mday = mday;
1615 mytm.tm_year = year;
1616 mytm.tm_wday = wday;
1617 mytm.tm_yday = yday;
1618 mytm.tm_isdst = isdst;
1619 RETVAL = asctime(&mytm);
1636 realtime = times( &tms );
1638 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1639 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1640 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1641 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1642 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1645 difftime(time1, time2)
1650 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1663 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1666 mytm.tm_hour = hour;
1667 mytm.tm_mday = mday;
1669 mytm.tm_year = year;
1670 mytm.tm_wday = wday;
1671 mytm.tm_yday = yday;
1672 mytm.tm_isdst = isdst;
1673 RETVAL = mktime(&mytm);
1678 #XXX: if $xsubpp::WantOptimize is always the default
1679 # sv_setpv(TARG, ...) could be used rather than
1680 # ST(0) = sv_2mortal(newSVpv(...))
1682 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1695 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1697 ST(0) = sv_2mortal(newSVpv(buf, 0));
1709 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1710 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1713 access(filename, mode)
1731 pathconf(filename, name)
1760 XSprePUSH; PUSHTARG;