This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #53746] bug with index() matching beyond end of string
[perl5.git] / ext / POSIX / POSIX.xs
CommitLineData
6e22d046
JH
1#define PERL_EXT_POSIX
2
2986a63f
JH
3#ifdef NETWARE
4 #define _POSIX_
4efcf9a2
SB
5 /*
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
10 */
2986a63f
JH
11 #include <sys/utsname.h>
12#endif /* NETWARE */
13
c5be433b
GS
14#define PERL_NO_GET_CONTEXT
15
463ee0b2 16#include "EXTERN.h"
760ac839 17#define PERLIO_NOT_STDIO 1
463ee0b2
LW
18#include "perl.h"
19#include "XSUB.h"
acfe0abc 20#if defined(PERL_IMPLICIT_SYS)
873ef191
GS
21# undef signal
22# undef open
cd661bb6 23# undef setmode
35ff7856 24# define open PerlLIO_open3
873ef191 25#endif
2304df62 26#include <ctype.h>
a0d0e21e 27#ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
2304df62 28#include <dirent.h>
a0d0e21e 29#endif
2304df62 30#include <errno.h>
2304df62
AD
31#ifdef I_FLOAT
32#include <float.h>
33#endif
a0d0e21e 34#ifdef I_LIMITS
2304df62 35#include <limits.h>
a0d0e21e 36#endif
2304df62
AD
37#include <locale.h>
38#include <math.h>
85e6fe83 39#ifdef I_PWD
2304df62 40#include <pwd.h>
85e6fe83 41#endif
2304df62
AD
42#include <setjmp.h>
43#include <signal.h>
2304df62 44#include <stdarg.h>
17c3b450 45
2304df62
AD
46#ifdef I_STDDEF
47#include <stddef.h>
48#endif
6990d991 49
b5846a0b
BS
50#ifdef I_UNISTD
51#include <unistd.h>
52#endif
53
3609ea0d 54/* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
a0d0e21e
LW
55 metaconfig for future extension writers. We don't use them in POSIX.
56 (This is really sneaky :-) --AD
57*/
58#if defined(I_TERMIOS)
59#include <termios.h>
60#endif
a0d0e21e 61#ifdef I_STDLIB
2304df62 62#include <stdlib.h>
a0d0e21e 63#endif
5518ecd4 64#ifndef __ultrix__
2304df62 65#include <string.h>
5518ecd4 66#endif
2304df62 67#include <sys/stat.h>
2304df62 68#include <sys/types.h>
2304df62 69#include <time.h>
6dead956 70#ifdef I_UNISTD
1d2dff63 71#include <unistd.h>
6dead956 72#endif
bf4acbe4
GS
73#ifdef MACOS_TRADITIONAL
74#undef fdopen
75#endif
71be2cbc 76#include <fcntl.h>
77
e2465f50 78#ifdef HAS_TZNAME
fb207d52 79# if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
e2465f50
JH
80extern char *tzname[];
81# endif
82#else
fb207d52 83#if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
e2465f50
JH
84char *tzname[] = { "" , "" };
85#endif
cb2479a8
JH
86#endif
87
aec614a5
NC
88#ifndef PERL_UNUSED_DECL
89# ifdef HASATTRIBUTE
90# if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
91# define PERL_UNUSED_DECL
92# else
93# define PERL_UNUSED_DECL __attribute__((unused))
94# endif
27da23d5 95# else
aec614a5 96# define PERL_UNUSED_DECL
27da23d5 97# endif
27da23d5
JH
98#endif
99
100#ifndef dNOOP
101#define dNOOP extern int Perl___notused PERL_UNUSED_DECL
102#endif
103
104#ifndef dVAR
105#define dVAR dNOOP
106#endif
107
6c418a22 108#if defined(__VMS) && !defined(__POSIX_SOURCE)
6c418a22 109# include <libdef.h> /* LIB$_INVARG constant */
110# include <lib$routines.h> /* prototype for lib$ediv() */
111# include <starlet.h> /* prototype for sys$gettim() */
774d564b 112# if DECC_VERSION < 50000000
86200d5c 113# define pid_t int /* old versions of DECC miss this in types.h */
774d564b 114# endif
6c418a22 115
6990d991 116# undef mkfifo
6c418a22 117# define mkfifo(a,b) (not_here("mkfifo"),-1)
118# define tzset() not_here("tzset")
119
5f6761f9
DS
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>
5f6761f9 123# endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
6c418a22 124
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)
128
129 /* The non-POSIX CRTL times() has void return type, so we just get the
130 current time directly */
34f7a5fe 131 clock_t vms_times(struct tms *bufptr) {
d28f7c37 132 dTHX;
6c418a22 133 clock_t retval;
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)
137# include <ints.h>
138 uint64 vmstime;
139 _ckvmssts(sys$gettim(&vmstime));
140 vmstime /= 100000;
141 retval = vmstime & 0x7fffffff;
142# else
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));
150# endif
151 /* Fill in the struct tms using the CRTL routine . . .*/
34f7a5fe 152 times((tbuffer_t *)bufptr);
6c418a22 153 return (clock_t) retval;
154 }
155# define times(t) vms_times(t)
156#else
d308986b 157#if defined (__CYGWIN__)
f89d6eaa
EF
158# define tzname _tzname
159#endif
2986a63f 160#if defined (WIN32) || defined (NETWARE)
6990d991 161# undef mkfifo
6dead956 162# define mkfifo(a,b) not_here("mkfifo")
873ef191 163# define ttyname(a) (char*)not_here("ttyname")
6dead956 164# define sigset_t long
86200d5c 165# define pid_t long
6dead956
GS
166# ifdef __BORLANDC__
167# define tzname _tzname
168# endif
169# ifdef _MSC_VER
170# define mode_t short
171# endif
62520c91
GS
172# ifdef __MINGW32__
173# define mode_t short
f6c6487a
GS
174# ifndef tzset
175# define tzset() not_here("tzset")
176# endif
177# ifndef _POSIX_OPEN_MAX
178# define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
179# endif
62520c91 180# endif
6dead956
GS
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")
2986a63f 190#ifndef NETWARE
6e22d046
JH
191# undef setuid
192# undef setgid
2986a63f
JH
193# define setuid(a) not_here("setuid")
194# define setgid(a) not_here("setgid")
195#endif /* NETWARE */
6dead956 196#else
6990d991
JH
197
198# ifndef HAS_MKFIFO
bf4acbe4 199# if defined(OS2) || defined(MACOS_TRADITIONAL)
d6a255e6 200# define mkfifo(a,b) not_here("mkfifo")
3609ea0d 201# else /* !( defined OS2 ) */
d6a255e6
IZ
202# ifndef mkfifo
203# define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
204# endif
6990d991
JH
205# endif
206# endif /* !HAS_MKFIFO */
207
bf4acbe4 208# ifdef MACOS_TRADITIONAL
bf4acbe4
GS
209# define ttyname(a) (char*)not_here("ttyname")
210# define tzset() not_here("tzset")
211# else
27da23d5
JH
212# ifdef I_GRP
213# include <grp.h>
214# endif
bf4acbe4
GS
215# include <sys/times.h>
216# ifdef HAS_UNAME
217# include <sys/utsname.h>
218# endif
219# include <sys/wait.h>
6c418a22 220# endif
6c418a22 221# ifdef I_UTIME
222# include <utime.h>
223# endif
2986a63f 224#endif /* WIN32 || NETWARE */
6dead956 225#endif /* __VMS */
2304df62
AD
226
227typedef int SysRet;
a0d0e21e 228typedef long SysRetLong;
2304df62
AD
229typedef sigset_t* POSIX__SigSet;
230typedef HV* POSIX__SigAction;
a0d0e21e
LW
231#ifdef I_TERMIOS
232typedef struct termios* POSIX__Termios;
233#else /* Define termios types to int, and call not_here for the functions.*/
234#define POSIX__Termios int
235#define speed_t int
236#define tcflag_t int
237#define cc_t int
238#define cfgetispeed(x) not_here("cfgetispeed")
239#define cfgetospeed(x) not_here("cfgetospeed")
240#define tcdrain(x) not_here("tcdrain")
241#define tcflush(x,y) not_here("tcflush")
242#define tcsendbreak(x,y) not_here("tcsendbreak")
243#define cfsetispeed(x,y) not_here("cfsetispeed")
244#define cfsetospeed(x,y) not_here("cfsetospeed")
245#define ctermid(x) (char *) not_here("ctermid")
246#define tcflow(x,y) not_here("tcflow")
247#define tcgetattr(x,y) not_here("tcgetattr")
248#define tcsetattr(x,y,z) not_here("tcsetattr")
249#endif
250
251/* Possibly needed prototypes */
20ce7b12 252char *cuserid (char *);
6e22d046 253#ifndef WIN32
20ce7b12
GS
254double strtod (const char *, char **);
255long strtol (const char *, char **, int);
256unsigned long strtoul (const char *, char **, int);
6e22d046 257#endif
a0d0e21e
LW
258
259#ifndef HAS_CUSERID
260#define cuserid(a) (char *) not_here("cuserid")
261#endif
262#ifndef HAS_DIFFTIME
263#ifndef difftime
264#define difftime(a,b) not_here("difftime")
265#endif
266#endif
267#ifndef HAS_FPATHCONF
3609ea0d 268#define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
a0d0e21e
LW
269#endif
270#ifndef HAS_MKTIME
271#define mktime(a) not_here("mktime")
8990e307
LW
272#endif
273#ifndef HAS_NICE
274#define nice(a) not_here("nice")
275#endif
a0d0e21e 276#ifndef HAS_PATHCONF
3609ea0d 277#define pathconf(f,n) (SysRetLong) not_here("pathconf")
a0d0e21e
LW
278#endif
279#ifndef HAS_SYSCONF
3609ea0d 280#define sysconf(n) (SysRetLong) not_here("sysconf")
a0d0e21e 281#endif
8990e307
LW
282#ifndef HAS_READLINK
283#define readlink(a,b,c) not_here("readlink")
284#endif
285#ifndef HAS_SETPGID
286#define setpgid(a,b) not_here("setpgid")
287#endif
8990e307
LW
288#ifndef HAS_SETSID
289#define setsid() not_here("setsid")
290#endif
a0d0e21e
LW
291#ifndef HAS_STRCOLL
292#define strcoll(s1,s2) not_here("strcoll")
293#endif
a89d8a78
DH
294#ifndef HAS_STRTOD
295#define strtod(s1,s2) not_here("strtod")
296#endif
297#ifndef HAS_STRTOL
298#define strtol(s1,s2,b) not_here("strtol")
299#endif
300#ifndef HAS_STRTOUL
301#define strtoul(s1,s2,b) not_here("strtoul")
302#endif
a0d0e21e
LW
303#ifndef HAS_STRXFRM
304#define strxfrm(s1,s2,n) not_here("strxfrm")
8990e307
LW
305#endif
306#ifndef HAS_TCGETPGRP
307#define tcgetpgrp(a) not_here("tcgetpgrp")
308#endif
309#ifndef HAS_TCSETPGRP
310#define tcsetpgrp(a,b) not_here("tcsetpgrp")
311#endif
312#ifndef HAS_TIMES
2986a63f 313#ifndef NETWARE
8990e307 314#define times(a) not_here("times")
2986a63f 315#endif /* NETWARE */
8990e307
LW
316#endif
317#ifndef HAS_UNAME
318#define uname(a) not_here("uname")
319#endif
320#ifndef HAS_WAITPID
321#define waitpid(a,b,c) not_here("waitpid")
322#endif
323
a0d0e21e
LW
324#ifndef HAS_MBLEN
325#ifndef mblen
326#define mblen(a,b) not_here("mblen")
327#endif
328#endif
329#ifndef HAS_MBSTOWCS
330#define mbstowcs(s, pwcs, n) not_here("mbstowcs")
331#endif
332#ifndef HAS_MBTOWC
333#define mbtowc(pwc, s, n) not_here("mbtowc")
334#endif
335#ifndef HAS_WCSTOMBS
336#define wcstombs(s, pwcs, n) not_here("wcstombs")
337#endif
338#ifndef HAS_WCTOMB
339#define wctomb(s, wchar) not_here("wcstombs")
340#endif
341#if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
342/* If we don't have these functions, then we wouldn't have gotten a typedef
343 for wchar_t, the wide character type. Defining wchar_t allows the
344 functions referencing it to compile. Its actual type is then meaningless,
345 since without the above functions, all sections using it end up calling
346 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
347#ifndef wchar_t
348#define wchar_t char
349#endif
350#endif
351
352#ifndef HAS_LOCALECONV
353#define localeconv() not_here("localeconv")
354#endif
355
172ea7c8 356#ifdef HAS_LONG_DOUBLE
53796371 357# if LONG_DOUBLESIZE > NVSIZE
172ea7c8
JH
358# undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
359# endif
360#endif
361
362#ifndef HAS_LONG_DOUBLE
363#ifdef LDBL_MAX
364#undef LDBL_MAX
365#endif
366#ifdef LDBL_MIN
367#undef LDBL_MIN
368#endif
369#ifdef LDBL_EPSILON
370#undef LDBL_EPSILON
371#endif
372#endif
373
ec193bec
JH
374/* Background: in most systems the low byte of the wait status
375 * is the signal (the lowest 7 bits) and the coredump flag is
376 * the eight bit, and the second lowest byte is the exit status.
377 * BeOS bucks the trend and has the bytes in different order.
378 * See beos/beos.c for how the reality is bent even in BeOS
379 * to follow the traditional. However, to make the POSIX
380 * wait W*() macros to work in BeOS, we need to unbend the
381 * reality back in place. --jhi */
382#ifdef __BEOS__
383# define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
384#else
385# define WMUNGE(x) (x)
386#endif
387
8990e307 388static int
4b48cf39 389not_here(const char *s)
8990e307
LW
390{
391 croak("POSIX::%s not implemented on this architecture", s);
392 return -1;
393}
463ee0b2 394
1cb0fb50 395#include "const-c.inc"
a290f238 396
1dfe7606 397static void
40b7a5f5 398restore_sigmask(pTHX_ SV *osset_sv)
1dfe7606 399{
7feb700b
JH
400 /* Fortunately, restoring the signal mask can't fail, because
401 * there's nothing we can do about it if it does -- we're not
402 * supposed to return -1 from sigaction unless the disposition
403 * was unaffected.
404 */
7feb700b
JH
405 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
406 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
1dfe7606
AJ
407}
408
2304df62
AD
409MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
410
411POSIX::SigSet
412new(packname = "POSIX::SigSet", ...)
d3f5e399 413 const char * packname
2304df62
AD
414 CODE:
415 {
416 int i;
a02a5408 417 Newx(RETVAL, 1, sigset_t);
2304df62 418 sigemptyset(RETVAL);
a0d0e21e 419 for (i = 1; i < items; i++)
2304df62
AD
420 sigaddset(RETVAL, SvIV(ST(i)));
421 }
422 OUTPUT:
423 RETVAL
463ee0b2 424
8990e307 425void
2304df62
AD
426DESTROY(sigset)
427 POSIX::SigSet sigset
428 CODE:
01667c76 429 Safefree(sigset);
2304df62
AD
430
431SysRet
432sigaddset(sigset, sig)
433 POSIX::SigSet sigset
434 int sig
435
436SysRet
437sigdelset(sigset, sig)
438 POSIX::SigSet sigset
439 int sig
440
441SysRet
442sigemptyset(sigset)
443 POSIX::SigSet sigset
444
445SysRet
446sigfillset(sigset)
447 POSIX::SigSet sigset
448
449int
450sigismember(sigset, sig)
451 POSIX::SigSet sigset
452 int sig
453
a0d0e21e
LW
454MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
455
456POSIX::Termios
457new(packname = "POSIX::Termios", ...)
d3f5e399 458 const char * packname
a0d0e21e
LW
459 CODE:
460 {
461#ifdef I_TERMIOS
a02a5408 462 Newx(RETVAL, 1, struct termios);
a0d0e21e
LW
463#else
464 not_here("termios");
640cc986 465 RETVAL = 0;
a0d0e21e
LW
466#endif
467 }
468 OUTPUT:
469 RETVAL
470
471void
472DESTROY(termios_ref)
473 POSIX::Termios termios_ref
474 CODE:
475#ifdef I_TERMIOS
01667c76 476 Safefree(termios_ref);
a0d0e21e
LW
477#else
478 not_here("termios");
479#endif
480
481SysRet
482getattr(termios_ref, fd = 0)
483 POSIX::Termios termios_ref
484 int fd
485 CODE:
486 RETVAL = tcgetattr(fd, termios_ref);
487 OUTPUT:
488 RETVAL
489
490SysRet
491setattr(termios_ref, fd = 0, optional_actions = 0)
492 POSIX::Termios termios_ref
493 int fd
494 int optional_actions
495 CODE:
496 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
497 OUTPUT:
498 RETVAL
499
500speed_t
501cfgetispeed(termios_ref)
502 POSIX::Termios termios_ref
503
504speed_t
505cfgetospeed(termios_ref)
506 POSIX::Termios termios_ref
507
508tcflag_t
509getiflag(termios_ref)
510 POSIX::Termios termios_ref
511 CODE:
512#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
513 RETVAL = termios_ref->c_iflag;
514#else
640cc986
HM
515 not_here("getiflag");
516 RETVAL = 0;
a0d0e21e
LW
517#endif
518 OUTPUT:
519 RETVAL
520
521tcflag_t
522getoflag(termios_ref)
523 POSIX::Termios termios_ref
524 CODE:
525#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
526 RETVAL = termios_ref->c_oflag;
527#else
640cc986
HM
528 not_here("getoflag");
529 RETVAL = 0;
a0d0e21e
LW
530#endif
531 OUTPUT:
532 RETVAL
533
534tcflag_t
535getcflag(termios_ref)
536 POSIX::Termios termios_ref
537 CODE:
538#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
539 RETVAL = termios_ref->c_cflag;
540#else
640cc986
HM
541 not_here("getcflag");
542 RETVAL = 0;
a0d0e21e
LW
543#endif
544 OUTPUT:
545 RETVAL
546
547tcflag_t
548getlflag(termios_ref)
549 POSIX::Termios termios_ref
550 CODE:
551#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
552 RETVAL = termios_ref->c_lflag;
553#else
640cc986
HM
554 not_here("getlflag");
555 RETVAL = 0;
a0d0e21e
LW
556#endif
557 OUTPUT:
558 RETVAL
559
560cc_t
561getcc(termios_ref, ccix)
562 POSIX::Termios termios_ref
b56fc9ec 563 unsigned int ccix
a0d0e21e
LW
564 CODE:
565#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
566 if (ccix >= NCCS)
567 croak("Bad getcc subscript");
568 RETVAL = termios_ref->c_cc[ccix];
569#else
640cc986
HM
570 not_here("getcc");
571 RETVAL = 0;
a0d0e21e
LW
572#endif
573 OUTPUT:
574 RETVAL
575
576SysRet
577cfsetispeed(termios_ref, speed)
578 POSIX::Termios termios_ref
579 speed_t speed
580
581SysRet
582cfsetospeed(termios_ref, speed)
583 POSIX::Termios termios_ref
584 speed_t speed
585
586void
587setiflag(termios_ref, iflag)
588 POSIX::Termios termios_ref
589 tcflag_t iflag
590 CODE:
591#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
592 termios_ref->c_iflag = iflag;
593#else
594 not_here("setiflag");
595#endif
596
597void
598setoflag(termios_ref, oflag)
599 POSIX::Termios termios_ref
600 tcflag_t oflag
601 CODE:
602#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
603 termios_ref->c_oflag = oflag;
604#else
605 not_here("setoflag");
606#endif
607
608void
609setcflag(termios_ref, cflag)
610 POSIX::Termios termios_ref
611 tcflag_t cflag
612 CODE:
613#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
614 termios_ref->c_cflag = cflag;
615#else
616 not_here("setcflag");
617#endif
618
619void
620setlflag(termios_ref, lflag)
621 POSIX::Termios termios_ref
622 tcflag_t lflag
623 CODE:
624#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
625 termios_ref->c_lflag = lflag;
626#else
627 not_here("setlflag");
628#endif
629
630void
631setcc(termios_ref, ccix, cc)
632 POSIX::Termios termios_ref
b56fc9ec 633 unsigned int ccix
a0d0e21e
LW
634 cc_t cc
635 CODE:
636#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
637 if (ccix >= NCCS)
638 croak("Bad setcc subscript");
639 termios_ref->c_cc[ccix] = cc;
640#else
641 not_here("setcc");
642#endif
643
644
a0d0e21e
LW
645MODULE = POSIX PACKAGE = POSIX
646
1cb0fb50 647INCLUDE: const-xs.inc
a290f238 648
e99d581a
NC
649int
650WEXITSTATUS(status)
651 int status
72bfe1b2
NC
652 ALIAS:
653 POSIX::WIFEXITED = 1
654 POSIX::WIFSIGNALED = 2
655 POSIX::WIFSTOPPED = 3
656 POSIX::WSTOPSIG = 4
657 POSIX::WTERMSIG = 5
658 CODE:
659 switch(ix) {
660 case 0:
d49025b7 661#ifdef WEXITSTATUS
72bfe1b2 662 RETVAL = WEXITSTATUS(status);
d49025b7
NC
663#else
664 not_here("WEXITSTATUS");
665#endif
72bfe1b2
NC
666 break;
667 case 1:
d49025b7 668#ifdef WIFEXITED
72bfe1b2 669 RETVAL = WIFEXITED(status);
d49025b7
NC
670#else
671 not_here("WIFEXITED");
672#endif
72bfe1b2
NC
673 break;
674 case 2:
d49025b7 675#ifdef WIFSIGNALED
72bfe1b2 676 RETVAL = WIFSIGNALED(status);
d49025b7
NC
677#else
678 not_here("WIFSIGNALED");
679#endif
72bfe1b2
NC
680 break;
681 case 3:
d49025b7 682#ifdef WIFSTOPPED
72bfe1b2 683 RETVAL = WIFSTOPPED(status);
d49025b7
NC
684#else
685 not_here("WIFSTOPPED");
686#endif
72bfe1b2
NC
687 break;
688 case 4:
d49025b7 689#ifdef WSTOPSIG
72bfe1b2 690 RETVAL = WSTOPSIG(status);
d49025b7
NC
691#else
692 not_here("WSTOPSIG");
693#endif
72bfe1b2
NC
694 break;
695 case 5:
d49025b7 696#ifdef WTERMSIG
72bfe1b2 697 RETVAL = WTERMSIG(status);
d49025b7
NC
698#else
699 not_here("WTERMSIG");
700#endif
72bfe1b2
NC
701 break;
702 default:
703 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", ix);
704 }
705 OUTPUT:
706 RETVAL
2304df62
AD
707
708int
709isalnum(charstring)
767bb2e0
TS
710 SV * charstring
711 PREINIT:
712 STRLEN len;
2304df62 713 CODE:
767bb2e0
TS
714 unsigned char *s = (unsigned char *) SvPV(charstring, len);
715 unsigned char *e = s + len;
5344da4e 716 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
717 if (!isalnum(*s))
718 RETVAL = 0;
719 OUTPUT:
720 RETVAL
721
722int
723isalpha(charstring)
767bb2e0
TS
724 SV * charstring
725 PREINIT:
726 STRLEN len;
2304df62 727 CODE:
767bb2e0
TS
728 unsigned char *s = (unsigned char *) SvPV(charstring, len);
729 unsigned char *e = s + len;
5344da4e 730 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
731 if (!isalpha(*s))
732 RETVAL = 0;
733 OUTPUT:
734 RETVAL
735
736int
737iscntrl(charstring)
767bb2e0
TS
738 SV * charstring
739 PREINIT:
740 STRLEN len;
2304df62 741 CODE:
767bb2e0
TS
742 unsigned char *s = (unsigned char *) SvPV(charstring, len);
743 unsigned char *e = s + len;
5344da4e 744 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
745 if (!iscntrl(*s))
746 RETVAL = 0;
747 OUTPUT:
748 RETVAL
749
750int
751isdigit(charstring)
767bb2e0
TS
752 SV * charstring
753 PREINIT:
754 STRLEN len;
2304df62 755 CODE:
767bb2e0
TS
756 unsigned char *s = (unsigned char *) SvPV(charstring, len);
757 unsigned char *e = s + len;
5344da4e 758 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
759 if (!isdigit(*s))
760 RETVAL = 0;
761 OUTPUT:
762 RETVAL
763
764int
765isgraph(charstring)
767bb2e0
TS
766 SV * charstring
767 PREINIT:
768 STRLEN len;
2304df62 769 CODE:
767bb2e0
TS
770 unsigned char *s = (unsigned char *) SvPV(charstring, len);
771 unsigned char *e = s + len;
5344da4e 772 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
773 if (!isgraph(*s))
774 RETVAL = 0;
775 OUTPUT:
776 RETVAL
777
778int
779islower(charstring)
767bb2e0
TS
780 SV * charstring
781 PREINIT:
782 STRLEN len;
2304df62 783 CODE:
767bb2e0
TS
784 unsigned char *s = (unsigned char *) SvPV(charstring, len);
785 unsigned char *e = s + len;
5344da4e 786 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
787 if (!islower(*s))
788 RETVAL = 0;
789 OUTPUT:
790 RETVAL
791
792int
793isprint(charstring)
767bb2e0
TS
794 SV * charstring
795 PREINIT:
796 STRLEN len;
2304df62 797 CODE:
767bb2e0
TS
798 unsigned char *s = (unsigned char *) SvPV(charstring, len);
799 unsigned char *e = s + len;
5344da4e 800 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
801 if (!isprint(*s))
802 RETVAL = 0;
803 OUTPUT:
804 RETVAL
805
806int
807ispunct(charstring)
767bb2e0
TS
808 SV * charstring
809 PREINIT:
810 STRLEN len;
2304df62 811 CODE:
767bb2e0
TS
812 unsigned char *s = (unsigned char *) SvPV(charstring, len);
813 unsigned char *e = s + len;
5344da4e 814 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
815 if (!ispunct(*s))
816 RETVAL = 0;
817 OUTPUT:
818 RETVAL
819
820int
821isspace(charstring)
767bb2e0
TS
822 SV * charstring
823 PREINIT:
824 STRLEN len;
2304df62 825 CODE:
767bb2e0
TS
826 unsigned char *s = (unsigned char *) SvPV(charstring, len);
827 unsigned char *e = s + len;
5344da4e 828 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
829 if (!isspace(*s))
830 RETVAL = 0;
831 OUTPUT:
832 RETVAL
8990e307
LW
833
834int
2304df62 835isupper(charstring)
767bb2e0
TS
836 SV * charstring
837 PREINIT:
838 STRLEN len;
2304df62 839 CODE:
767bb2e0
TS
840 unsigned char *s = (unsigned char *) SvPV(charstring, len);
841 unsigned char *e = s + len;
5344da4e 842 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
843 if (!isupper(*s))
844 RETVAL = 0;
845 OUTPUT:
846 RETVAL
8990e307
LW
847
848int
2304df62 849isxdigit(charstring)
767bb2e0
TS
850 SV * charstring
851 PREINIT:
852 STRLEN len;
2304df62 853 CODE:
767bb2e0
TS
854 unsigned char *s = (unsigned char *) SvPV(charstring, len);
855 unsigned char *e = s + len;
5344da4e 856 for (RETVAL = 1; RETVAL && s < e; s++)
2304df62
AD
857 if (!isxdigit(*s))
858 RETVAL = 0;
859 OUTPUT:
860 RETVAL
861
862SysRet
863open(filename, flags = O_RDONLY, mode = 0666)
864 char * filename
865 int flags
a0d0e21e 866 Mode_t mode
748a9306
LW
867 CODE:
868 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
869 TAINT_PROPER("open");
870 RETVAL = open(filename, flags, mode);
871 OUTPUT:
872 RETVAL
873
2304df62
AD
874
875HV *
876localeconv()
877 CODE:
a0d0e21e 878#ifdef HAS_LOCALECONV
2304df62
AD
879 struct lconv *lcbuf;
880 RETVAL = newHV();
c4e79b56 881 sv_2mortal((SV*)RETVAL);
8063af02 882 if ((lcbuf = localeconv())) {
2304df62
AD
883 /* the strings */
884 if (lcbuf->decimal_point && *lcbuf->decimal_point)
885 hv_store(RETVAL, "decimal_point", 13,
886 newSVpv(lcbuf->decimal_point, 0), 0);
887 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
888 hv_store(RETVAL, "thousands_sep", 13,
889 newSVpv(lcbuf->thousands_sep, 0), 0);
28e8609d 890#ifndef NO_LOCALECONV_GROUPING
2304df62
AD
891 if (lcbuf->grouping && *lcbuf->grouping)
892 hv_store(RETVAL, "grouping", 8,
893 newSVpv(lcbuf->grouping, 0), 0);
28e8609d 894#endif
2304df62
AD
895 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
896 hv_store(RETVAL, "int_curr_symbol", 15,
897 newSVpv(lcbuf->int_curr_symbol, 0), 0);
898 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
899 hv_store(RETVAL, "currency_symbol", 15,
900 newSVpv(lcbuf->currency_symbol, 0), 0);
901 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
902 hv_store(RETVAL, "mon_decimal_point", 17,
903 newSVpv(lcbuf->mon_decimal_point, 0), 0);
39e571d4 904#ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
2304df62
AD
905 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
906 hv_store(RETVAL, "mon_thousands_sep", 17,
907 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
3609ea0d 908#endif
28e8609d 909#ifndef NO_LOCALECONV_MON_GROUPING
2304df62
AD
910 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
911 hv_store(RETVAL, "mon_grouping", 12,
912 newSVpv(lcbuf->mon_grouping, 0), 0);
28e8609d 913#endif
2304df62
AD
914 if (lcbuf->positive_sign && *lcbuf->positive_sign)
915 hv_store(RETVAL, "positive_sign", 13,
916 newSVpv(lcbuf->positive_sign, 0), 0);
917 if (lcbuf->negative_sign && *lcbuf->negative_sign)
918 hv_store(RETVAL, "negative_sign", 13,
919 newSVpv(lcbuf->negative_sign, 0), 0);
920 /* the integers */
921 if (lcbuf->int_frac_digits != CHAR_MAX)
922 hv_store(RETVAL, "int_frac_digits", 15,
923 newSViv(lcbuf->int_frac_digits), 0);
924 if (lcbuf->frac_digits != CHAR_MAX)
925 hv_store(RETVAL, "frac_digits", 11,
926 newSViv(lcbuf->frac_digits), 0);
927 if (lcbuf->p_cs_precedes != CHAR_MAX)
928 hv_store(RETVAL, "p_cs_precedes", 13,
929 newSViv(lcbuf->p_cs_precedes), 0);
930 if (lcbuf->p_sep_by_space != CHAR_MAX)
931 hv_store(RETVAL, "p_sep_by_space", 14,
932 newSViv(lcbuf->p_sep_by_space), 0);
933 if (lcbuf->n_cs_precedes != CHAR_MAX)
934 hv_store(RETVAL, "n_cs_precedes", 13,
935 newSViv(lcbuf->n_cs_precedes), 0);
936 if (lcbuf->n_sep_by_space != CHAR_MAX)
937 hv_store(RETVAL, "n_sep_by_space", 14,
938 newSViv(lcbuf->n_sep_by_space), 0);
939 if (lcbuf->p_sign_posn != CHAR_MAX)
940 hv_store(RETVAL, "p_sign_posn", 11,
941 newSViv(lcbuf->p_sign_posn), 0);
942 if (lcbuf->n_sign_posn != CHAR_MAX)
943 hv_store(RETVAL, "n_sign_posn", 11,
944 newSViv(lcbuf->n_sign_posn), 0);
945 }
a0d0e21e
LW
946#else
947 localeconv(); /* A stub to call not_here(). */
948#endif
2304df62
AD
949 OUTPUT:
950 RETVAL
951
952char *
c28ee57b 953setlocale(category, locale = 0)
2304df62
AD
954 int category
955 char * locale
1ba01ae3
SH
956 PREINIT:
957 char * retval;
c28ee57b 958 CODE:
1ba01ae3
SH
959 retval = setlocale(category, locale);
960 if (retval) {
961 /* Save retval since subsequent setlocale() calls
962 * may overwrite it. */
963 RETVAL = savepv(retval);
36477c24 964#ifdef USE_LOCALE_CTYPE
bbce6d69 965 if (category == LC_CTYPE
966#ifdef LC_ALL
967 || category == LC_ALL
968#endif
969 )
970 {
971 char *newctype;
972#ifdef LC_ALL
973 if (category == LC_ALL)
974 newctype = setlocale(LC_CTYPE, NULL);
975 else
976#endif
977 newctype = RETVAL;
864dbfa3 978 new_ctype(newctype);
bbce6d69 979 }
36477c24 980#endif /* USE_LOCALE_CTYPE */
981#ifdef USE_LOCALE_COLLATE
bbce6d69 982 if (category == LC_COLLATE
983#ifdef LC_ALL
984 || category == LC_ALL
985#endif
986 )
987 {
988 char *newcoll;
989#ifdef LC_ALL
990 if (category == LC_ALL)
991 newcoll = setlocale(LC_COLLATE, NULL);
992 else
993#endif
994 newcoll = RETVAL;
864dbfa3 995 new_collate(newcoll);
bbce6d69 996 }
36477c24 997#endif /* USE_LOCALE_COLLATE */
998#ifdef USE_LOCALE_NUMERIC
bbce6d69 999 if (category == LC_NUMERIC
1000#ifdef LC_ALL
1001 || category == LC_ALL
1002#endif
1003 )
1004 {
1005 char *newnum;
1006#ifdef LC_ALL
1007 if (category == LC_ALL)
1008 newnum = setlocale(LC_NUMERIC, NULL);
1009 else
1010#endif
1011 newnum = RETVAL;
864dbfa3 1012 new_numeric(newnum);
bbce6d69 1013 }
36477c24 1014#endif /* USE_LOCALE_NUMERIC */
bbce6d69 1015 }
1ba01ae3
SH
1016 else
1017 RETVAL = NULL;
c28ee57b
JH
1018 OUTPUT:
1019 RETVAL
1ba01ae3
SH
1020 CLEANUP:
1021 if (RETVAL)
1022 Safefree(RETVAL);
2304df62 1023
e1ca407b 1024NV
2304df62 1025acos(x)
e1ca407b 1026 NV x
2304df62 1027
e1ca407b 1028NV
2304df62 1029asin(x)
e1ca407b 1030 NV x
2304df62 1031
e1ca407b 1032NV
2304df62 1033atan(x)
e1ca407b 1034 NV x
2304df62 1035
e1ca407b 1036NV
2304df62 1037ceil(x)
e1ca407b 1038 NV x
2304df62 1039
e1ca407b 1040NV
2304df62 1041cosh(x)
e1ca407b 1042 NV x
2304df62 1043
e1ca407b 1044NV
2304df62 1045floor(x)
e1ca407b 1046 NV x
2304df62 1047
e1ca407b 1048NV
2304df62 1049fmod(x,y)
e1ca407b
A
1050 NV x
1051 NV y
2304df62
AD
1052
1053void
1054frexp(x)
e1ca407b 1055 NV x
2304df62
AD
1056 PPCODE:
1057 int expvar;
2304df62
AD
1058 /* (We already know stack is long enough.) */
1059 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1060 PUSHs(sv_2mortal(newSViv(expvar)));
1061
e1ca407b 1062NV
2304df62 1063ldexp(x,exp)
e1ca407b 1064 NV x
2304df62
AD
1065 int exp
1066
e1ca407b 1067NV
2304df62 1068log10(x)
e1ca407b 1069 NV x
2304df62
AD
1070
1071void
1072modf(x)
e1ca407b 1073 NV x
2304df62 1074 PPCODE:
e1ca407b 1075 NV intvar;
2304df62 1076 /* (We already know stack is long enough.) */
bf4acbe4 1077 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
2304df62
AD
1078 PUSHs(sv_2mortal(newSVnv(intvar)));
1079
e1ca407b 1080NV
2304df62 1081sinh(x)
e1ca407b 1082 NV x
2304df62 1083
e1ca407b 1084NV
3b35bae3 1085tan(x)
e1ca407b 1086 NV x
3b35bae3 1087
e1ca407b 1088NV
2304df62 1089tanh(x)
e1ca407b 1090 NV x
2304df62
AD
1091
1092SysRet
1dfe7606 1093sigaction(sig, optaction, oldaction = 0)
2304df62 1094 int sig
1dfe7606 1095 SV * optaction
2304df62
AD
1096 POSIX::SigAction oldaction
1097 CODE:
2986a63f 1098#if defined(WIN32) || defined(NETWARE)
6dead956
GS
1099 RETVAL = not_here("sigaction");
1100#else
2304df62
AD
1101# This code is really grody because we're trying to make the signal
1102# interface look beautiful, which is hard.
1103
2304df62 1104 {
27da23d5 1105 dVAR;
1dfe7606 1106 POSIX__SigAction action;
f4c556ac 1107 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
2304df62
AD
1108 struct sigaction act;
1109 struct sigaction oact;
1dfe7606 1110 sigset_t sset;
183bde56 1111 SV *osset_sv;
27c1a449 1112 sigset_t osset;
2304df62
AD
1113 POSIX__SigSet sigset;
1114 SV** svp;
1d81eac9 1115 SV** sigsvp;
3609ea0d 1116
516d25e8
SP
1117 if (sig < 0) {
1118 croak("Negative signals are not allowed");
1119 }
1120
1d81eac9 1121 if (sig == 0 && SvPOK(ST(0))) {
aa07b2f6 1122 const char *s = SvPVX_const(ST(0));
1d81eac9
JH
1123 int i = whichsig(s);
1124
1125 if (i < 0 && memEQ(s, "SIG", 3))
1126 i = whichsig(s + 3);
1127 if (i < 0) {
1128 if (ckWARN(WARN_SIGNAL))
1129 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1130 "No such signal: SIG%s", s);
1131 XSRETURN_UNDEF;
1132 }
1133 else
1134 sig = i;
1135 }
3609ea0d
JH
1136#ifdef NSIG
1137 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1138 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1139 "No such signal: %d", sig);
1140 XSRETURN_UNDEF;
1141 }
1142#endif
1d81eac9
JH
1143 sigsvp = hv_fetch(GvHVn(siggv),
1144 PL_sig_name[sig],
1145 strlen(PL_sig_name[sig]),
1146 TRUE);
2304df62 1147
1dfe7606
AJ
1148 /* Check optaction and set action */
1149 if(SvTRUE(optaction)) {
1150 if(sv_isa(optaction, "POSIX::SigAction"))
1151 action = (HV*)SvRV(optaction);
1152 else
1153 croak("action is not of type POSIX::SigAction");
1154 }
1155 else {
1156 action=0;
1157 }
1158
1159 /* sigaction() is supposed to look atomic. In particular, any
1160 * signal handler invoked during a sigaction() call should
1161 * see either the old or the new disposition, and not something
1162 * in between. We use sigprocmask() to make it so.
1163 */
1164 sigfillset(&sset);
1165 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1166 if(RETVAL == -1)
15c0d34a 1167 XSRETURN_UNDEF;
1dfe7606
AJ
1168 ENTER;
1169 /* Restore signal mask no matter how we exit this block. */
183bde56
NA
1170 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1171 SAVEFREESV( osset_sv );
40b7a5f5 1172 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1dfe7606
AJ
1173
1174 RETVAL=-1; /* In case both oldaction and action are 0. */
1175
1176 /* Remember old disposition if desired. */
2304df62 1177 if (oldaction) {
017a3ce5 1178 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1dfe7606
AJ
1179 if(!svp)
1180 croak("Can't supply an oldaction without a HANDLER");
1181 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1182 sv_setsv(*svp, *sigsvp);
1183 }
1184 else {
1185 sv_setpv(*svp, "DEFAULT");
1186 }
1187 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1188 if(RETVAL == -1)
15c0d34a 1189 XSRETURN_UNDEF;
1dfe7606 1190 /* Get back the mask. */
017a3ce5 1191 svp = hv_fetchs(oldaction, "MASK", TRUE);
1dfe7606
AJ
1192 if (sv_isa(*svp, "POSIX::SigSet")) {
1193 IV tmp = SvIV((SV*)SvRV(*svp));
1194 sigset = INT2PTR(sigset_t*, tmp);
1195 }
1196 else {
a02a5408 1197 Newx(sigset, 1, sigset_t);
1dfe7606
AJ
1198 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1199 }
1200 *sigset = oact.sa_mask;
1201
1202 /* Get back the flags. */
017a3ce5 1203 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1dfe7606 1204 sv_setiv(*svp, oact.sa_flags);
d36b6582
CS
1205
1206 /* Get back whether the old handler used safe signals. */
017a3ce5 1207 svp = hv_fetchs(oldaction, "SAFE", TRUE);
e91e3b10
RB
1208 sv_setiv(*svp,
1209 /* compare incompatible pointers by casting to integer */
1210 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
2304df62
AD
1211 }
1212
1213 if (action) {
d36b6582
CS
1214 /* Safe signals use "csighandler", which vectors through the
1215 PL_sighandlerp pointer when it's safe to do so.
1216 (BTW, "csighandler" is very different from "sighandler".) */
017a3ce5 1217 svp = hv_fetchs(action, "SAFE", FALSE);
e91e3b10
RB
1218 act.sa_handler =
1219 DPTR2FPTR(
87d46f97 1220 void (*)(int),
e91e3b10
RB
1221 (*svp && SvTRUE(*svp))
1222 ? PL_csighandlerp : PL_sighandlerp
1223 );
d36b6582
CS
1224
1225 /* Vector new Perl handler through %SIG.
1226 (The core signal handlers read %SIG to dispatch.) */
017a3ce5 1227 svp = hv_fetchs(action, "HANDLER", FALSE);
2304df62
AD
1228 if (!svp)
1229 croak("Can't supply an action without a HANDLER");
1dfe7606 1230 sv_setsv(*sigsvp, *svp);
d36b6582
CS
1231
1232 /* This call actually calls sigaction() with almost the
1233 right settings, including appropriate interpretation
1234 of DEFAULT and IGNORE. However, why are we doing
1235 this when we're about to do it again just below? XXX */
1236 mg_set(*sigsvp);
1237
1238 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1dfe7606 1239 if(SvPOK(*svp)) {
aa07b2f6 1240 const char *s=SvPVX_const(*svp);
1dfe7606
AJ
1241 if(strEQ(s,"IGNORE")) {
1242 act.sa_handler = SIG_IGN;
1243 }
1244 else if(strEQ(s,"DEFAULT")) {
1245 act.sa_handler = SIG_DFL;
1246 }
1dfe7606 1247 }
2304df62
AD
1248
1249 /* Set up any desired mask. */
017a3ce5 1250 svp = hv_fetchs(action, "MASK", FALSE);
2304df62 1251 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
ac634a9a 1252 IV tmp = SvIV((SV*)SvRV(*svp));
1dfe7606 1253 sigset = INT2PTR(sigset_t*, tmp);
2304df62
AD
1254 act.sa_mask = *sigset;
1255 }
1256 else
85e6fe83 1257 sigemptyset(& act.sa_mask);
2304df62
AD
1258
1259 /* Set up any desired flags. */
017a3ce5 1260 svp = hv_fetchs(action, "FLAGS", FALSE);
2304df62 1261 act.sa_flags = svp ? SvIV(*svp) : 0;
2304df62 1262
1dfe7606
AJ
1263 /* Don't worry about cleaning up *sigsvp if this fails,
1264 * because that means we tried to disposition a
1265 * nonblockable signal, in which case *sigsvp is
1266 * essentially meaningless anyway.
1267 */
6c418a22 1268 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
a7aad5de
A
1269 if(RETVAL == -1)
1270 XSRETURN_UNDEF;
2304df62 1271 }
1dfe7606
AJ
1272
1273 LEAVE;
2304df62 1274 }
6dead956 1275#endif
2304df62
AD
1276 OUTPUT:
1277 RETVAL
1278
1279SysRet
1280sigpending(sigset)
1281 POSIX::SigSet sigset
1282
1283SysRet
1284sigprocmask(how, sigset, oldsigset = 0)
1285 int how
b13bbac7 1286 POSIX::SigSet sigset = NO_INIT
33c27489
GS
1287 POSIX::SigSet oldsigset = NO_INIT
1288INIT:
a3b811a7 1289 if (! SvOK(ST(1))) {
b13bbac7 1290 sigset = NULL;
a3b811a7 1291 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
b13bbac7
AB
1292 IV tmp = SvIV((SV*)SvRV(ST(1)));
1293 sigset = INT2PTR(POSIX__SigSet,tmp);
1294 } else {
1295 croak("sigset is not of type POSIX::SigSet");
33c27489 1296 }
b13bbac7 1297
194cfca0 1298 if (items < 3 || ! SvOK(ST(2))) {
b13bbac7 1299 oldsigset = NULL;
a3b811a7 1300 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
33c27489 1301 IV tmp = SvIV((SV*)SvRV(ST(2)));
56431972 1302 oldsigset = INT2PTR(POSIX__SigSet,tmp);
b13bbac7
AB
1303 } else {
1304 croak("oldsigset is not of type POSIX::SigSet");
33c27489 1305 }
2304df62
AD
1306
1307SysRet
1308sigsuspend(signal_mask)
1309 POSIX::SigSet signal_mask
1310
2304df62
AD
1311void
1312_exit(status)
1313 int status
8990e307 1314
85e6fe83 1315SysRet
8990e307
LW
1316close(fd)
1317 int fd
1318
85e6fe83 1319SysRet
8990e307
LW
1320dup(fd)
1321 int fd
1322
85e6fe83 1323SysRet
8990e307
LW
1324dup2(fd1, fd2)
1325 int fd1
1326 int fd2
1327
4a9d6100 1328SV *
a0d0e21e 1329lseek(fd, offset, whence)
85e6fe83
LW
1330 int fd
1331 Off_t offset
1332 int whence
4a9d6100
GS
1333 CODE:
1334 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1335 RETVAL = sizeof(Off_t) > sizeof(IV)
1336 ? newSVnv((NV)pos) : newSViv((IV)pos);
1337 OUTPUT:
1338 RETVAL
8990e307 1339
c5661c80 1340void
8990e307
LW
1341nice(incr)
1342 int incr
15f0f28a
AE
1343 PPCODE:
1344 errno = 0;
1345 if ((incr = nice(incr)) != -1 || errno == 0) {
1346 if (incr == 0)
1347 XPUSHs(sv_2mortal(newSVpvn("0 but true", 10)));
1348 else
1349 XPUSHs(sv_2mortal(newSViv(incr)));
1350 }
8990e307 1351
8063af02 1352void
8990e307 1353pipe()
85e6fe83
LW
1354 PPCODE:
1355 int fds[2];
85e6fe83 1356 if (pipe(fds) != -1) {
924508f0 1357 EXTEND(SP,2);
85e6fe83
LW
1358 PUSHs(sv_2mortal(newSViv(fds[0])));
1359 PUSHs(sv_2mortal(newSViv(fds[1])));
1360 }
8990e307 1361
85e6fe83 1362SysRet
a0d0e21e 1363read(fd, buffer, nbytes)
7747499c
TB
1364 PREINIT:
1365 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1366 INPUT:
1367 int fd
1368 size_t nbytes
1369 char * buffer = sv_grow( sv_buffer, nbytes+1 );
a0d0e21e 1370 CLEANUP:
7747499c 1371 if (RETVAL >= 0) {
b162af07 1372 SvCUR_set(sv_buffer, RETVAL);
7747499c
TB
1373 SvPOK_only(sv_buffer);
1374 *SvEND(sv_buffer) = '\0';
bbce6d69 1375 SvTAINTED_on(sv_buffer);
7747499c 1376 }
8990e307 1377
85e6fe83 1378SysRet
8990e307 1379setpgid(pid, pgid)
86200d5c
JH
1380 pid_t pid
1381 pid_t pgid
8990e307 1382
86200d5c 1383pid_t
8990e307
LW
1384setsid()
1385
86200d5c 1386pid_t
8990e307
LW
1387tcgetpgrp(fd)
1388 int fd
1389
85e6fe83 1390SysRet
8990e307
LW
1391tcsetpgrp(fd, pgrp_id)
1392 int fd
86200d5c 1393 pid_t pgrp_id
8990e307 1394
8063af02 1395void
8990e307 1396uname()
2304df62 1397 PPCODE:
a0d0e21e 1398#ifdef HAS_UNAME
85e6fe83 1399 struct utsname buf;
85e6fe83 1400 if (uname(&buf) >= 0) {
924508f0 1401 EXTEND(SP, 5);
85e6fe83
LW
1402 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1403 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1404 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1405 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1406 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
8990e307 1407 }
a0d0e21e
LW
1408#else
1409 uname((char *) 0); /* A stub to call not_here(). */
1410#endif
8990e307 1411
85e6fe83 1412SysRet
a0d0e21e
LW
1413write(fd, buffer, nbytes)
1414 int fd
1415 char * buffer
1416 size_t nbytes
1417
33f01dd1
SH
1418SV *
1419tmpnam()
1420 PREINIT:
1421 STRLEN i;
1422 int len;
1423 CODE:
1424 RETVAL = newSVpvn("", 0);
1425 SvGROW(RETVAL, L_tmpnam);
1426 len = strlen(tmpnam(SvPV(RETVAL, i)));
1427 SvCUR_set(RETVAL, len);
1428 OUTPUT:
1429 RETVAL
a0d0e21e
LW
1430
1431void
1432abort()
1433
1434int
1435mblen(s, n)
1436 char * s
1437 size_t n
1438
1439size_t
1440mbstowcs(s, pwcs, n)
1441 wchar_t * s
1442 char * pwcs
1443 size_t n
1444
1445int
1446mbtowc(pwc, s, n)
1447 wchar_t * pwc
1448 char * s
1449 size_t n
1450
1451int
1452wcstombs(s, pwcs, n)
1453 char * s
1454 wchar_t * pwcs
1455 size_t n
1456
1457int
1458wctomb(s, wchar)
1459 char * s
1460 wchar_t wchar
1461
1462int
1463strcoll(s1, s2)
1464 char * s1
1465 char * s2
1466
a89d8a78
DH
1467void
1468strtod(str)
1469 char * str
1470 PREINIT:
1471 double num;
1472 char *unparsed;
1473 PPCODE:
36477c24 1474 SET_NUMERIC_LOCAL();
a89d8a78
DH
1475 num = strtod(str, &unparsed);
1476 PUSHs(sv_2mortal(newSVnv(num)));
1477 if (GIMME == G_ARRAY) {
924508f0 1478 EXTEND(SP, 1);
a89d8a78
DH
1479 if (unparsed)
1480 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1481 else
6b88bc9c 1482 PUSHs(&PL_sv_undef);
a89d8a78
DH
1483 }
1484
1485void
1486strtol(str, base = 0)
1487 char * str
1488 int base
1489 PREINIT:
1490 long num;
1491 char *unparsed;
1492 PPCODE:
1493 num = strtol(str, &unparsed, base);
42718184
RB
1494#if IVSIZE <= LONGSIZE
1495 if (num < IV_MIN || num > IV_MAX)
a89d8a78 1496 PUSHs(sv_2mortal(newSVnv((double)num)));
42718184
RB
1497 else
1498#endif
1499 PUSHs(sv_2mortal(newSViv((IV)num)));
a89d8a78 1500 if (GIMME == G_ARRAY) {
924508f0 1501 EXTEND(SP, 1);
a89d8a78
DH
1502 if (unparsed)
1503 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1504 else
6b88bc9c 1505 PUSHs(&PL_sv_undef);
a89d8a78
DH
1506 }
1507
1508void
1509strtoul(str, base = 0)
4b48cf39 1510 const char * str
a89d8a78
DH
1511 int base
1512 PREINIT:
1513 unsigned long num;
1514 char *unparsed;
1515 PPCODE:
1516 num = strtoul(str, &unparsed, base);
84c133a0
RB
1517#if IVSIZE <= LONGSIZE
1518 if (num > IV_MAX)
a89d8a78 1519 PUSHs(sv_2mortal(newSVnv((double)num)));
84c133a0
RB
1520 else
1521#endif
1522 PUSHs(sv_2mortal(newSViv((IV)num)));
a89d8a78 1523 if (GIMME == G_ARRAY) {
924508f0 1524 EXTEND(SP, 1);
a89d8a78
DH
1525 if (unparsed)
1526 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1527 else
6b88bc9c 1528 PUSHs(&PL_sv_undef);
a89d8a78
DH
1529 }
1530
8063af02 1531void
a0d0e21e
LW
1532strxfrm(src)
1533 SV * src
85e6fe83 1534 CODE:
a0d0e21e
LW
1535 {
1536 STRLEN srclen;
1537 STRLEN dstlen;
1538 char *p = SvPV(src,srclen);
1539 srclen++;
561b68a9 1540 ST(0) = sv_2mortal(newSV(srclen*4+1));
a0d0e21e
LW
1541 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1542 if (dstlen > srclen) {
1543 dstlen++;
1544 SvGROW(ST(0), dstlen);
1545 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1546 dstlen--;
1547 }
b162af07 1548 SvCUR_set(ST(0), dstlen);
a0d0e21e
LW
1549 SvPOK_only(ST(0));
1550 }
1551
1552SysRet
1553mkfifo(filename, mode)
1554 char * filename
1555 Mode_t mode
748a9306
LW
1556 CODE:
1557 TAINT_PROPER("mkfifo");
1558 RETVAL = mkfifo(filename, mode);
1559 OUTPUT:
1560 RETVAL
a0d0e21e
LW
1561
1562SysRet
1563tcdrain(fd)
1564 int fd
1565
1566
1567SysRet
1568tcflow(fd, action)
1569 int fd
1570 int action
1571
1572
1573SysRet
1574tcflush(fd, queue_selector)
1575 int fd
1576 int queue_selector
1577
1578SysRet
1579tcsendbreak(fd, duration)
1580 int fd
1581 int duration
1582
1583char *
c1646883 1584asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
a0d0e21e
LW
1585 int sec
1586 int min
1587 int hour
1588 int mday
1589 int mon
1590 int year
1591 int wday
1592 int yday
1593 int isdst
1594 CODE:
1595 {
1596 struct tm mytm;
7747499c 1597 init_tm(&mytm); /* XXX workaround - see init_tm() above */
a0d0e21e
LW
1598 mytm.tm_sec = sec;
1599 mytm.tm_min = min;
1600 mytm.tm_hour = hour;
1601 mytm.tm_mday = mday;
1602 mytm.tm_mon = mon;
1603 mytm.tm_year = year;
1604 mytm.tm_wday = wday;
1605 mytm.tm_yday = yday;
1606 mytm.tm_isdst = isdst;
1607 RETVAL = asctime(&mytm);
1608 }
1609 OUTPUT:
1610 RETVAL
1611
1612long
1613clock()
1614
1615char *
1616ctime(time)
748a9306 1617 Time_t &time
8990e307 1618
37120919
AD
1619void
1620times()
1621 PPCODE:
1622 struct tms tms;
1623 clock_t realtime;
1624 realtime = times( &tms );
924508f0 1625 EXTEND(SP,5);
9607fc9c 1626 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1627 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1628 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1629 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1630 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
37120919 1631
a0d0e21e
LW
1632double
1633difftime(time1, time2)
1634 Time_t time1
1635 Time_t time2
1636
1637SysRetLong
c1646883 1638mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
a0d0e21e
LW
1639 int sec
1640 int min
1641 int hour
1642 int mday
1643 int mon
1644 int year
1645 int wday
1646 int yday
1647 int isdst
1648 CODE:
1649 {
1650 struct tm mytm;
7747499c 1651 init_tm(&mytm); /* XXX workaround - see init_tm() above */
a0d0e21e
LW
1652 mytm.tm_sec = sec;
1653 mytm.tm_min = min;
1654 mytm.tm_hour = hour;
1655 mytm.tm_mday = mday;
1656 mytm.tm_mon = mon;
1657 mytm.tm_year = year;
1658 mytm.tm_wday = wday;
1659 mytm.tm_yday = yday;
1660 mytm.tm_isdst = isdst;
aebaba0b 1661 RETVAL = (SysRetLong) mktime(&mytm);
a0d0e21e 1662 }
85e6fe83
LW
1663 OUTPUT:
1664 RETVAL
a0d0e21e 1665
8063af02
DM
1666#XXX: if $xsubpp::WantOptimize is always the default
1667# sv_setpv(TARG, ...) could be used rather than
1668# ST(0) = sv_2mortal(newSVpv(...))
1669void
e44f695e 1670strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
a0d0e21e
LW
1671 char * fmt
1672 int sec
1673 int min
1674 int hour
1675 int mday
1676 int mon
1677 int year
1678 int wday
1679 int yday
1680 int isdst
1681 CODE:
1682 {
b3c85772 1683 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
2a74cb2d
JH
1684 if (buf) {
1685 ST(0) = sv_2mortal(newSVpv(buf, 0));
bf8afc63 1686 Safefree(buf);
2a74cb2d 1687 }
a0d0e21e
LW
1688 }
1689
1690void
1691tzset()
1692
1693void
1694tzname()
1695 PPCODE:
924508f0 1696 EXTEND(SP,2);
79cb57f6
GS
1697 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1698 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
a0d0e21e
LW
1699
1700SysRet
1701access(filename, mode)
1702 char * filename
1703 Mode_t mode
1704
1705char *
1706ctermid(s = 0)
3ab23a19
RGS
1707 char * s = 0;
1708 CODE:
1709#ifdef HAS_CTERMID_R
e02b9112 1710 s = (char *) safemalloc((size_t) L_ctermid);
3ab23a19
RGS
1711#endif
1712 RETVAL = ctermid(s);
1713 OUTPUT:
1714 RETVAL
d1fd7089 1715 CLEANUP:
3ab23a19 1716#ifdef HAS_CTERMID_R
d1fd7089 1717 Safefree(s);
3ab23a19 1718#endif
a0d0e21e
LW
1719
1720char *
1721cuserid(s = 0)
1722 char * s = 0;
1723
1724SysRetLong
1725fpathconf(fd, name)
1726 int fd
1727 int name
1728
1729SysRetLong
1730pathconf(filename, name)
1731 char * filename
1732 int name
1733
1734SysRet
1735pause()
1736
a043a685
GW
1737SysRet
1738setgid(gid)
1739 Gid_t gid
13ec70af 1740 CLEANUP:
e9df3e1a 1741#ifndef WIN32
13ec70af
RGS
1742 if (RETVAL >= 0) {
1743 PL_gid = getgid();
1744 PL_egid = getegid();
1745 }
e9df3e1a 1746#endif
a043a685
GW
1747
1748SysRet
1749setuid(uid)
1750 Uid_t uid
13ec70af 1751 CLEANUP:
e9df3e1a 1752#ifndef WIN32
13ec70af
RGS
1753 if (RETVAL >= 0) {
1754 PL_uid = getuid();
1755 PL_euid = geteuid();
1756 }
e9df3e1a 1757#endif
a043a685 1758
a0d0e21e
LW
1759SysRetLong
1760sysconf(name)
1761 int name
1762
1763char *
1764ttyname(fd)
1765 int fd
a043a685 1766
c6c619a9 1767void
b5846a0b 1768getcwd()
8f95b30d
JH
1769 PPCODE:
1770 {
1771 dXSTARG;
89423764 1772 getcwd_sv(TARG);
8f95b30d
JH
1773 XSprePUSH; PUSHTARG;
1774 }
1775
0d7021f5
RGS
1776SysRet
1777lchown(uid, gid, path)
1778 Uid_t uid
1779 Gid_t gid
1780 char * path
1781 CODE:
1782#ifdef HAS_LCHOWN
1783 /* yes, the order of arguments is different,
1784 * but consistent with CORE::chown() */
1785 RETVAL = lchown(path, uid, gid);
1786#else
1787 RETVAL = not_here("lchown");
1788#endif
1789 OUTPUT:
1790 RETVAL