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? */
54 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
55 metaconfig for future extension writers. We don't use them in POSIX.
56 (This is really sneaky :-) --AD
58 #if defined(I_TERMIOS)
68 #include <sys/types.h>
73 #ifdef MACOS_TRADITIONAL
79 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
80 extern char *tzname[];
83 #if !defined(WIN32) && !defined(__UWIN__) || (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")
173 # define setuid(a) not_here("setuid")
174 # define setgid(a) not_here("setgid")
179 # if defined(OS2) || defined(MACOS_TRADITIONAL)
180 # define mkfifo(a,b) not_here("mkfifo")
181 # else /* !( defined OS2 ) */
183 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
186 # endif /* !HAS_MKFIFO */
188 # ifdef MACOS_TRADITIONAL
189 # define ttyname(a) (char*)not_here("ttyname")
190 # define tzset() not_here("tzset")
193 # include <sys/times.h>
195 # include <sys/utsname.h>
197 # include <sys/wait.h>
202 #endif /* WIN32 || NETWARE */
206 typedef long SysRetLong;
207 typedef sigset_t* POSIX__SigSet;
208 typedef HV* POSIX__SigAction;
210 typedef struct termios* POSIX__Termios;
211 #else /* Define termios types to int, and call not_here for the functions.*/
212 #define POSIX__Termios int
216 #define cfgetispeed(x) not_here("cfgetispeed")
217 #define cfgetospeed(x) not_here("cfgetospeed")
218 #define tcdrain(x) not_here("tcdrain")
219 #define tcflush(x,y) not_here("tcflush")
220 #define tcsendbreak(x,y) not_here("tcsendbreak")
221 #define cfsetispeed(x,y) not_here("cfsetispeed")
222 #define cfsetospeed(x,y) not_here("cfsetospeed")
223 #define ctermid(x) (char *) not_here("ctermid")
224 #define tcflow(x,y) not_here("tcflow")
225 #define tcgetattr(x,y) not_here("tcgetattr")
226 #define tcsetattr(x,y,z) not_here("tcsetattr")
229 /* Possibly needed prototypes */
230 char *cuserid (char *);
232 double strtod (const char *, char **);
233 long strtol (const char *, char **, int);
234 unsigned long strtoul (const char *, char **, int);
238 #define cuserid(a) (char *) not_here("cuserid")
242 #define difftime(a,b) not_here("difftime")
245 #ifndef HAS_FPATHCONF
246 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
249 #define mktime(a) not_here("mktime")
252 #define nice(a) not_here("nice")
255 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
258 #define sysconf(n) (SysRetLong) not_here("sysconf")
261 #define readlink(a,b,c) not_here("readlink")
264 #define setpgid(a,b) not_here("setpgid")
267 #define setsid() not_here("setsid")
270 #define strcoll(s1,s2) not_here("strcoll")
273 #define strtod(s1,s2) not_here("strtod")
276 #define strtol(s1,s2,b) not_here("strtol")
279 #define strtoul(s1,s2,b) not_here("strtoul")
282 #define strxfrm(s1,s2,n) not_here("strxfrm")
284 #ifndef HAS_TCGETPGRP
285 #define tcgetpgrp(a) not_here("tcgetpgrp")
287 #ifndef HAS_TCSETPGRP
288 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
292 #define times(a) not_here("times")
296 #define uname(a) not_here("uname")
299 #define waitpid(a,b,c) not_here("waitpid")
304 #define mblen(a,b) not_here("mblen")
308 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
311 #define mbtowc(pwc, s, n) not_here("mbtowc")
314 #define wcstombs(s, pwcs, n) not_here("wcstombs")
317 #define wctomb(s, wchar) not_here("wcstombs")
319 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
320 /* If we don't have these functions, then we wouldn't have gotten a typedef
321 for wchar_t, the wide character type. Defining wchar_t allows the
322 functions referencing it to compile. Its actual type is then meaningless,
323 since without the above functions, all sections using it end up calling
324 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
330 #ifndef HAS_LOCALECONV
331 #define localeconv() not_here("localeconv")
334 #ifdef HAS_LONG_DOUBLE
335 # if LONG_DOUBLESIZE > NVSIZE
336 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
340 #ifndef HAS_LONG_DOUBLE
352 /* Background: in most systems the low byte of the wait status
353 * is the signal (the lowest 7 bits) and the coredump flag is
354 * the eight bit, and the second lowest byte is the exit status.
355 * BeOS bucks the trend and has the bytes in different order.
356 * See beos/beos.c for how the reality is bent even in BeOS
357 * to follow the traditional. However, to make the POSIX
358 * wait W*() macros to work in BeOS, we need to unbend the
359 * reality back in place. --jhi */
361 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
363 # define WMUNGE(x) (x)
369 croak("POSIX::%s not implemented on this architecture", s);
373 #include "const-c.inc"
375 /* These were implemented in the old "constant" subroutine. They are actually
376 macros that take an integer argument and return an integer result. */
378 int_macro_int (const char *name, STRLEN len, IV *arg_result) {
379 /* Initially switch on the length of the name. */
380 /* This code has been edited from a "constant" function generated by:
382 use ExtUtils::Constant qw (constant_types C_constant XS_constant);
384 my $types = {map {($_, 1)} qw(IV)};
385 my @names = (qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS WIFEXITED
386 WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
388 print constant_types(); # macro defs
389 foreach (C_constant ("POSIX", 'int_macro_int', 'IV', $types, undef, 5, @names) ) {
390 print $_, "\n"; # C constant subs
392 print "#### XS Section:\n";
393 print XS_constant ("POSIX", $types);
399 /* Names all of length 7. */
400 /* S_ISBLK S_ISCHR S_ISDIR S_ISREG */
401 /* Offset 5 gives the best switch position. */
404 if (memEQ(name, "S_ISREG", 7)) {
407 *arg_result = S_ISREG(*arg_result);
408 return PERL_constant_ISIV;
410 return PERL_constant_NOTDEF;
415 if (memEQ(name, "S_ISCHR", 7)) {
418 *arg_result = S_ISCHR(*arg_result);
419 return PERL_constant_ISIV;
421 return PERL_constant_NOTDEF;
426 if (memEQ(name, "S_ISDIR", 7)) {
429 *arg_result = S_ISDIR(*arg_result);
430 return PERL_constant_ISIV;
432 return PERL_constant_NOTDEF;
437 if (memEQ(name, "S_ISBLK", 7)) {
440 *arg_result = S_ISBLK(*arg_result);
441 return PERL_constant_ISIV;
443 return PERL_constant_NOTDEF;
450 /* Names all of length 8. */
451 /* S_ISFIFO WSTOPSIG WTERMSIG */
452 /* Offset 3 gives the best switch position. */
455 if (memEQ(name, "WSTOPSIG", 8)) {
459 *arg_result = WSTOPSIG(WMUNGE(i));
460 return PERL_constant_ISIV;
462 return PERL_constant_NOTDEF;
467 if (memEQ(name, "WTERMSIG", 8)) {
471 *arg_result = WTERMSIG(WMUNGE(i));
472 return PERL_constant_ISIV;
474 return PERL_constant_NOTDEF;
479 if (memEQ(name, "S_ISFIFO", 8)) {
482 *arg_result = S_ISFIFO(*arg_result);
483 return PERL_constant_ISIV;
485 return PERL_constant_NOTDEF;
492 if (memEQ(name, "WIFEXITED", 9)) {
495 *arg_result = WIFEXITED(WMUNGE(i));
496 return PERL_constant_ISIV;
498 return PERL_constant_NOTDEF;
503 if (memEQ(name, "WIFSTOPPED", 10)) {
506 *arg_result = WIFSTOPPED(WMUNGE(i));
507 return PERL_constant_ISIV;
509 return PERL_constant_NOTDEF;
514 /* Names all of length 11. */
515 /* WEXITSTATUS WIFSIGNALED */
516 /* Offset 1 gives the best switch position. */
519 if (memEQ(name, "WEXITSTATUS", 11)) {
523 *arg_result = WEXITSTATUS(WMUNGE(i));
524 return PERL_constant_ISIV;
526 return PERL_constant_NOTDEF;
531 if (memEQ(name, "WIFSIGNALED", 11)) {
535 *arg_result = WIFSIGNALED(WMUNGE(i));
536 return PERL_constant_ISIV;
538 return PERL_constant_NOTDEF;
545 return PERL_constant_NOTFOUND;
549 restore_sigmask(pTHX_ SV *osset_sv)
551 /* Fortunately, restoring the signal mask can't fail, because
552 * there's nothing we can do about it if it does -- we're not
553 * supposed to return -1 from sigaction unless the disposition
556 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
557 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
560 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
563 new(packname = "POSIX::SigSet", ...)
568 New(0, RETVAL, 1, sigset_t);
570 for (i = 1; i < items; i++)
571 sigaddset(RETVAL, SvIV(ST(i)));
583 sigaddset(sigset, sig)
588 sigdelset(sigset, sig)
601 sigismember(sigset, sig)
606 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
609 new(packname = "POSIX::Termios", ...)
614 New(0, RETVAL, 1, struct termios);
625 POSIX::Termios termios_ref
628 Safefree(termios_ref);
634 getattr(termios_ref, fd = 0)
635 POSIX::Termios termios_ref
638 RETVAL = tcgetattr(fd, termios_ref);
643 setattr(termios_ref, fd = 0, optional_actions = 0)
644 POSIX::Termios termios_ref
648 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
653 cfgetispeed(termios_ref)
654 POSIX::Termios termios_ref
657 cfgetospeed(termios_ref)
658 POSIX::Termios termios_ref
661 getiflag(termios_ref)
662 POSIX::Termios termios_ref
664 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
665 RETVAL = termios_ref->c_iflag;
667 not_here("getiflag");
674 getoflag(termios_ref)
675 POSIX::Termios termios_ref
677 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
678 RETVAL = termios_ref->c_oflag;
680 not_here("getoflag");
687 getcflag(termios_ref)
688 POSIX::Termios termios_ref
690 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
691 RETVAL = termios_ref->c_cflag;
693 not_here("getcflag");
700 getlflag(termios_ref)
701 POSIX::Termios termios_ref
703 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
704 RETVAL = termios_ref->c_lflag;
706 not_here("getlflag");
713 getcc(termios_ref, ccix)
714 POSIX::Termios termios_ref
717 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
719 croak("Bad getcc subscript");
720 RETVAL = termios_ref->c_cc[ccix];
729 cfsetispeed(termios_ref, speed)
730 POSIX::Termios termios_ref
734 cfsetospeed(termios_ref, speed)
735 POSIX::Termios termios_ref
739 setiflag(termios_ref, iflag)
740 POSIX::Termios termios_ref
743 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
744 termios_ref->c_iflag = iflag;
746 not_here("setiflag");
750 setoflag(termios_ref, oflag)
751 POSIX::Termios termios_ref
754 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
755 termios_ref->c_oflag = oflag;
757 not_here("setoflag");
761 setcflag(termios_ref, cflag)
762 POSIX::Termios termios_ref
765 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
766 termios_ref->c_cflag = cflag;
768 not_here("setcflag");
772 setlflag(termios_ref, lflag)
773 POSIX::Termios termios_ref
776 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
777 termios_ref->c_lflag = lflag;
779 not_here("setlflag");
783 setcc(termios_ref, ccix, cc)
784 POSIX::Termios termios_ref
788 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
790 croak("Bad setcc subscript");
791 termios_ref->c_cc[ccix] = cc;
797 MODULE = POSIX PACKAGE = POSIX
799 INCLUDE: const-xs.inc
802 int_macro_int(sv, iv)
809 const char * s = SvPV(sv, len);
812 /* Change this to int_macro_int(s, len, &iv, &nv);
813 if you need to return both NVs and IVs */
814 type = int_macro_int(s, len, &iv);
815 /* Return 1 or 2 items. First is error message, or undef if no error.
816 Second, if present, is found value */
818 case PERL_constant_NOTFOUND:
819 sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s));
824 case PERL_constant_NOTDEF:
825 sv = sv_2mortal(newSVpvf(
826 "Your vendor has not defined POSIX macro %s, used", s));
831 case PERL_constant_ISIV:
835 sv = sv_2mortal(newSVpvf(
836 "Unexpected return type %d while processing POSIX macro %s, used",
849 unsigned char *s = (unsigned char *) SvPV(charstring, len);
850 unsigned char *e = s + len;
851 for (RETVAL = 1; RETVAL && s < e; s++)
863 unsigned char *s = (unsigned char *) SvPV(charstring, len);
864 unsigned char *e = s + len;
865 for (RETVAL = 1; RETVAL && s < e; s++)
877 unsigned char *s = (unsigned char *) SvPV(charstring, len);
878 unsigned char *e = s + len;
879 for (RETVAL = 1; RETVAL && s < e; s++)
891 unsigned char *s = (unsigned char *) SvPV(charstring, len);
892 unsigned char *e = s + len;
893 for (RETVAL = 1; RETVAL && s < e; s++)
905 unsigned char *s = (unsigned char *) SvPV(charstring, len);
906 unsigned char *e = s + len;
907 for (RETVAL = 1; RETVAL && s < e; s++)
919 unsigned char *s = (unsigned char *) SvPV(charstring, len);
920 unsigned char *e = s + len;
921 for (RETVAL = 1; RETVAL && s < e; s++)
933 unsigned char *s = (unsigned char *) SvPV(charstring, len);
934 unsigned char *e = s + len;
935 for (RETVAL = 1; RETVAL && s < e; s++)
947 unsigned char *s = (unsigned char *) SvPV(charstring, len);
948 unsigned char *e = s + len;
949 for (RETVAL = 1; RETVAL && s < e; s++)
961 unsigned char *s = (unsigned char *) SvPV(charstring, len);
962 unsigned char *e = s + len;
963 for (RETVAL = 1; RETVAL && s < e; s++)
975 unsigned char *s = (unsigned char *) SvPV(charstring, len);
976 unsigned char *e = s + len;
977 for (RETVAL = 1; RETVAL && s < e; s++)
989 unsigned char *s = (unsigned char *) SvPV(charstring, len);
990 unsigned char *e = s + len;
991 for (RETVAL = 1; RETVAL && s < e; s++)
998 open(filename, flags = O_RDONLY, mode = 0666)
1003 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1004 TAINT_PROPER("open");
1005 RETVAL = open(filename, flags, mode);
1013 #ifdef HAS_LOCALECONV
1014 struct lconv *lcbuf;
1016 sv_2mortal((SV*)RETVAL);
1017 if ((lcbuf = localeconv())) {
1019 if (lcbuf->decimal_point && *lcbuf->decimal_point)
1020 hv_store(RETVAL, "decimal_point", 13,
1021 newSVpv(lcbuf->decimal_point, 0), 0);
1022 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
1023 hv_store(RETVAL, "thousands_sep", 13,
1024 newSVpv(lcbuf->thousands_sep, 0), 0);
1025 #ifndef NO_LOCALECONV_GROUPING
1026 if (lcbuf->grouping && *lcbuf->grouping)
1027 hv_store(RETVAL, "grouping", 8,
1028 newSVpv(lcbuf->grouping, 0), 0);
1030 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
1031 hv_store(RETVAL, "int_curr_symbol", 15,
1032 newSVpv(lcbuf->int_curr_symbol, 0), 0);
1033 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
1034 hv_store(RETVAL, "currency_symbol", 15,
1035 newSVpv(lcbuf->currency_symbol, 0), 0);
1036 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
1037 hv_store(RETVAL, "mon_decimal_point", 17,
1038 newSVpv(lcbuf->mon_decimal_point, 0), 0);
1039 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1040 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
1041 hv_store(RETVAL, "mon_thousands_sep", 17,
1042 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
1044 #ifndef NO_LOCALECONV_MON_GROUPING
1045 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
1046 hv_store(RETVAL, "mon_grouping", 12,
1047 newSVpv(lcbuf->mon_grouping, 0), 0);
1049 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1050 hv_store(RETVAL, "positive_sign", 13,
1051 newSVpv(lcbuf->positive_sign, 0), 0);
1052 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1053 hv_store(RETVAL, "negative_sign", 13,
1054 newSVpv(lcbuf->negative_sign, 0), 0);
1056 if (lcbuf->int_frac_digits != CHAR_MAX)
1057 hv_store(RETVAL, "int_frac_digits", 15,
1058 newSViv(lcbuf->int_frac_digits), 0);
1059 if (lcbuf->frac_digits != CHAR_MAX)
1060 hv_store(RETVAL, "frac_digits", 11,
1061 newSViv(lcbuf->frac_digits), 0);
1062 if (lcbuf->p_cs_precedes != CHAR_MAX)
1063 hv_store(RETVAL, "p_cs_precedes", 13,
1064 newSViv(lcbuf->p_cs_precedes), 0);
1065 if (lcbuf->p_sep_by_space != CHAR_MAX)
1066 hv_store(RETVAL, "p_sep_by_space", 14,
1067 newSViv(lcbuf->p_sep_by_space), 0);
1068 if (lcbuf->n_cs_precedes != CHAR_MAX)
1069 hv_store(RETVAL, "n_cs_precedes", 13,
1070 newSViv(lcbuf->n_cs_precedes), 0);
1071 if (lcbuf->n_sep_by_space != CHAR_MAX)
1072 hv_store(RETVAL, "n_sep_by_space", 14,
1073 newSViv(lcbuf->n_sep_by_space), 0);
1074 if (lcbuf->p_sign_posn != CHAR_MAX)
1075 hv_store(RETVAL, "p_sign_posn", 11,
1076 newSViv(lcbuf->p_sign_posn), 0);
1077 if (lcbuf->n_sign_posn != CHAR_MAX)
1078 hv_store(RETVAL, "n_sign_posn", 11,
1079 newSViv(lcbuf->n_sign_posn), 0);
1082 localeconv(); /* A stub to call not_here(). */
1088 setlocale(category, locale = 0)
1092 RETVAL = setlocale(category, locale);
1094 #ifdef USE_LOCALE_CTYPE
1095 if (category == LC_CTYPE
1097 || category == LC_ALL
1103 if (category == LC_ALL)
1104 newctype = setlocale(LC_CTYPE, NULL);
1108 new_ctype(newctype);
1110 #endif /* USE_LOCALE_CTYPE */
1111 #ifdef USE_LOCALE_COLLATE
1112 if (category == LC_COLLATE
1114 || category == LC_ALL
1120 if (category == LC_ALL)
1121 newcoll = setlocale(LC_COLLATE, NULL);
1125 new_collate(newcoll);
1127 #endif /* USE_LOCALE_COLLATE */
1128 #ifdef USE_LOCALE_NUMERIC
1129 if (category == LC_NUMERIC
1131 || category == LC_ALL
1137 if (category == LC_ALL)
1138 newnum = setlocale(LC_NUMERIC, NULL);
1142 new_numeric(newnum);
1144 #endif /* USE_LOCALE_NUMERIC */
1184 /* (We already know stack is long enough.) */
1185 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1186 PUSHs(sv_2mortal(newSViv(expvar)));
1202 /* (We already know stack is long enough.) */
1203 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1204 PUSHs(sv_2mortal(newSVnv(intvar)));
1219 sigaction(sig, optaction, oldaction = 0)
1222 POSIX::SigAction oldaction
1224 #if defined(WIN32) || defined(NETWARE)
1225 RETVAL = not_here("sigaction");
1227 # This code is really grody because we're trying to make the signal
1228 # interface look beautiful, which is hard.
1231 POSIX__SigAction action;
1232 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1233 struct sigaction act;
1234 struct sigaction oact;
1238 POSIX__SigSet sigset;
1241 if (sig == 0 && SvPOK(ST(0))) {
1242 char *s = SvPVX(ST(0));
1243 int i = whichsig(s);
1245 if (i < 0 && memEQ(s, "SIG", 3))
1246 i = whichsig(s + 3);
1248 if (ckWARN(WARN_SIGNAL))
1249 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1250 "No such signal: SIG%s", s);
1256 sigsvp = hv_fetch(GvHVn(siggv),
1258 strlen(PL_sig_name[sig]),
1261 /* Check optaction and set action */
1262 if(SvTRUE(optaction)) {
1263 if(sv_isa(optaction, "POSIX::SigAction"))
1264 action = (HV*)SvRV(optaction);
1266 croak("action is not of type POSIX::SigAction");
1272 /* sigaction() is supposed to look atomic. In particular, any
1273 * signal handler invoked during a sigaction() call should
1274 * see either the old or the new disposition, and not something
1275 * in between. We use sigprocmask() to make it so.
1278 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1282 /* Restore signal mask no matter how we exit this block. */
1283 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1284 SAVEFREESV( osset_sv );
1285 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1287 RETVAL=-1; /* In case both oldaction and action are 0. */
1289 /* Remember old disposition if desired. */
1291 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
1293 croak("Can't supply an oldaction without a HANDLER");
1294 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1295 sv_setsv(*svp, *sigsvp);
1298 sv_setpv(*svp, "DEFAULT");
1300 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1303 /* Get back the mask. */
1304 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
1305 if (sv_isa(*svp, "POSIX::SigSet")) {
1306 IV tmp = SvIV((SV*)SvRV(*svp));
1307 sigset = INT2PTR(sigset_t*, tmp);
1310 New(0, sigset, 1, sigset_t);
1311 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1313 *sigset = oact.sa_mask;
1315 /* Get back the flags. */
1316 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
1317 sv_setiv(*svp, oact.sa_flags);
1319 /* Get back whether the old handler used safe signals. */
1320 svp = hv_fetch(oldaction, "SAFE", 4, TRUE);
1321 sv_setiv(*svp, oact.sa_handler == PL_csighandlerp);
1325 /* Safe signals use "csighandler", which vectors through the
1326 PL_sighandlerp pointer when it's safe to do so.
1327 (BTW, "csighandler" is very different from "sighandler".) */
1328 svp = hv_fetch(action, "SAFE", 4, FALSE);
1329 act.sa_handler = (*svp && SvTRUE(*svp))
1330 ? PL_csighandlerp : PL_sighandlerp;
1332 /* Vector new Perl handler through %SIG.
1333 (The core signal handlers read %SIG to dispatch.) */
1334 svp = hv_fetch(action, "HANDLER", 7, FALSE);
1336 croak("Can't supply an action without a HANDLER");
1337 sv_setsv(*sigsvp, *svp);
1339 /* This call actually calls sigaction() with almost the
1340 right settings, including appropriate interpretation
1341 of DEFAULT and IGNORE. However, why are we doing
1342 this when we're about to do it again just below? XXX */
1345 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1347 char *s=SvPVX(*svp);
1348 if(strEQ(s,"IGNORE")) {
1349 act.sa_handler = SIG_IGN;
1351 else if(strEQ(s,"DEFAULT")) {
1352 act.sa_handler = SIG_DFL;
1356 /* Set up any desired mask. */
1357 svp = hv_fetch(action, "MASK", 4, FALSE);
1358 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1359 IV tmp = SvIV((SV*)SvRV(*svp));
1360 sigset = INT2PTR(sigset_t*, tmp);
1361 act.sa_mask = *sigset;
1364 sigemptyset(& act.sa_mask);
1366 /* Set up any desired flags. */
1367 svp = hv_fetch(action, "FLAGS", 5, FALSE);
1368 act.sa_flags = svp ? SvIV(*svp) : 0;
1370 /* Don't worry about cleaning up *sigsvp if this fails,
1371 * because that means we tried to disposition a
1372 * nonblockable signal, in which case *sigsvp is
1373 * essentially meaningless anyway.
1375 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1388 POSIX::SigSet sigset
1391 sigprocmask(how, sigset, oldsigset = 0)
1393 POSIX::SigSet sigset = NO_INIT
1394 POSIX::SigSet oldsigset = NO_INIT
1396 if (SvTYPE(ST(1)) == SVt_NULL) {
1398 } else if (sv_derived_from(ST(1), "POSIX::SigSet")) {
1399 IV tmp = SvIV((SV*)SvRV(ST(1)));
1400 sigset = INT2PTR(POSIX__SigSet,tmp);
1402 croak("sigset is not of type POSIX::SigSet");
1405 if ( items < 3 || SvTYPE(ST(2)) == SVt_NULL) {
1407 } else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
1408 IV tmp = SvIV((SV*)SvRV(ST(2)));
1409 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1411 croak("oldsigset is not of type POSIX::SigSet");
1415 sigsuspend(signal_mask)
1416 POSIX::SigSet signal_mask
1436 lseek(fd, offset, whence)
1441 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1442 RETVAL = sizeof(Off_t) > sizeof(IV)
1443 ? newSVnv((NV)pos) : newSViv((IV)pos);
1452 if ((incr = nice(incr)) != -1 || errno == 0) {
1454 XPUSHs(sv_2mortal(newSVpvn("0 but true", 10)));
1456 XPUSHs(sv_2mortal(newSViv(incr)));
1463 if (pipe(fds) != -1) {
1465 PUSHs(sv_2mortal(newSViv(fds[0])));
1466 PUSHs(sv_2mortal(newSViv(fds[1])));
1470 read(fd, buffer, nbytes)
1472 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1476 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1479 SvCUR(sv_buffer) = RETVAL;
1480 SvPOK_only(sv_buffer);
1481 *SvEND(sv_buffer) = '\0';
1482 SvTAINTED_on(sv_buffer);
1498 tcsetpgrp(fd, pgrp_id)
1507 if (uname(&buf) >= 0) {
1509 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1510 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1511 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1512 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1513 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1516 uname((char *) 0); /* A stub to call not_here(). */
1520 write(fd, buffer, nbytes)
1531 RETVAL = newSVpvn("", 0);
1532 SvGROW(RETVAL, L_tmpnam);
1533 len = strlen(tmpnam(SvPV(RETVAL, i)));
1534 SvCUR_set(RETVAL, len);
1547 mbstowcs(s, pwcs, n)
1559 wcstombs(s, pwcs, n)
1581 SET_NUMERIC_LOCAL();
1582 num = strtod(str, &unparsed);
1583 PUSHs(sv_2mortal(newSVnv(num)));
1584 if (GIMME == G_ARRAY) {
1587 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1589 PUSHs(&PL_sv_undef);
1593 strtol(str, base = 0)
1600 num = strtol(str, &unparsed, base);
1601 #if IVSIZE <= LONGSIZE
1602 if (num < IV_MIN || num > IV_MAX)
1603 PUSHs(sv_2mortal(newSVnv((double)num)));
1606 PUSHs(sv_2mortal(newSViv((IV)num)));
1607 if (GIMME == G_ARRAY) {
1610 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1612 PUSHs(&PL_sv_undef);
1616 strtoul(str, base = 0)
1623 num = strtoul(str, &unparsed, base);
1624 #if IVSIZE <= LONGSIZE
1626 PUSHs(sv_2mortal(newSVnv((double)num)));
1629 PUSHs(sv_2mortal(newSViv((IV)num)));
1630 if (GIMME == G_ARRAY) {
1633 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1635 PUSHs(&PL_sv_undef);
1645 char *p = SvPV(src,srclen);
1647 ST(0) = sv_2mortal(NEWSV(800,srclen*4+1));
1648 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1649 if (dstlen > srclen) {
1651 SvGROW(ST(0), dstlen);
1652 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1655 SvCUR(ST(0)) = dstlen;
1660 mkfifo(filename, mode)
1664 TAINT_PROPER("mkfifo");
1665 RETVAL = mkfifo(filename, mode);
1681 tcflush(fd, queue_selector)
1686 tcsendbreak(fd, duration)
1691 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1704 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1707 mytm.tm_hour = hour;
1708 mytm.tm_mday = mday;
1710 mytm.tm_year = year;
1711 mytm.tm_wday = wday;
1712 mytm.tm_yday = yday;
1713 mytm.tm_isdst = isdst;
1714 RETVAL = asctime(&mytm);
1731 realtime = times( &tms );
1733 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1734 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1735 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1736 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1737 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1740 difftime(time1, time2)
1745 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1758 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1761 mytm.tm_hour = hour;
1762 mytm.tm_mday = mday;
1764 mytm.tm_year = year;
1765 mytm.tm_wday = wday;
1766 mytm.tm_yday = yday;
1767 mytm.tm_isdst = isdst;
1768 RETVAL = mktime(&mytm);
1773 #XXX: if $xsubpp::WantOptimize is always the default
1774 # sv_setpv(TARG, ...) could be used rather than
1775 # ST(0) = sv_2mortal(newSVpv(...))
1777 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1790 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1792 ST(0) = sv_2mortal(newSVpv(buf, 0));
1804 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1805 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1808 access(filename, mode)
1816 #ifdef HAS_CTERMID_R
1817 s = safemalloc((size_t) L_ctermid);
1819 RETVAL = ctermid(s);
1823 #ifdef HAS_CTERMID_R
1837 pathconf(filename, name)
1851 PL_egid = getegid();
1862 PL_euid = geteuid();
1880 XSprePUSH; PUSHTARG;
1884 lchown(uid, gid, path)
1890 /* yes, the order of arguments is different,
1891 * but consistent with CORE::chown() */
1892 RETVAL = lchown(path, uid, gid);
1894 RETVAL = not_here("lchown");