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