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