10 * Ideally this should be somewhere down in the includes
11 * but putting it in other places is giving compiler errors.
12 * Also here I am unable to check for HAS_UNAME since it wouldn't have
13 * yet come into the file at this stage - sgp 18th Oct 2000
15 #include <sys/utsname.h>
18 #define PERL_NO_GET_CONTEXT
21 #define PERLIO_NOT_STDIO 1
24 #if defined(PERL_IMPLICIT_SYS)
28 # define open PerlLIO_open3
31 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
58 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
59 metaconfig for future extension writers. We don't use them in POSIX.
60 (This is really sneaky :-) --AD
62 #if defined(I_TERMIOS)
70 #include <sys/types.h>
75 #ifdef MACOS_TRADITIONAL
81 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE)
82 extern char *tzname[];
85 #if !defined(WIN32) || (defined(__MINGW32__) && !defined(tzname))
86 char *tzname[] = { "" , "" };
90 #if defined(__VMS) && !defined(__POSIX_SOURCE)
91 # include <libdef.h> /* LIB$_INVARG constant */
92 # include <lib$routines.h> /* prototype for lib$ediv() */
93 # include <starlet.h> /* prototype for sys$gettim() */
94 # if DECC_VERSION < 50000000
95 # define pid_t int /* old versions of DECC miss this in types.h */
99 # define mkfifo(a,b) (not_here("mkfifo"),-1)
100 # define tzset() not_here("tzset")
102 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
103 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
104 # include <utsname.h>
105 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
107 /* The POSIX notion of ttyname() is better served by getname() under VMS */
108 static char ttnambuf[64];
109 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
111 /* The non-POSIX CRTL times() has void return type, so we just get the
112 current time directly */
113 clock_t vms_times(struct tms *bufptr) {
116 /* Get wall time and convert to 10 ms intervals to
117 * produce the return value that the POSIX standard expects */
118 # if defined(__DECC) && defined (__ALPHA)
121 _ckvmssts(sys$gettim(&vmstime));
123 retval = vmstime & 0x7fffffff;
125 /* (Older hw or ccs don't have an atomic 64-bit type, so we
126 * juggle 32-bit ints (and a float) to produce a time_t result
127 * with minimal loss of information.) */
128 long int vmstime[2],remainder,divisor = 100000;
129 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
130 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
131 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
133 /* Fill in the struct tms using the CRTL routine . . .*/
134 times((tbuffer_t *)bufptr);
135 return (clock_t) retval;
137 # define times(t) vms_times(t)
139 #if defined (__CYGWIN__)
140 # define tzname _tzname
142 #if defined (WIN32) || defined (NETWARE)
144 # define mkfifo(a,b) not_here("mkfifo")
145 # define ttyname(a) (char*)not_here("ttyname")
146 # define sigset_t long
149 # define tzname _tzname
152 # define mode_t short
155 # define mode_t short
157 # define tzset() not_here("tzset")
159 # ifndef _POSIX_OPEN_MAX
160 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
163 # define sigaction(a,b,c) not_here("sigaction")
164 # define sigpending(a) not_here("sigpending")
165 # define sigprocmask(a,b,c) not_here("sigprocmask")
166 # define sigsuspend(a) not_here("sigsuspend")
167 # define sigemptyset(a) not_here("sigemptyset")
168 # define sigaddset(a,b) not_here("sigaddset")
169 # define sigdelset(a,b) not_here("sigdelset")
170 # define sigfillset(a) not_here("sigfillset")
171 # define sigismember(a,b) not_here("sigismember")
175 # define setuid(a) not_here("setuid")
176 # define setgid(a) not_here("setgid")
181 # if defined(OS2) || defined(MACOS_TRADITIONAL)
182 # define mkfifo(a,b) not_here("mkfifo")
183 # else /* !( defined OS2 ) */
185 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
188 # endif /* !HAS_MKFIFO */
190 # ifdef MACOS_TRADITIONAL
191 # define ttyname(a) (char*)not_here("ttyname")
192 # define tzset() not_here("tzset")
195 # include <sys/times.h>
197 # include <sys/utsname.h>
199 # include <sys/wait.h>
204 #endif /* WIN32 || NETWARE */
208 typedef long SysRetLong;
209 typedef sigset_t* POSIX__SigSet;
210 typedef HV* POSIX__SigAction;
212 typedef struct termios* POSIX__Termios;
213 #else /* Define termios types to int, and call not_here for the functions.*/
214 #define POSIX__Termios int
218 #define cfgetispeed(x) not_here("cfgetispeed")
219 #define cfgetospeed(x) not_here("cfgetospeed")
220 #define tcdrain(x) not_here("tcdrain")
221 #define tcflush(x,y) not_here("tcflush")
222 #define tcsendbreak(x,y) not_here("tcsendbreak")
223 #define cfsetispeed(x,y) not_here("cfsetispeed")
224 #define cfsetospeed(x,y) not_here("cfsetospeed")
225 #define ctermid(x) (char *) not_here("ctermid")
226 #define tcflow(x,y) not_here("tcflow")
227 #define tcgetattr(x,y) not_here("tcgetattr")
228 #define tcsetattr(x,y,z) not_here("tcsetattr")
231 /* Possibly needed prototypes */
232 char *cuserid (char *);
234 double strtod (const char *, char **);
235 long strtol (const char *, char **, int);
236 unsigned long strtoul (const char *, char **, int);
240 #define cuserid(a) (char *) not_here("cuserid")
244 #define difftime(a,b) not_here("difftime")
247 #ifndef HAS_FPATHCONF
248 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
251 #define mktime(a) not_here("mktime")
254 #define nice(a) not_here("nice")
257 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
260 #define sysconf(n) (SysRetLong) not_here("sysconf")
263 #define readlink(a,b,c) not_here("readlink")
266 #define setpgid(a,b) not_here("setpgid")
269 #define setsid() not_here("setsid")
272 #define strcoll(s1,s2) not_here("strcoll")
275 #define strtod(s1,s2) not_here("strtod")
278 #define strtol(s1,s2,b) not_here("strtol")
281 #define strtoul(s1,s2,b) not_here("strtoul")
284 #define strxfrm(s1,s2,n) not_here("strxfrm")
286 #ifndef HAS_TCGETPGRP
287 #define tcgetpgrp(a) not_here("tcgetpgrp")
289 #ifndef HAS_TCSETPGRP
290 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
294 #define times(a) not_here("times")
298 #define uname(a) not_here("uname")
301 #define waitpid(a,b,c) not_here("waitpid")
306 #define mblen(a,b) not_here("mblen")
310 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
313 #define mbtowc(pwc, s, n) not_here("mbtowc")
316 #define wcstombs(s, pwcs, n) not_here("wcstombs")
319 #define wctomb(s, wchar) not_here("wcstombs")
321 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
322 /* If we don't have these functions, then we wouldn't have gotten a typedef
323 for wchar_t, the wide character type. Defining wchar_t allows the
324 functions referencing it to compile. Its actual type is then meaningless,
325 since without the above functions, all sections using it end up calling
326 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
332 #ifndef HAS_LOCALECONV
333 #define localeconv() not_here("localeconv")
336 #ifdef HAS_LONG_DOUBLE
337 # if LONG_DOUBLESIZE > NVSIZE
338 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
342 #ifndef HAS_LONG_DOUBLE
354 /* Background: in most systems the low byte of the wait status
355 * is the signal (the lowest 7 bits) and the coredump flag is
356 * the eight bit, and the second lowest byte is the exit status.
357 * BeOS bucks the trend and has the bytes in different order.
358 * See beos/beos.c for how the reality is bent even in BeOS
359 * to follow the traditional. However, to make the POSIX
360 * wait W*() macros to work in BeOS, we need to unbend the
361 * reality back in place. --jhi */
363 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
365 # define WMUNGE(x) (x)
371 croak("POSIX::%s not implemented on this architecture", s);
375 #include "const-c.inc"
377 /* These were implemented in the old "constant" subroutine. They are actually
378 macros that take an integer argument and return an integer result. */
380 int_macro_int (const char *name, STRLEN len, IV *arg_result) {
381 /* Initially switch on the length of the name. */
382 /* This code has been edited from a "constant" function generated by:
384 use ExtUtils::Constant qw (constant_types C_constant XS_constant);
386 my $types = {map {($_, 1)} qw(IV)};
387 my @names = (qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS WIFEXITED
388 WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
390 print constant_types(); # macro defs
391 foreach (C_constant ("POSIX", 'int_macro_int', 'IV', $types, undef, 5, @names) ) {
392 print $_, "\n"; # C constant subs
394 print "#### XS Section:\n";
395 print XS_constant ("POSIX", $types);
401 /* Names all of length 7. */
402 /* S_ISBLK S_ISCHR S_ISDIR S_ISREG */
403 /* Offset 5 gives the best switch position. */
406 if (memEQ(name, "S_ISREG", 7)) {
409 *arg_result = S_ISREG(*arg_result);
410 return PERL_constant_ISIV;
412 return PERL_constant_NOTDEF;
417 if (memEQ(name, "S_ISCHR", 7)) {
420 *arg_result = S_ISCHR(*arg_result);
421 return PERL_constant_ISIV;
423 return PERL_constant_NOTDEF;
428 if (memEQ(name, "S_ISDIR", 7)) {
431 *arg_result = S_ISDIR(*arg_result);
432 return PERL_constant_ISIV;
434 return PERL_constant_NOTDEF;
439 if (memEQ(name, "S_ISBLK", 7)) {
442 *arg_result = S_ISBLK(*arg_result);
443 return PERL_constant_ISIV;
445 return PERL_constant_NOTDEF;
452 /* Names all of length 8. */
453 /* S_ISFIFO WSTOPSIG WTERMSIG */
454 /* Offset 3 gives the best switch position. */
457 if (memEQ(name, "WSTOPSIG", 8)) {
460 *arg_result = WSTOPSIG(WMUNGE(*arg_result));
461 return PERL_constant_ISIV;
463 return PERL_constant_NOTDEF;
468 if (memEQ(name, "WTERMSIG", 8)) {
471 *arg_result = WTERMSIG(WMUNGE(*arg_result));
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)) {
494 *arg_result = WIFEXITED(WMUNGE(*arg_result));
495 return PERL_constant_ISIV;
497 return PERL_constant_NOTDEF;
502 if (memEQ(name, "WIFSTOPPED", 10)) {
504 *arg_result = WIFSTOPPED(WMUNGE(*arg_result));
505 return PERL_constant_ISIV;
507 return PERL_constant_NOTDEF;
512 /* Names all of length 11. */
513 /* WEXITSTATUS WIFSIGNALED */
514 /* Offset 1 gives the best switch position. */
517 if (memEQ(name, "WEXITSTATUS", 11)) {
520 *arg_result = WEXITSTATUS(WMUNGE(*arg_result));
521 return PERL_constant_ISIV;
523 return PERL_constant_NOTDEF;
528 if (memEQ(name, "WIFSIGNALED", 11)) {
531 *arg_result = WIFSIGNALED(WMUNGE(*arg_result));
532 return PERL_constant_ISIV;
534 return PERL_constant_NOTDEF;
541 return PERL_constant_NOTFOUND;
545 restore_sigmask(pTHX_ SV *osset_sv)
547 /* Fortunately, restoring the signal mask can't fail, because
548 * there's nothing we can do about it if it does -- we're not
549 * supposed to return -1 from sigaction unless the disposition
552 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
553 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
556 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
559 new(packname = "POSIX::SigSet", ...)
564 New(0, RETVAL, 1, sigset_t);
566 for (i = 1; i < items; i++)
567 sigaddset(RETVAL, SvIV(ST(i)));
579 sigaddset(sigset, sig)
584 sigdelset(sigset, sig)
597 sigismember(sigset, sig)
602 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
605 new(packname = "POSIX::Termios", ...)
610 New(0, RETVAL, 1, struct termios);
621 POSIX::Termios termios_ref
624 Safefree(termios_ref);
630 getattr(termios_ref, fd = 0)
631 POSIX::Termios termios_ref
634 RETVAL = tcgetattr(fd, termios_ref);
639 setattr(termios_ref, fd = 0, optional_actions = 0)
640 POSIX::Termios termios_ref
644 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
649 cfgetispeed(termios_ref)
650 POSIX::Termios termios_ref
653 cfgetospeed(termios_ref)
654 POSIX::Termios termios_ref
657 getiflag(termios_ref)
658 POSIX::Termios termios_ref
660 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
661 RETVAL = termios_ref->c_iflag;
663 not_here("getiflag");
670 getoflag(termios_ref)
671 POSIX::Termios termios_ref
673 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
674 RETVAL = termios_ref->c_oflag;
676 not_here("getoflag");
683 getcflag(termios_ref)
684 POSIX::Termios termios_ref
686 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
687 RETVAL = termios_ref->c_cflag;
689 not_here("getcflag");
696 getlflag(termios_ref)
697 POSIX::Termios termios_ref
699 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
700 RETVAL = termios_ref->c_lflag;
702 not_here("getlflag");
709 getcc(termios_ref, ccix)
710 POSIX::Termios termios_ref
713 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
715 croak("Bad getcc subscript");
716 RETVAL = termios_ref->c_cc[ccix];
725 cfsetispeed(termios_ref, speed)
726 POSIX::Termios termios_ref
730 cfsetospeed(termios_ref, speed)
731 POSIX::Termios termios_ref
735 setiflag(termios_ref, iflag)
736 POSIX::Termios termios_ref
739 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
740 termios_ref->c_iflag = iflag;
742 not_here("setiflag");
746 setoflag(termios_ref, oflag)
747 POSIX::Termios termios_ref
750 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
751 termios_ref->c_oflag = oflag;
753 not_here("setoflag");
757 setcflag(termios_ref, cflag)
758 POSIX::Termios termios_ref
761 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
762 termios_ref->c_cflag = cflag;
764 not_here("setcflag");
768 setlflag(termios_ref, lflag)
769 POSIX::Termios termios_ref
772 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
773 termios_ref->c_lflag = lflag;
775 not_here("setlflag");
779 setcc(termios_ref, ccix, cc)
780 POSIX::Termios termios_ref
784 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
786 croak("Bad setcc subscript");
787 termios_ref->c_cc[ccix] = cc;
793 MODULE = POSIX PACKAGE = POSIX
795 INCLUDE: const-xs.inc
798 int_macro_int(sv, iv)
805 const char * s = SvPV(sv, len);
808 /* Change this to int_macro_int(s, len, &iv, &nv);
809 if you need to return both NVs and IVs */
810 type = int_macro_int(s, len, &iv);
811 /* Return 1 or 2 items. First is error message, or undef if no error.
812 Second, if present, is found value */
814 case PERL_constant_NOTFOUND:
815 sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s));
820 case PERL_constant_NOTDEF:
821 sv = sv_2mortal(newSVpvf(
822 "Your vendor has not defined POSIX macro %s, used", s));
827 case PERL_constant_ISIV:
831 sv = sv_2mortal(newSVpvf(
832 "Unexpected return type %d while processing POSIX macro %s, used",
841 unsigned char * charstring
843 unsigned char *s = charstring;
844 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
845 for (RETVAL = 1; RETVAL && s < e; s++)
853 unsigned char * charstring
855 unsigned char *s = charstring;
856 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
857 for (RETVAL = 1; RETVAL && s < e; s++)
865 unsigned char * charstring
867 unsigned char *s = charstring;
868 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
869 for (RETVAL = 1; RETVAL && s < e; s++)
877 unsigned char * charstring
879 unsigned char *s = charstring;
880 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
881 for (RETVAL = 1; RETVAL && s < e; s++)
889 unsigned char * charstring
891 unsigned char *s = charstring;
892 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
893 for (RETVAL = 1; RETVAL && s < e; s++)
901 unsigned char * charstring
903 unsigned char *s = charstring;
904 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
905 for (RETVAL = 1; RETVAL && s < e; s++)
913 unsigned char * charstring
915 unsigned char *s = charstring;
916 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
917 for (RETVAL = 1; RETVAL && s < e; s++)
925 unsigned char * charstring
927 unsigned char *s = charstring;
928 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
929 for (RETVAL = 1; RETVAL && s < e; s++)
937 unsigned char * charstring
939 unsigned char *s = charstring;
940 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
941 for (RETVAL = 1; RETVAL && s < e; s++)
949 unsigned char * charstring
951 unsigned char *s = charstring;
952 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
953 for (RETVAL = 1; RETVAL && s < e; s++)
961 unsigned char * charstring
963 unsigned char *s = charstring;
964 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
965 for (RETVAL = 1; RETVAL && s < e; s++)
972 open(filename, flags = O_RDONLY, mode = 0666)
977 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
978 TAINT_PROPER("open");
979 RETVAL = open(filename, flags, mode);
987 #ifdef HAS_LOCALECONV
990 if ((lcbuf = localeconv())) {
992 if (lcbuf->decimal_point && *lcbuf->decimal_point)
993 hv_store(RETVAL, "decimal_point", 13,
994 newSVpv(lcbuf->decimal_point, 0), 0);
995 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
996 hv_store(RETVAL, "thousands_sep", 13,
997 newSVpv(lcbuf->thousands_sep, 0), 0);
998 #ifndef NO_LOCALECONV_GROUPING
999 if (lcbuf->grouping && *lcbuf->grouping)
1000 hv_store(RETVAL, "grouping", 8,
1001 newSVpv(lcbuf->grouping, 0), 0);
1003 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
1004 hv_store(RETVAL, "int_curr_symbol", 15,
1005 newSVpv(lcbuf->int_curr_symbol, 0), 0);
1006 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
1007 hv_store(RETVAL, "currency_symbol", 15,
1008 newSVpv(lcbuf->currency_symbol, 0), 0);
1009 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
1010 hv_store(RETVAL, "mon_decimal_point", 17,
1011 newSVpv(lcbuf->mon_decimal_point, 0), 0);
1012 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1013 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
1014 hv_store(RETVAL, "mon_thousands_sep", 17,
1015 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
1017 #ifndef NO_LOCALECONV_MON_GROUPING
1018 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
1019 hv_store(RETVAL, "mon_grouping", 12,
1020 newSVpv(lcbuf->mon_grouping, 0), 0);
1022 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1023 hv_store(RETVAL, "positive_sign", 13,
1024 newSVpv(lcbuf->positive_sign, 0), 0);
1025 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1026 hv_store(RETVAL, "negative_sign", 13,
1027 newSVpv(lcbuf->negative_sign, 0), 0);
1029 if (lcbuf->int_frac_digits != CHAR_MAX)
1030 hv_store(RETVAL, "int_frac_digits", 15,
1031 newSViv(lcbuf->int_frac_digits), 0);
1032 if (lcbuf->frac_digits != CHAR_MAX)
1033 hv_store(RETVAL, "frac_digits", 11,
1034 newSViv(lcbuf->frac_digits), 0);
1035 if (lcbuf->p_cs_precedes != CHAR_MAX)
1036 hv_store(RETVAL, "p_cs_precedes", 13,
1037 newSViv(lcbuf->p_cs_precedes), 0);
1038 if (lcbuf->p_sep_by_space != CHAR_MAX)
1039 hv_store(RETVAL, "p_sep_by_space", 14,
1040 newSViv(lcbuf->p_sep_by_space), 0);
1041 if (lcbuf->n_cs_precedes != CHAR_MAX)
1042 hv_store(RETVAL, "n_cs_precedes", 13,
1043 newSViv(lcbuf->n_cs_precedes), 0);
1044 if (lcbuf->n_sep_by_space != CHAR_MAX)
1045 hv_store(RETVAL, "n_sep_by_space", 14,
1046 newSViv(lcbuf->n_sep_by_space), 0);
1047 if (lcbuf->p_sign_posn != CHAR_MAX)
1048 hv_store(RETVAL, "p_sign_posn", 11,
1049 newSViv(lcbuf->p_sign_posn), 0);
1050 if (lcbuf->n_sign_posn != CHAR_MAX)
1051 hv_store(RETVAL, "n_sign_posn", 11,
1052 newSViv(lcbuf->n_sign_posn), 0);
1055 localeconv(); /* A stub to call not_here(). */
1061 setlocale(category, locale = 0)
1065 RETVAL = setlocale(category, locale);
1067 #ifdef USE_LOCALE_CTYPE
1068 if (category == LC_CTYPE
1070 || category == LC_ALL
1076 if (category == LC_ALL)
1077 newctype = setlocale(LC_CTYPE, NULL);
1081 new_ctype(newctype);
1083 #endif /* USE_LOCALE_CTYPE */
1084 #ifdef USE_LOCALE_COLLATE
1085 if (category == LC_COLLATE
1087 || category == LC_ALL
1093 if (category == LC_ALL)
1094 newcoll = setlocale(LC_COLLATE, NULL);
1098 new_collate(newcoll);
1100 #endif /* USE_LOCALE_COLLATE */
1101 #ifdef USE_LOCALE_NUMERIC
1102 if (category == LC_NUMERIC
1104 || category == LC_ALL
1110 if (category == LC_ALL)
1111 newnum = setlocale(LC_NUMERIC, NULL);
1115 new_numeric(newnum);
1117 #endif /* USE_LOCALE_NUMERIC */
1157 /* (We already know stack is long enough.) */
1158 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1159 PUSHs(sv_2mortal(newSViv(expvar)));
1175 /* (We already know stack is long enough.) */
1176 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1177 PUSHs(sv_2mortal(newSVnv(intvar)));
1192 sigaction(sig, optaction, oldaction = 0)
1195 POSIX::SigAction oldaction
1197 #if defined(WIN32) || defined(NETWARE)
1198 RETVAL = not_here("sigaction");
1200 # This code is really grody because we're trying to make the signal
1201 # interface look beautiful, which is hard.
1204 POSIX__SigAction action;
1205 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1206 struct sigaction act;
1207 struct sigaction oact;
1211 POSIX__SigSet sigset;
1213 SV** sigsvp = hv_fetch(GvHVn(siggv),
1215 strlen(PL_sig_name[sig]),
1218 /* Check optaction and set action */
1219 if(SvTRUE(optaction)) {
1220 if(sv_isa(optaction, "POSIX::SigAction"))
1221 action = (HV*)SvRV(optaction);
1223 croak("action is not of type POSIX::SigAction");
1229 /* sigaction() is supposed to look atomic. In particular, any
1230 * signal handler invoked during a sigaction() call should
1231 * see either the old or the new disposition, and not something
1232 * in between. We use sigprocmask() to make it so.
1235 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1239 /* Restore signal mask no matter how we exit this block. */
1240 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1241 SAVEFREESV( osset_sv );
1242 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1244 RETVAL=-1; /* In case both oldaction and action are 0. */
1246 /* Remember old disposition if desired. */
1248 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
1250 croak("Can't supply an oldaction without a HANDLER");
1251 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1252 sv_setsv(*svp, *sigsvp);
1255 sv_setpv(*svp, "DEFAULT");
1257 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1260 /* Get back the mask. */
1261 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
1262 if (sv_isa(*svp, "POSIX::SigSet")) {
1263 IV tmp = SvIV((SV*)SvRV(*svp));
1264 sigset = INT2PTR(sigset_t*, tmp);
1267 New(0, sigset, 1, sigset_t);
1268 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1270 *sigset = oact.sa_mask;
1272 /* Get back the flags. */
1273 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
1274 sv_setiv(*svp, oact.sa_flags);
1278 /* Vector new handler through %SIG. (We always use sighandler
1279 for the C signal handler, which reads %SIG to dispatch.) */
1280 svp = hv_fetch(action, "HANDLER", 7, FALSE);
1282 croak("Can't supply an action without a HANDLER");
1283 sv_setsv(*sigsvp, *svp);
1284 mg_set(*sigsvp); /* handles DEFAULT and IGNORE */
1286 char *s=SvPVX(*svp);
1287 if(strEQ(s,"IGNORE")) {
1288 act.sa_handler = SIG_IGN;
1290 else if(strEQ(s,"DEFAULT")) {
1291 act.sa_handler = SIG_DFL;
1294 act.sa_handler = PL_sighandlerp;
1298 act.sa_handler = PL_sighandlerp;
1301 /* Set up any desired mask. */
1302 svp = hv_fetch(action, "MASK", 4, FALSE);
1303 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1304 IV tmp = SvIV((SV*)SvRV(*svp));
1305 sigset = INT2PTR(sigset_t*, tmp);
1306 act.sa_mask = *sigset;
1309 sigemptyset(& act.sa_mask);
1311 /* Set up any desired flags. */
1312 svp = hv_fetch(action, "FLAGS", 5, FALSE);
1313 act.sa_flags = svp ? SvIV(*svp) : 0;
1315 /* Don't worry about cleaning up *sigsvp if this fails,
1316 * because that means we tried to disposition a
1317 * nonblockable signal, in which case *sigsvp is
1318 * essentially meaningless anyway.
1320 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1333 POSIX::SigSet sigset
1336 sigprocmask(how, sigset, oldsigset = 0)
1338 POSIX::SigSet sigset
1339 POSIX::SigSet oldsigset = NO_INIT
1344 else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
1345 IV tmp = SvIV((SV*)SvRV(ST(2)));
1346 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1349 New(0, oldsigset, 1, sigset_t);
1350 sigemptyset(oldsigset);
1351 sv_setref_pv(ST(2), "POSIX::SigSet", (void*)oldsigset);
1355 sigsuspend(signal_mask)
1356 POSIX::SigSet signal_mask
1376 lseek(fd, offset, whence)
1389 if (pipe(fds) != -1) {
1391 PUSHs(sv_2mortal(newSViv(fds[0])));
1392 PUSHs(sv_2mortal(newSViv(fds[1])));
1396 read(fd, buffer, nbytes)
1398 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1402 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1405 SvCUR(sv_buffer) = RETVAL;
1406 SvPOK_only(sv_buffer);
1407 *SvEND(sv_buffer) = '\0';
1408 SvTAINTED_on(sv_buffer);
1424 tcsetpgrp(fd, pgrp_id)
1433 if (uname(&buf) >= 0) {
1435 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1436 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1437 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1438 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1439 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1442 uname((char *) 0); /* A stub to call not_here(). */
1446 write(fd, buffer, nbytes)
1457 RETVAL = newSVpvn("", 0);
1458 SvGROW(RETVAL, L_tmpnam);
1459 len = strlen(tmpnam(SvPV(RETVAL, i)));
1460 SvCUR_set(RETVAL, len);
1473 mbstowcs(s, pwcs, n)
1485 wcstombs(s, pwcs, n)
1507 SET_NUMERIC_LOCAL();
1508 num = strtod(str, &unparsed);
1509 PUSHs(sv_2mortal(newSVnv(num)));
1510 if (GIMME == G_ARRAY) {
1513 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1515 PUSHs(&PL_sv_undef);
1519 strtol(str, base = 0)
1526 num = strtol(str, &unparsed, base);
1527 #if IVSIZE <= LONGSIZE
1528 if (num < IV_MIN || num > IV_MAX)
1529 PUSHs(sv_2mortal(newSVnv((double)num)));
1532 PUSHs(sv_2mortal(newSViv((IV)num)));
1533 if (GIMME == G_ARRAY) {
1536 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1538 PUSHs(&PL_sv_undef);
1542 strtoul(str, base = 0)
1549 num = strtoul(str, &unparsed, base);
1551 PUSHs(sv_2mortal(newSViv((IV)num)));
1553 PUSHs(sv_2mortal(newSVnv((double)num)));
1554 if (GIMME == G_ARRAY) {
1557 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1559 PUSHs(&PL_sv_undef);
1569 char *p = SvPV(src,srclen);
1571 ST(0) = sv_2mortal(NEWSV(800,srclen));
1572 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1573 if (dstlen > srclen) {
1575 SvGROW(ST(0), dstlen);
1576 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1579 SvCUR(ST(0)) = dstlen;
1584 mkfifo(filename, mode)
1588 TAINT_PROPER("mkfifo");
1589 RETVAL = mkfifo(filename, mode);
1605 tcflush(fd, queue_selector)
1610 tcsendbreak(fd, duration)
1615 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1628 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1631 mytm.tm_hour = hour;
1632 mytm.tm_mday = mday;
1634 mytm.tm_year = year;
1635 mytm.tm_wday = wday;
1636 mytm.tm_yday = yday;
1637 mytm.tm_isdst = isdst;
1638 RETVAL = asctime(&mytm);
1655 realtime = times( &tms );
1657 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1658 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1659 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1660 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1661 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1664 difftime(time1, time2)
1669 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1682 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1685 mytm.tm_hour = hour;
1686 mytm.tm_mday = mday;
1688 mytm.tm_year = year;
1689 mytm.tm_wday = wday;
1690 mytm.tm_yday = yday;
1691 mytm.tm_isdst = isdst;
1692 RETVAL = mktime(&mytm);
1697 #XXX: if $xsubpp::WantOptimize is always the default
1698 # sv_setpv(TARG, ...) could be used rather than
1699 # ST(0) = sv_2mortal(newSVpv(...))
1701 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1714 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1716 ST(0) = sv_2mortal(newSVpv(buf, 0));
1728 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1729 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1732 access(filename, mode)
1750 pathconf(filename, name)
1779 XSprePUSH; PUSHTARG;