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