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 #ifndef PERL_UNUSED_DECL
90 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
91 # define PERL_UNUSED_DECL
93 # define PERL_UNUSED_DECL __attribute__((unused))
96 # define PERL_UNUSED_DECL
101 #define dNOOP extern int Perl___notused PERL_UNUSED_DECL
108 #if defined(__VMS) && !defined(__POSIX_SOURCE)
109 # include <libdef.h> /* LIB$_INVARG constant */
110 # include <lib$routines.h> /* prototype for lib$ediv() */
111 # include <starlet.h> /* prototype for sys$gettim() */
112 # if DECC_VERSION < 50000000
113 # define pid_t int /* old versions of DECC miss this in types.h */
117 # define mkfifo(a,b) (not_here("mkfifo"),-1)
118 # define tzset() not_here("tzset")
120 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
121 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
122 # include <utsname.h>
123 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
125 /* The POSIX notion of ttyname() is better served by getname() under VMS */
126 static char ttnambuf[64];
127 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
129 /* The non-POSIX CRTL times() has void return type, so we just get the
130 current time directly */
131 clock_t vms_times(struct tms *bufptr) {
134 /* Get wall time and convert to 10 ms intervals to
135 * produce the return value that the POSIX standard expects */
136 # if defined(__DECC) && defined (__ALPHA)
139 _ckvmssts(sys$gettim(&vmstime));
141 retval = vmstime & 0x7fffffff;
143 /* (Older hw or ccs don't have an atomic 64-bit type, so we
144 * juggle 32-bit ints (and a float) to produce a time_t result
145 * with minimal loss of information.) */
146 long int vmstime[2],remainder,divisor = 100000;
147 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
148 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
149 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
151 /* Fill in the struct tms using the CRTL routine . . .*/
152 times((tbuffer_t *)bufptr);
153 return (clock_t) retval;
155 # define times(t) vms_times(t)
157 #if defined (__CYGWIN__)
158 # define tzname _tzname
160 #if defined (WIN32) || defined (NETWARE)
162 # define mkfifo(a,b) not_here("mkfifo")
163 # define ttyname(a) (char*)not_here("ttyname")
164 # define sigset_t long
167 # define tzname _tzname
170 # define mode_t short
173 # define mode_t short
175 # define tzset() not_here("tzset")
177 # ifndef _POSIX_OPEN_MAX
178 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
181 # define sigaction(a,b,c) not_here("sigaction")
182 # define sigpending(a) not_here("sigpending")
183 # define sigprocmask(a,b,c) not_here("sigprocmask")
184 # define sigsuspend(a) not_here("sigsuspend")
185 # define sigemptyset(a) not_here("sigemptyset")
186 # define sigaddset(a,b) not_here("sigaddset")
187 # define sigdelset(a,b) not_here("sigdelset")
188 # define sigfillset(a) not_here("sigfillset")
189 # define sigismember(a,b) not_here("sigismember")
193 # define setuid(a) not_here("setuid")
194 # define setgid(a) not_here("setgid")
199 # if defined(OS2) || defined(MACOS_TRADITIONAL)
200 # define mkfifo(a,b) not_here("mkfifo")
201 # else /* !( defined OS2 ) */
203 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
206 # endif /* !HAS_MKFIFO */
208 # ifdef MACOS_TRADITIONAL
209 # define ttyname(a) (char*)not_here("ttyname")
210 # define tzset() not_here("tzset")
213 # include <sys/times.h>
215 # include <sys/utsname.h>
217 # include <sys/wait.h>
222 #endif /* WIN32 || NETWARE */
226 typedef long SysRetLong;
227 typedef sigset_t* POSIX__SigSet;
228 typedef HV* POSIX__SigAction;
230 typedef struct termios* POSIX__Termios;
231 #else /* Define termios types to int, and call not_here for the functions.*/
232 #define POSIX__Termios int
236 #define cfgetispeed(x) not_here("cfgetispeed")
237 #define cfgetospeed(x) not_here("cfgetospeed")
238 #define tcdrain(x) not_here("tcdrain")
239 #define tcflush(x,y) not_here("tcflush")
240 #define tcsendbreak(x,y) not_here("tcsendbreak")
241 #define cfsetispeed(x,y) not_here("cfsetispeed")
242 #define cfsetospeed(x,y) not_here("cfsetospeed")
243 #define ctermid(x) (char *) not_here("ctermid")
244 #define tcflow(x,y) not_here("tcflow")
245 #define tcgetattr(x,y) not_here("tcgetattr")
246 #define tcsetattr(x,y,z) not_here("tcsetattr")
249 /* Possibly needed prototypes */
250 char *cuserid (char *);
252 double strtod (const char *, char **);
253 long strtol (const char *, char **, int);
254 unsigned long strtoul (const char *, char **, int);
258 #define cuserid(a) (char *) not_here("cuserid")
262 #define difftime(a,b) not_here("difftime")
265 #ifndef HAS_FPATHCONF
266 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
269 #define mktime(a) not_here("mktime")
272 #define nice(a) not_here("nice")
275 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
278 #define sysconf(n) (SysRetLong) not_here("sysconf")
281 #define readlink(a,b,c) not_here("readlink")
284 #define setpgid(a,b) not_here("setpgid")
287 #define setsid() not_here("setsid")
290 #define strcoll(s1,s2) not_here("strcoll")
293 #define strtod(s1,s2) not_here("strtod")
296 #define strtol(s1,s2,b) not_here("strtol")
299 #define strtoul(s1,s2,b) not_here("strtoul")
302 #define strxfrm(s1,s2,n) not_here("strxfrm")
304 #ifndef HAS_TCGETPGRP
305 #define tcgetpgrp(a) not_here("tcgetpgrp")
307 #ifndef HAS_TCSETPGRP
308 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
312 #define times(a) not_here("times")
316 #define uname(a) not_here("uname")
319 #define waitpid(a,b,c) not_here("waitpid")
324 #define mblen(a,b) not_here("mblen")
328 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
331 #define mbtowc(pwc, s, n) not_here("mbtowc")
334 #define wcstombs(s, pwcs, n) not_here("wcstombs")
337 #define wctomb(s, wchar) not_here("wcstombs")
339 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
340 /* If we don't have these functions, then we wouldn't have gotten a typedef
341 for wchar_t, the wide character type. Defining wchar_t allows the
342 functions referencing it to compile. Its actual type is then meaningless,
343 since without the above functions, all sections using it end up calling
344 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
350 #ifndef HAS_LOCALECONV
351 #define localeconv() not_here("localeconv")
354 #ifdef HAS_LONG_DOUBLE
355 # if LONG_DOUBLESIZE > NVSIZE
356 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
360 #ifndef HAS_LONG_DOUBLE
372 /* Background: in most systems the low byte of the wait status
373 * is the signal (the lowest 7 bits) and the coredump flag is
374 * the eight bit, and the second lowest byte is the exit status.
375 * BeOS bucks the trend and has the bytes in different order.
376 * See beos/beos.c for how the reality is bent even in BeOS
377 * to follow the traditional. However, to make the POSIX
378 * wait W*() macros to work in BeOS, we need to unbend the
379 * reality back in place. --jhi */
381 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
383 # define WMUNGE(x) (x)
389 croak("POSIX::%s not implemented on this architecture", s);
393 #include "const-c.inc"
395 /* These were implemented in the old "constant" subroutine. They are actually
396 macros that take an integer argument and return an integer result. */
398 int_macro_int (const char *name, STRLEN len, IV *arg_result) {
399 /* Initially switch on the length of the name. */
400 /* This code has been edited from a "constant" function generated by:
402 use ExtUtils::Constant qw (constant_types C_constant XS_constant);
404 my $types = {map {($_, 1)} qw(IV)};
405 my @names = (qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS WIFEXITED
406 WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
408 print constant_types(); # macro defs
409 foreach (C_constant ("POSIX", 'int_macro_int', 'IV', $types, undef, 5, @names) ) {
410 print $_, "\n"; # C constant subs
412 print "#### XS Section:\n";
413 print XS_constant ("POSIX", $types);
418 /* Names all of length 7. */
419 /* S_ISBLK S_ISCHR S_ISDIR S_ISREG */
420 /* Offset 5 gives the best switch position. */
423 if (memEQ(name, "S_ISREG", 7)) {
426 *arg_result = S_ISREG(*arg_result);
427 return PERL_constant_ISIV;
429 return PERL_constant_NOTDEF;
434 if (memEQ(name, "S_ISCHR", 7)) {
437 *arg_result = S_ISCHR(*arg_result);
438 return PERL_constant_ISIV;
440 return PERL_constant_NOTDEF;
445 if (memEQ(name, "S_ISDIR", 7)) {
448 *arg_result = S_ISDIR(*arg_result);
449 return PERL_constant_ISIV;
451 return PERL_constant_NOTDEF;
456 if (memEQ(name, "S_ISBLK", 7)) {
459 *arg_result = S_ISBLK(*arg_result);
460 return PERL_constant_ISIV;
462 return PERL_constant_NOTDEF;
469 /* Names all of length 8. */
470 /* S_ISFIFO WSTOPSIG WTERMSIG */
471 /* Offset 3 gives the best switch position. */
474 if (memEQ(name, "WSTOPSIG", 8)) {
478 *arg_result = WSTOPSIG(WMUNGE(i));
479 return PERL_constant_ISIV;
481 return PERL_constant_NOTDEF;
486 if (memEQ(name, "WTERMSIG", 8)) {
490 *arg_result = WTERMSIG(WMUNGE(i));
491 return PERL_constant_ISIV;
493 return PERL_constant_NOTDEF;
498 if (memEQ(name, "S_ISFIFO", 8)) {
501 *arg_result = S_ISFIFO(*arg_result);
502 return PERL_constant_ISIV;
504 return PERL_constant_NOTDEF;
511 if (memEQ(name, "WIFEXITED", 9)) {
514 *arg_result = WIFEXITED(WMUNGE(i));
515 return PERL_constant_ISIV;
517 return PERL_constant_NOTDEF;
522 if (memEQ(name, "WIFSTOPPED", 10)) {
525 *arg_result = WIFSTOPPED(WMUNGE(i));
526 return PERL_constant_ISIV;
528 return PERL_constant_NOTDEF;
533 /* Names all of length 11. */
534 /* WEXITSTATUS WIFSIGNALED */
535 /* Offset 1 gives the best switch position. */
538 if (memEQ(name, "WEXITSTATUS", 11)) {
542 *arg_result = WEXITSTATUS(WMUNGE(i));
543 return PERL_constant_ISIV;
545 return PERL_constant_NOTDEF;
550 if (memEQ(name, "WIFSIGNALED", 11)) {
554 *arg_result = WIFSIGNALED(WMUNGE(i));
555 return PERL_constant_ISIV;
557 return PERL_constant_NOTDEF;
564 return PERL_constant_NOTFOUND;
568 restore_sigmask(pTHX_ SV *osset_sv)
570 /* Fortunately, restoring the signal mask can't fail, because
571 * there's nothing we can do about it if it does -- we're not
572 * supposed to return -1 from sigaction unless the disposition
575 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
576 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
579 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
582 new(packname = "POSIX::SigSet", ...)
587 Newx(RETVAL, 1, sigset_t);
589 for (i = 1; i < items; i++)
590 sigaddset(RETVAL, SvIV(ST(i)));
602 sigaddset(sigset, sig)
607 sigdelset(sigset, sig)
620 sigismember(sigset, sig)
625 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
628 new(packname = "POSIX::Termios", ...)
633 Newx(RETVAL, 1, struct termios);
644 POSIX::Termios termios_ref
647 Safefree(termios_ref);
653 getattr(termios_ref, fd = 0)
654 POSIX::Termios termios_ref
657 RETVAL = tcgetattr(fd, termios_ref);
662 setattr(termios_ref, fd = 0, optional_actions = 0)
663 POSIX::Termios termios_ref
667 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
672 cfgetispeed(termios_ref)
673 POSIX::Termios termios_ref
676 cfgetospeed(termios_ref)
677 POSIX::Termios termios_ref
680 getiflag(termios_ref)
681 POSIX::Termios termios_ref
683 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
684 RETVAL = termios_ref->c_iflag;
686 not_here("getiflag");
693 getoflag(termios_ref)
694 POSIX::Termios termios_ref
696 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
697 RETVAL = termios_ref->c_oflag;
699 not_here("getoflag");
706 getcflag(termios_ref)
707 POSIX::Termios termios_ref
709 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
710 RETVAL = termios_ref->c_cflag;
712 not_here("getcflag");
719 getlflag(termios_ref)
720 POSIX::Termios termios_ref
722 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
723 RETVAL = termios_ref->c_lflag;
725 not_here("getlflag");
732 getcc(termios_ref, ccix)
733 POSIX::Termios termios_ref
736 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
738 croak("Bad getcc subscript");
739 RETVAL = termios_ref->c_cc[ccix];
748 cfsetispeed(termios_ref, speed)
749 POSIX::Termios termios_ref
753 cfsetospeed(termios_ref, speed)
754 POSIX::Termios termios_ref
758 setiflag(termios_ref, iflag)
759 POSIX::Termios termios_ref
762 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
763 termios_ref->c_iflag = iflag;
765 not_here("setiflag");
769 setoflag(termios_ref, oflag)
770 POSIX::Termios termios_ref
773 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
774 termios_ref->c_oflag = oflag;
776 not_here("setoflag");
780 setcflag(termios_ref, cflag)
781 POSIX::Termios termios_ref
784 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
785 termios_ref->c_cflag = cflag;
787 not_here("setcflag");
791 setlflag(termios_ref, lflag)
792 POSIX::Termios termios_ref
795 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
796 termios_ref->c_lflag = lflag;
798 not_here("setlflag");
802 setcc(termios_ref, ccix, cc)
803 POSIX::Termios termios_ref
807 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
809 croak("Bad setcc subscript");
810 termios_ref->c_cc[ccix] = cc;
816 MODULE = POSIX PACKAGE = POSIX
818 INCLUDE: const-xs.inc
821 int_macro_int(sv, iv)
828 const char * s = SvPV(sv, len);
831 /* Change this to int_macro_int(s, len, &iv, &nv);
832 if you need to return both NVs and IVs */
833 type = int_macro_int(s, len, &iv);
834 /* Return 1 or 2 items. First is error message, or undef if no error.
835 Second, if present, is found value */
837 case PERL_constant_NOTFOUND:
838 sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s));
843 case PERL_constant_NOTDEF:
844 sv = sv_2mortal(newSVpvf(
845 "Your vendor has not defined POSIX macro %s, used", s));
850 case PERL_constant_ISIV:
854 sv = sv_2mortal(newSVpvf(
855 "Unexpected return type %d while processing POSIX macro %s, used",
868 unsigned char *s = (unsigned char *) SvPV(charstring, len);
869 unsigned char *e = s + len;
870 for (RETVAL = 1; RETVAL && s < e; s++)
882 unsigned char *s = (unsigned char *) SvPV(charstring, len);
883 unsigned char *e = s + len;
884 for (RETVAL = 1; RETVAL && s < e; s++)
896 unsigned char *s = (unsigned char *) SvPV(charstring, len);
897 unsigned char *e = s + len;
898 for (RETVAL = 1; RETVAL && s < e; s++)
910 unsigned char *s = (unsigned char *) SvPV(charstring, len);
911 unsigned char *e = s + len;
912 for (RETVAL = 1; RETVAL && s < e; s++)
924 unsigned char *s = (unsigned char *) SvPV(charstring, len);
925 unsigned char *e = s + len;
926 for (RETVAL = 1; RETVAL && s < e; s++)
938 unsigned char *s = (unsigned char *) SvPV(charstring, len);
939 unsigned char *e = s + len;
940 for (RETVAL = 1; RETVAL && s < e; s++)
952 unsigned char *s = (unsigned char *) SvPV(charstring, len);
953 unsigned char *e = s + len;
954 for (RETVAL = 1; RETVAL && s < e; s++)
966 unsigned char *s = (unsigned char *) SvPV(charstring, len);
967 unsigned char *e = s + len;
968 for (RETVAL = 1; RETVAL && s < e; s++)
980 unsigned char *s = (unsigned char *) SvPV(charstring, len);
981 unsigned char *e = s + len;
982 for (RETVAL = 1; RETVAL && s < e; s++)
994 unsigned char *s = (unsigned char *) SvPV(charstring, len);
995 unsigned char *e = s + len;
996 for (RETVAL = 1; RETVAL && s < e; s++)
1003 isxdigit(charstring)
1008 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1009 unsigned char *e = s + len;
1010 for (RETVAL = 1; RETVAL && s < e; s++)
1017 open(filename, flags = O_RDONLY, mode = 0666)
1022 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1023 TAINT_PROPER("open");
1024 RETVAL = open(filename, flags, mode);
1032 #ifdef HAS_LOCALECONV
1033 struct lconv *lcbuf;
1035 sv_2mortal((SV*)RETVAL);
1036 if ((lcbuf = localeconv())) {
1038 if (lcbuf->decimal_point && *lcbuf->decimal_point)
1039 hv_store(RETVAL, "decimal_point", 13,
1040 newSVpv(lcbuf->decimal_point, 0), 0);
1041 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
1042 hv_store(RETVAL, "thousands_sep", 13,
1043 newSVpv(lcbuf->thousands_sep, 0), 0);
1044 #ifndef NO_LOCALECONV_GROUPING
1045 if (lcbuf->grouping && *lcbuf->grouping)
1046 hv_store(RETVAL, "grouping", 8,
1047 newSVpv(lcbuf->grouping, 0), 0);
1049 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
1050 hv_store(RETVAL, "int_curr_symbol", 15,
1051 newSVpv(lcbuf->int_curr_symbol, 0), 0);
1052 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
1053 hv_store(RETVAL, "currency_symbol", 15,
1054 newSVpv(lcbuf->currency_symbol, 0), 0);
1055 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
1056 hv_store(RETVAL, "mon_decimal_point", 17,
1057 newSVpv(lcbuf->mon_decimal_point, 0), 0);
1058 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1059 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
1060 hv_store(RETVAL, "mon_thousands_sep", 17,
1061 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
1063 #ifndef NO_LOCALECONV_MON_GROUPING
1064 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
1065 hv_store(RETVAL, "mon_grouping", 12,
1066 newSVpv(lcbuf->mon_grouping, 0), 0);
1068 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1069 hv_store(RETVAL, "positive_sign", 13,
1070 newSVpv(lcbuf->positive_sign, 0), 0);
1071 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1072 hv_store(RETVAL, "negative_sign", 13,
1073 newSVpv(lcbuf->negative_sign, 0), 0);
1075 if (lcbuf->int_frac_digits != CHAR_MAX)
1076 hv_store(RETVAL, "int_frac_digits", 15,
1077 newSViv(lcbuf->int_frac_digits), 0);
1078 if (lcbuf->frac_digits != CHAR_MAX)
1079 hv_store(RETVAL, "frac_digits", 11,
1080 newSViv(lcbuf->frac_digits), 0);
1081 if (lcbuf->p_cs_precedes != CHAR_MAX)
1082 hv_store(RETVAL, "p_cs_precedes", 13,
1083 newSViv(lcbuf->p_cs_precedes), 0);
1084 if (lcbuf->p_sep_by_space != CHAR_MAX)
1085 hv_store(RETVAL, "p_sep_by_space", 14,
1086 newSViv(lcbuf->p_sep_by_space), 0);
1087 if (lcbuf->n_cs_precedes != CHAR_MAX)
1088 hv_store(RETVAL, "n_cs_precedes", 13,
1089 newSViv(lcbuf->n_cs_precedes), 0);
1090 if (lcbuf->n_sep_by_space != CHAR_MAX)
1091 hv_store(RETVAL, "n_sep_by_space", 14,
1092 newSViv(lcbuf->n_sep_by_space), 0);
1093 if (lcbuf->p_sign_posn != CHAR_MAX)
1094 hv_store(RETVAL, "p_sign_posn", 11,
1095 newSViv(lcbuf->p_sign_posn), 0);
1096 if (lcbuf->n_sign_posn != CHAR_MAX)
1097 hv_store(RETVAL, "n_sign_posn", 11,
1098 newSViv(lcbuf->n_sign_posn), 0);
1101 localeconv(); /* A stub to call not_here(). */
1107 setlocale(category, locale = 0)
1111 RETVAL = setlocale(category, locale);
1113 #ifdef USE_LOCALE_CTYPE
1114 if (category == LC_CTYPE
1116 || category == LC_ALL
1122 if (category == LC_ALL)
1123 newctype = setlocale(LC_CTYPE, NULL);
1127 new_ctype(newctype);
1129 #endif /* USE_LOCALE_CTYPE */
1130 #ifdef USE_LOCALE_COLLATE
1131 if (category == LC_COLLATE
1133 || category == LC_ALL
1139 if (category == LC_ALL)
1140 newcoll = setlocale(LC_COLLATE, NULL);
1144 new_collate(newcoll);
1146 #endif /* USE_LOCALE_COLLATE */
1147 #ifdef USE_LOCALE_NUMERIC
1148 if (category == LC_NUMERIC
1150 || category == LC_ALL
1156 if (category == LC_ALL)
1157 newnum = setlocale(LC_NUMERIC, NULL);
1161 new_numeric(newnum);
1163 #endif /* USE_LOCALE_NUMERIC */
1203 /* (We already know stack is long enough.) */
1204 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1205 PUSHs(sv_2mortal(newSViv(expvar)));
1221 /* (We already know stack is long enough.) */
1222 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1223 PUSHs(sv_2mortal(newSVnv(intvar)));
1238 sigaction(sig, optaction, oldaction = 0)
1241 POSIX::SigAction oldaction
1243 #if defined(WIN32) || defined(NETWARE)
1244 RETVAL = not_here("sigaction");
1246 # This code is really grody because we're trying to make the signal
1247 # interface look beautiful, which is hard.
1250 POSIX__SigAction action;
1251 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1252 struct sigaction act;
1253 struct sigaction oact;
1257 POSIX__SigSet sigset;
1260 if (sig == 0 && SvPOK(ST(0))) {
1261 const char *s = SvPVX_const(ST(0));
1262 int i = whichsig(s);
1264 if (i < 0 && memEQ(s, "SIG", 3))
1265 i = whichsig(s + 3);
1267 if (ckWARN(WARN_SIGNAL))
1268 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1269 "No such signal: SIG%s", s);
1275 sigsvp = hv_fetch(GvHVn(siggv),
1277 strlen(PL_sig_name[sig]),
1280 /* Check optaction and set action */
1281 if(SvTRUE(optaction)) {
1282 if(sv_isa(optaction, "POSIX::SigAction"))
1283 action = (HV*)SvRV(optaction);
1285 croak("action is not of type POSIX::SigAction");
1291 /* sigaction() is supposed to look atomic. In particular, any
1292 * signal handler invoked during a sigaction() call should
1293 * see either the old or the new disposition, and not something
1294 * in between. We use sigprocmask() to make it so.
1297 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1301 /* Restore signal mask no matter how we exit this block. */
1302 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1303 SAVEFREESV( osset_sv );
1304 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1306 RETVAL=-1; /* In case both oldaction and action are 0. */
1308 /* Remember old disposition if desired. */
1310 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
1312 croak("Can't supply an oldaction without a HANDLER");
1313 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1314 sv_setsv(*svp, *sigsvp);
1317 sv_setpv(*svp, "DEFAULT");
1319 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1322 /* Get back the mask. */
1323 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
1324 if (sv_isa(*svp, "POSIX::SigSet")) {
1325 IV tmp = SvIV((SV*)SvRV(*svp));
1326 sigset = INT2PTR(sigset_t*, tmp);
1329 Newx(sigset, 1, sigset_t);
1330 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1332 *sigset = oact.sa_mask;
1334 /* Get back the flags. */
1335 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
1336 sv_setiv(*svp, oact.sa_flags);
1338 /* Get back whether the old handler used safe signals. */
1339 svp = hv_fetch(oldaction, "SAFE", 4, TRUE);
1340 sv_setiv(*svp, oact.sa_handler == PL_csighandlerp);
1344 /* Safe signals use "csighandler", which vectors through the
1345 PL_sighandlerp pointer when it's safe to do so.
1346 (BTW, "csighandler" is very different from "sighandler".) */
1347 svp = hv_fetch(action, "SAFE", 4, FALSE);
1348 act.sa_handler = (*svp && SvTRUE(*svp))
1349 ? PL_csighandlerp : PL_sighandlerp;
1351 /* Vector new Perl handler through %SIG.
1352 (The core signal handlers read %SIG to dispatch.) */
1353 svp = hv_fetch(action, "HANDLER", 7, FALSE);
1355 croak("Can't supply an action without a HANDLER");
1356 sv_setsv(*sigsvp, *svp);
1358 /* This call actually calls sigaction() with almost the
1359 right settings, including appropriate interpretation
1360 of DEFAULT and IGNORE. However, why are we doing
1361 this when we're about to do it again just below? XXX */
1364 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1366 const char *s=SvPVX_const(*svp);
1367 if(strEQ(s,"IGNORE")) {
1368 act.sa_handler = SIG_IGN;
1370 else if(strEQ(s,"DEFAULT")) {
1371 act.sa_handler = SIG_DFL;
1375 /* Set up any desired mask. */
1376 svp = hv_fetch(action, "MASK", 4, FALSE);
1377 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1378 IV tmp = SvIV((SV*)SvRV(*svp));
1379 sigset = INT2PTR(sigset_t*, tmp);
1380 act.sa_mask = *sigset;
1383 sigemptyset(& act.sa_mask);
1385 /* Set up any desired flags. */
1386 svp = hv_fetch(action, "FLAGS", 5, FALSE);
1387 act.sa_flags = svp ? SvIV(*svp) : 0;
1389 /* Don't worry about cleaning up *sigsvp if this fails,
1390 * because that means we tried to disposition a
1391 * nonblockable signal, in which case *sigsvp is
1392 * essentially meaningless anyway.
1394 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1407 POSIX::SigSet sigset
1410 sigprocmask(how, sigset, oldsigset = 0)
1412 POSIX::SigSet sigset = NO_INIT
1413 POSIX::SigSet oldsigset = NO_INIT
1415 if (! SvOK(ST(1))) {
1417 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1418 IV tmp = SvIV((SV*)SvRV(ST(1)));
1419 sigset = INT2PTR(POSIX__SigSet,tmp);
1421 croak("sigset is not of type POSIX::SigSet");
1424 if (items < 3 || ! SvOK(ST(2))) {
1426 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1427 IV tmp = SvIV((SV*)SvRV(ST(2)));
1428 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1430 croak("oldsigset is not of type POSIX::SigSet");
1434 sigsuspend(signal_mask)
1435 POSIX::SigSet signal_mask
1455 lseek(fd, offset, whence)
1460 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1461 RETVAL = sizeof(Off_t) > sizeof(IV)
1462 ? newSVnv((NV)pos) : newSViv((IV)pos);
1471 if ((incr = nice(incr)) != -1 || errno == 0) {
1473 XPUSHs(sv_2mortal(newSVpvn("0 but true", 10)));
1475 XPUSHs(sv_2mortal(newSViv(incr)));
1482 if (pipe(fds) != -1) {
1484 PUSHs(sv_2mortal(newSViv(fds[0])));
1485 PUSHs(sv_2mortal(newSViv(fds[1])));
1489 read(fd, buffer, nbytes)
1491 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1495 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1498 SvCUR_set(sv_buffer, RETVAL);
1499 SvPOK_only(sv_buffer);
1500 *SvEND(sv_buffer) = '\0';
1501 SvTAINTED_on(sv_buffer);
1517 tcsetpgrp(fd, pgrp_id)
1526 if (uname(&buf) >= 0) {
1528 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1529 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1530 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1531 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1532 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1535 uname((char *) 0); /* A stub to call not_here(). */
1539 write(fd, buffer, nbytes)
1550 RETVAL = newSVpvn("", 0);
1551 SvGROW(RETVAL, L_tmpnam);
1552 len = strlen(tmpnam(SvPV(RETVAL, i)));
1553 SvCUR_set(RETVAL, len);
1566 mbstowcs(s, pwcs, n)
1578 wcstombs(s, pwcs, n)
1600 SET_NUMERIC_LOCAL();
1601 num = strtod(str, &unparsed);
1602 PUSHs(sv_2mortal(newSVnv(num)));
1603 if (GIMME == G_ARRAY) {
1606 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1608 PUSHs(&PL_sv_undef);
1612 strtol(str, base = 0)
1619 num = strtol(str, &unparsed, base);
1620 #if IVSIZE <= LONGSIZE
1621 if (num < IV_MIN || num > IV_MAX)
1622 PUSHs(sv_2mortal(newSVnv((double)num)));
1625 PUSHs(sv_2mortal(newSViv((IV)num)));
1626 if (GIMME == G_ARRAY) {
1629 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1631 PUSHs(&PL_sv_undef);
1635 strtoul(str, base = 0)
1642 num = strtoul(str, &unparsed, base);
1643 #if IVSIZE <= LONGSIZE
1645 PUSHs(sv_2mortal(newSVnv((double)num)));
1648 PUSHs(sv_2mortal(newSViv((IV)num)));
1649 if (GIMME == G_ARRAY) {
1652 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1654 PUSHs(&PL_sv_undef);
1664 char *p = SvPV(src,srclen);
1666 ST(0) = sv_2mortal(NEWSV(800,srclen*4+1));
1667 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1668 if (dstlen > srclen) {
1670 SvGROW(ST(0), dstlen);
1671 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1674 SvCUR_set(ST(0), dstlen);
1679 mkfifo(filename, mode)
1683 TAINT_PROPER("mkfifo");
1684 RETVAL = mkfifo(filename, mode);
1700 tcflush(fd, queue_selector)
1705 tcsendbreak(fd, duration)
1710 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1723 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1726 mytm.tm_hour = hour;
1727 mytm.tm_mday = mday;
1729 mytm.tm_year = year;
1730 mytm.tm_wday = wday;
1731 mytm.tm_yday = yday;
1732 mytm.tm_isdst = isdst;
1733 RETVAL = asctime(&mytm);
1750 realtime = times( &tms );
1752 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1753 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1754 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1755 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1756 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1759 difftime(time1, time2)
1764 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1777 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1780 mytm.tm_hour = hour;
1781 mytm.tm_mday = mday;
1783 mytm.tm_year = year;
1784 mytm.tm_wday = wday;
1785 mytm.tm_yday = yday;
1786 mytm.tm_isdst = isdst;
1787 RETVAL = mktime(&mytm);
1792 #XXX: if $xsubpp::WantOptimize is always the default
1793 # sv_setpv(TARG, ...) could be used rather than
1794 # ST(0) = sv_2mortal(newSVpv(...))
1796 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1809 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1811 ST(0) = sv_2mortal(newSVpv(buf, 0));
1823 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1824 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1827 access(filename, mode)
1835 #ifdef HAS_CTERMID_R
1836 s = safemalloc((size_t) L_ctermid);
1838 RETVAL = ctermid(s);
1842 #ifdef HAS_CTERMID_R
1856 pathconf(filename, name)
1870 PL_egid = getegid();
1881 PL_euid = geteuid();
1899 XSprePUSH; PUSHTARG;
1903 lchown(uid, gid, path)
1909 /* yes, the order of arguments is different,
1910 * but consistent with CORE::chown() */
1911 RETVAL = lchown(path, uid, gid);
1913 RETVAL = not_here("lchown");