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