2008.xs

filter: Statementstmt 53.4% 702 / 1313 Branchbran 38.5% 563 / 1460 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 45.6% 1265 / 2773 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/POSIX/2008.pm ↑ Summary const-c.inc »
1 /* vim: set ts=2 sw=2 sts=2 expandtab:
2 */
3  
4 #define PACKNAME "POSIX::2008"
5  
6 #ifndef _GNU_SOURCE
7 #define _GNU_SOURCE
8 #endif
9  
10 #define PERL_NO_GET_CONTEXT
11 #include "EXTERN.h"
12 #include "perl.h"
13 #include "XSUB.h"
14  
15 #define NEED_caller_cx /* Needed by constant() in const-xs.inc */
16 #define NEED_croak_xs_usage /* For subroutine argument count checks */
17 #include "ppport.h"
18 #include "2008.h"
19  
20 #ifdef PERL_IMPLICIT_SYS
21 #undef dup
22 #undef open
23 #undef close
24 #undef stat
25 #undef fstat
26 #undef lstat
27 #undef readlink
28 # if !defined(_WIN32) || defined(__CYGWIN__)
29 #undef abort
30 #undef access
31 #undef chdir
32 #undef fchdir
33 #undef chmod
34 #undef fchmod
35 #undef chown
36 #undef fchown
37 #undef fdopen
38 #undef fdopendir
39 #undef getegid
40 #undef geteuid
41 #undef getgid
42 #undef gethostname
43 #undef getuid
44 #undef isatty
45 #undef killpg
46 #undef link
47 #undef mkdir
48 #undef read
49 #undef rename
50 #undef rmdir
51 #undef setgid
52 #undef setuid
53 #undef symlink
54 #undef unlink
55 #undef write
56 # endif
57 #endif
58  
59 #ifdef PSX2008_HAS_COMPLEX_H
60 #include <complex.h>
61 #endif
62 #include <ctype.h>
63 #ifdef I_DIRENT
64 #include <dirent.h>
65 #endif
66 #ifdef PSX2008_HAS_DLFCN_H
67 #include <dlfcn.h>
68 #endif
69 #include <errno.h>
70 #ifdef I_FLOAT
71 #include <float.h>
72 #endif
73 #ifdef I_FCNTL
74 #include <fcntl.h>
75 #endif
76 #include <fenv.h>
77 #ifdef PSX2008_HAS_FNMATCH_H
78 #include <fnmatch.h>
79 #endif
80 #ifdef I_INTTYPES
81 #include <inttypes.h>
82 #endif
83 #ifdef PSX2008_HAS_LIBGEN_H
84 #include <libgen.h>
85 #endif
86 #ifdef I_LIMITS
87 #include <limits.h>
88 #endif
89 #ifdef I_NETDB
90 #include <netdb.h>
91 #endif
92 #ifdef I_MATH
93 #include <math.h>
94 #endif
95 #ifdef PSX2008_HAS_NL_TYPES_H
96 #include <nl_types.h>
97 #endif
98 #if defined(USE_QUADMATH) && defined(I_QUADMATH)
99 #include <quadmath.h>
100 #endif
101 #ifdef PSX2008_HAS_SIGNAL_H
102 #include <signal.h>
103 #endif
104 #ifdef I_STDLIB
105 #include <stdlib.h>
106 #endif
107 #ifdef I_STRING
108 #include <string.h>
109 #endif
110 #ifdef PSX2008_HAS_STRINGS_H
111 #include <strings.h>
112 #endif
113 #ifdef I_SUNMATH
114 #include <sunmath.h>
115 #endif
116 #ifdef I_SYS_PARAM
117 #include <sys/param.h>
118 #endif
119 #if defined(PSX2008_HAS_SYS_RANDOM_H) && (defined(PSX2008_HAS_GETENTROPY) || defined(PSX2008_HAS_GETRANDOM))
120 #include <sys/random.h>
121 #endif
122 #ifdef I_SYS_RESOURCE
123 #include <sys/resource.h>
124 #endif
125 #ifdef PSX2008_HAS_ACCEPT4
126 #include <sys/socket.h>
127 #endif
128 #ifdef I_SYS_STAT
129 #include <sys/stat.h>
130 #endif
131 #ifdef PSX2008_HAS_STATVFS
132 #include <sys/statvfs.h>
133 #endif
134 #ifdef I_SYS_TYPES
135 #include <sys/types.h>
136 #endif
137 #ifdef PSX2008_HAS_SYS_UIO_H
138 #include <sys/uio.h>
139 #endif
140 #ifdef I_TIME
141 #include <time.h>
142 #endif
143 #ifdef PSX2008_HAS_UNISTD_H
144 #include <unistd.h>
145 #endif
146 #ifdef PSX2008_HAS_UTMPX_H
147 #include <utmpx.h>
148 #endif
149 #if defined(PSX2008_HAS_POLL_H)
150 # include <poll.h>
151 #elif defined(PSX2008_HAS_SYS_POLL_H)
152 # include <sys/poll.h>
153 #endif
154  
155 #if defined(PSX2008_HAS_OPENAT2) || \
156 (defined(PSX2008_HAS_GETRANDOM_SYS) && !defined(PSX2008_HAS_GETRANDOM))
157 #include <sys/syscall.h>
158 #endif
159  
160 #ifdef PSX2008_HAS_OPENAT2
161 #include <linux/openat2.h>
162 #endif
163  
164 #if defined(PSX2008_HAS_BCRYPTGENRANDOM) && \
165 !defined(PSX2008_HAS_GETENTROPY) && \
166 !defined(PSX2008_HAS_GETRANDOM) && \
167 !defined(PSX2008_HAS_GETRANDOM_SYS) && \
168 !defined(PSX2008_HAS_ARC4RANDOM_BUF)
169 #include <windows.h>
170 #include <bcrypt.h>
171 #endif
172  
173 #ifndef GETENTROPY_MAX
174 #define GETENTROPY_MAX 256
175 #endif
176  
177 /* __builtin_darn() returns -1 (64-bit) to indicate an error and therefore -1
178 * never occurs as a random number. To work around this we only use the lower
179 * 32 bits. As a result, the chance of getting -1 (32-bit) is a tiny little
180 * bit smaller than for all other numbers. */
181 #if !defined(PSX2008_HAS_GETENTROPY) && \
182 !defined(PSX2008_HAS_GETRANDOM) && \
183 !defined(PSX2008_HAS_GETRANDOM_SYS) && \
184 !defined(PSX2008_HAS_ARC4RANDOM_BUF) && \
185 !defined(PSX2008_HAS_BCRYPTGENRANDOM)
186 # if defined(PSX2008_HAS_DARN)
187 # define _psx_cpu_rand_step_ok(buf) ((*(buf) = __builtin_darn()) != -1)
188 # include <stdint.h>
189 typedef uint64_t _psx_cpu_rand_raw_t;
190 typedef uint32_t _psx_cpu_rand_ret_t;
191 # elif defined(PSX2008_HAS_RNDR)
192 # define _psx_cpu_rand_step_ok(buf) (__rndr(buf) == 0)
193 # include <stdint.h>
194 # ifndef _MSC_VER
195 # include <arm_acle.h>
196 # endif
197 typedef uint64_t _psx_cpu_rand_raw_t;
198 typedef uint64_t _psx_cpu_rand_ret_t;
199 # elif defined(PSX2008_HAS_RDRAND64)
200 # define _psx_cpu_rand_step_ok(buf) (_rdrand64_step(buf) != 0)
201 # ifdef __INTEL_COMPILER /* https://stackoverflow.com/a/72265912 */
202 # include <stdint.h>
203 typedef uint64_t _psx_cpu_rand_raw_t;
204 typedef uint64_t _psx_cpu_rand_ret_t;
205 # else
206 typedef unsigned long long _psx_cpu_rand_raw_t;
207 typedef unsigned long long _psx_cpu_rand_ret_t;
208 # endif
209 # elif defined(PSX2008_HAS_RDRAND32)
210 # define _psx_cpu_rand_step_ok(buf) (_rdrand32_step(buf) != 0)
211 typedef unsigned int _psx_cpu_rand_raw_t;
212 typedef unsigned int _psx_cpu_rand_ret_t;
213 # endif
214 # if defined(PSX2008_HAS_RDRAND64) || defined(PSX2008_HAS_RDRAND32)
215 # include <immintrin.h>
216 # endif
217 #endif
218  
219 #ifdef _psx_cpu_rand_step_ok
220 # if defined(__clang__) || (defined(__GNUC__) && !defined(__INTEL_COMPILER))
221 # if defined(PSX2008_HAS_RDRAND32) || defined(PSX2008_HAS_RDRAND64)
222 # define PSX_CPURAND_TARGET __attribute__((target("rdrnd")))
223 # elif defined(PSX2008_HAS_RNDR)
224 # define PSX_CPURAND_TARGET __attribute__((target("+rng")))
225 # elif defined(PSX2008_HAS_DARN)
226 # ifdef __clang__
227 # define PSX_CPURAND_TARGET __attribute__((target("isa-v30-instructions")))
228 # else
229 # define PSX_CPURAND_TARGET __attribute__((target("cpu=power9")))
230 # endif
231 # endif
232 # else
233 # define PSX_CPURAND_TARGET
234 # endif
235 #endif
236  
237 #if !defined(INFINITY) && defined(NV_INF)
238 #define INFINITY NV_INF
239 #endif
240  
241 #ifndef SVf_QUOTEDPREFIX
242 #define SVf_QUOTEDPREFIX SVf
243 #endif
244  
245 #if IVSIZE > LONGSIZE && defined(PSX2008_HAS_LLDIV)
246 # define PSX2008_DIV_T lldiv_t
247 # define PSX2008_DIV(numer, denom) lldiv(numer, denom)
248 #endif
249 #if IVSIZE > INTSIZE && !defined(PSX2008_DIV) && defined(PSX2008_HAS_LDIV)
250 # define PSX2008_DIV_T ldiv_t
251 # define PSX2008_DIV(numer, denom) ldiv(numer, denom)
252 #endif
253 #if !defined(PSX2008_DIV) && defined(PSX2008_HAS_DIV)
254 # define PSX2008_DIV_T div_t
255 # define PSX2008_DIV(numer, denom) div(numer, denom)
256 #endif
257  
258 #if IVSIZE > LONGSIZE
259 # if defined(PSX2008_HAS_ATOLL)
260 # define PSX2008_ATOI(a) atoll(a)
261 # elif defined(PSX2008_HAS_ATOL)
262 # define PSX2008_ATOI(a) atol(a)
263 # elif defined(PSX2008_HAS_ATOI)
264 # define PSX2008_ATOI(a) atoi(a)
265 # endif
266 # if defined(PSX2008_HAS_FFSLL)
267 # define PSX2008_FFS(i) ffsll(i)
268 # elif defined(PSX2008_HAS_FFSL)
269 # define PSX2008_FFS(i) ffsl(i)
270 # elif defined(PSX2008_HAS_FFS)
271 # define PSX2008_FFS(i) ffs(i)
272 # endif
273 # if defined(PSX2008_HAS_LLABS)
274 # define PSX2008_ABS(i) llabs(i)
275 # elif defined(PSX2008_HAS_LABS)
276 # define PSX2008_ABS(i) labs(i)
277 # elif defined(PSX2008_HAS_ABS)
278 # define PSX2008_ABS(i) abs(i)
279 # endif
280 #elif IVSIZE > INTSIZE
281 # if defined(PSX2008_HAS_ATOL)
282 # define PSX2008_ATOI(a) atol(a)
283 # elif defined(PSX2008_HAS_ATOI)
284 # define PSX2008_ATOI(a) atoi(a)
285 # endif
286 # if defined(PSX2008_HAS_FFSL)
287 # define PSX2008_FFS(i) ffsl(i)
288 # elif defined(PSX2008_HAS_FFS)
289 # define PSX2008_FFS(i) ffs(i)
290 # endif
291 # if defined(PSX2008_HAS_LABS)
292 # define PSX2008_ABS(i) labs(i)
293 # elif defined(PSX2008_HAS_ABS)
294 # define PSX2008_ABS(i) abs(i)
295 # endif
296 #else
297 # if defined(PSX2008_HAS_ATOI)
298 # define PSX2008_ATOI(a) atoi(a)
299 # endif
300 # if defined(PSX2008_HAS_FFS)
301 # define PSX2008_FFS(i) ffs(i)
302 # endif
303 # if defined(PSX2008_HAS_ABS)
304 # define PSX2008_ABS(i) abs(i)
305 # endif
306 #endif
307  
308 #if defined(USE_QUADMATH)
309 # define PSX2008_COMPLEX_T __complex128
310 #elif defined(PSX2008_HAS_COMPLEX_H)
311 # if defined(USE_LONG_DOUBLE)
312 # define PSX2008_COMPLEX_T long double complex
313 # else
314 # define PSX2008_COMPLEX_T double complex
315 # endif
316 #endif
317  
318 /* __real__/__imag__ are gcc extensions but more efficient than "re + im * I".
319 * Since libquadmath is gcc-specific we don't have to worry about the #else
320 * branch if USE_QUADMATH is defined, do we? */
321  
322 #if defined(CMPLX) && !defined(USE_LONG_DOUBLE) && !defined(USE_QUADMATH)
323 # define COMPLEX_FROM_RE_IM(z, r, i) ( (z) = CMPLX((r), (i)) )
324 #elif defined(CMPLXL) && defined(USE_LONG_DOUBLE)
325 # define COMPLEX_FROM_RE_IM(z, r, i) ( (z) = CMPLXL((r), (i)) )
326 #elif defined(__GNUC__)
327 # define COMPLEX_FROM_RE_IM(z, r, i) \
328 ( (__real__ (z) = (r)), (__imag__ (z) = (i)) )
329 #else
330 # define COMPLEX_FROM_RE_IM(z, r, i) ( (z) = (r) + (i) * I )
331 #endif
332  
333 #if defined(USE_QUADMATH)
334 # define RETURN_COMPLEX(z) \
335 STMT_START { \
336 mPUSHs(newSVnv(crealq(z))); \
337 mPUSHs(newSVnv(cimagq(z))); \
338 } STMT_END
339 #elif defined(USE_LONG_DOUBLE)
340 # define RETURN_COMPLEX(z) \
341 STMT_START { \
342 mPUSHs(newSVnv(creall(z))); \
343 mPUSHs(newSVnv(cimagl(z))); \
344 } STMT_END
345 #else
346 # define RETURN_COMPLEX(z) \
347 STMT_START { \
348 mPUSHs(newSVnv(creal(z))); \
349 mPUSHs(newSVnv(cimag(z))); \
350 } STMT_END
351 #endif
352  
353 #if defined(AT_FDCWD) || \
354 defined(PSX2008_HAS_ACCEPT4) || \
355 defined(PSX2008_HAS_DUP3) || \
356 defined(PSX2008_HAS_FCHDIR) || \
357 defined(PSX2008_HAS_FCHMOD) || \
358 defined(PSX2008_HAS_FCHOWN) || \
359 defined(PSX2008_HAS_FDATASYNC) || \
360 defined(PSX2008_HAS_FDOPEN) || \
361 defined(PSX2008_HAS_FDOPENDIR) || \
362 defined(PSX2008_HAS_FEXECVE) || \
363 defined(PSX2008_HAS_FPATHCONF) || \
364 defined(PSX2008_HAS_FSTAT) || \
365 defined(PSX2008_HAS_FSTATVFS) || \
366 defined(PSX2008_HAS_FSYNC) || \
367 defined(PSX2008_HAS_FTRUNCATE) || \
368 defined(PSX2008_HAS_FUTIMENS) || \
369 defined(PSX2008_HAS_GRANTPT) || \
370 defined(PSX2008_HAS_ISATTY) || \
371 defined(PSX2008_HAS_POLL) || \
372 defined(PSX2008_HAS_POSIX_FADVISE) || \
373 defined(PSX2008_HAS_POSIX_FALLOCATE) || \
374 defined(PSX2008_HAS_POSIX_OPENPT) || \
375 defined(PSX2008_HAS_POLL) || \
376 defined(PSX2008_HAS_PTSNAME) || \
377 defined(PSX2008_HAS_READ) || \
378 defined(PSX2008_HAS_READV) || \
379 defined(PSX2008_HAS_PREAD) || \
380 defined(PSX2008_HAS_PREADV) || \
381 defined(PSX2008_HAS_PREADV2) || \
382 defined(PSX2008_HAS_TTYNAME) || \
383 defined(PSX2008_HAS_UNLOCKPT) || \
384 defined(PSX2008_HAS_WRITE) || \
385 defined(PSX2008_HAS_WRITEV) || \
386 defined(PSX2008_HAS_PWRITE) || \
387 defined(PSX2008_HAS_PWRITEV) || \
388 defined(PSX2008_HAS_PWRITEV2)
389 #define PSX2008_NEED_PSX_FILENO
390 #endif
391  
392 #if IVSIZE < Off_t_size
393 #define SvOFFt(sv) ((Off_t)SvNV(sv))
394 #else
395 #define SvOFFt(sv) ((Off_t)SvIV(sv))
396 #endif
397  
398 /* SvTIMEt is used by the typemap. */
399 #define SvTIMEt(sv) ((IVSIZE < sizeof(Time_t)) ? (Time_t)SvNV(sv) : (Time_t)SvIV(sv))
400  
401 #if IVSIZE < Size_t_size
402 #define SvSIZEt(sv) ((Size_t)SvNV(sv))
403 #define SvSTRLEN(sv) ((STRLEN)SvNV(sv))
404 #else
405 #define SvSIZEt(sv) ((Size_t)SvIV(sv))
406 #define SvSTRLEN(sv) ((STRLEN)SvIV(sv))
407 #endif
408  
409 /* https://perldoc.perl.org/perlguts#Read-Only-Values */
410 #if PERL_BCDVERSION >= 0x5018000
411 # define SvTRULYREADONLY(sv) SvREADONLY(sv)
412 #else
413 # define SvTRULYREADONLY(sv) (SvREADONLY(sv) && !SvIsCOW(sv))
414 #endif
415  
416 #define SvIsARRAY(sv) (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV)
417  
418 /* Treat omitted and explicitly undef arguments as if intended by the caller
419 * to avoid annoying "uninitialized" warnings. */
420 #define SvIsUNDEF_onpurpose(sv) (!(sv) || (sv) == &PL_sv_undef)
421  
422 /* Round up l to the next multiple of PERL_STRLEN_ROUNDUP_QUANTUM even if it
423 * already is a multiple so that we always have room for a trailing '\0'. +1
424 * does the trick. */
425 #define TopUpLEN(l) \
426 ((l)+1 < (l) ? (croak_memory_wrap(),0) : PERL_STRLEN_ROUNDUP((l)+1))
427  
428 #ifndef PSX2008_HAS_NFDS_T
429 typedef unsigned long nfds_t;
430 #endif
431  
432 #ifdef HAS_LONG_LONG
433 typedef long long IMax_t;
434 typedef unsigned long long UMax_t;
435 #else
436 typedef long IMax_t;
437 typedef unsigned long UMax_t;
438 #endif
439  
440 typedef int SysRet; /* returns -1 as undef, 0 as "0 but true", other unchanged */
441 typedef int SysRet0; /* returns -1 as undef, other unchanged */
442 typedef int SysRetTrue; /* returns 0 as "0 but true", undef otherwise */
443 typedef int psx_fd_t; /* checks for file handle or descriptor via typemap */
444 typedef const char* psx_safepath_t__fail_undef;
445 typedef const char* psx_safepath_t__fail_false_or_empty;
446  
447 /* https://sourceforge.net/p/mingw-w64/feature-requests/68/ */
448 #if defined(__MINGW32__) && defined(__STRICT_ANSI__) && !defined(USE_QUADMATH)
449 double __cdecl j0(double);
450 double __cdecl j1(double);
451 double __cdecl jn(int, double);
452 double __cdecl y0(double);
453 double __cdecl y1(double);
454 double __cdecl yn(int, double);
455 #endif
456  
457 #include "const-c.inc"
458  
459 #ifdef _psx_cpu_rand_step_ok
460 PSX_CPURAND_TARGET
461 PERL_STATIC_INLINE void
462 _cpu_rand50c(void *buf, Size_t len)
463 {
464 /* Crypto++ says rdrand doesn't need a retry limit. So be it. */
465 if (LIKELY(buf)) {
466 _psx_cpu_rand_raw_t rand_val;
467 _psx_cpu_rand_ret_t *ubuf = (_psx_cpu_rand_ret_t *)buf;
468 Size_t rest = len % sizeof(_psx_cpu_rand_ret_t);
469 #pragma GCC unroll 1 /* https://github.com/llvm/llvm-project/issues/42332 */
470 for (len /= sizeof(_psx_cpu_rand_ret_t); len; len--, ubuf++) {
471 do {} while (! _psx_cpu_rand_step_ok(&rand_val));
472 *ubuf = (_psx_cpu_rand_ret_t)rand_val;
473 }
474 if (rest) {
475 _psx_cpu_rand_ret_t u;
476 do {} while (! _psx_cpu_rand_step_ok(&rand_val));
477 u = (_psx_cpu_rand_ret_t)rand_val;
478 memcpy(ubuf, &u, rest);
479 }
480 }
481 }
482 #endif /* _psx_cpu_rand_step_ok */
483  
484 #ifdef EBCDIC
485 # define psx_isCNTRL(c) isCNTRL(c)
486 # define psx_isPRINT(c) isPRINT(c)
487 #else
488 # define psx_isCNTRL(c) ((unsigned)(c) < ' ' || (c) == 127)
489 # define psx_isPRINT(c) ((unsigned)((c) - ' ') < 95)
490 #endif
491 #define psx_isDIGIT(c) ((unsigned)((c) - '0') < 10)
492 #if defined(EBCDIC) || UVSIZE < 4
493 # define psx_needWHACK(c) (!!memCHRs("\"$%@\\", (c)))
494 #elif UVSIZE > 4
495 # define psx_needWHACK(c) ( (UV)((c) - 34) <= 58 && (UV)((UV)1 << ((c) - 34)) & (UV)0x40000004000000d )
496 #else
497 # define psx_needWHACK(c) (((UV)((c) - 34) <= 30 && (UV)((UV)1 << ((c) - 34)) & (UV)0x4000000d) || (c) == '\\')
498 #endif
499 PERL_STATIC_INLINE STRLEN
500 0 _psx_isprint_len(const char *const s, const STRLEN len)
501 {
502 STRLEN i;
503 0 ▶ for (i = 0; i < len && psx_isPRINT(s[i]) && !psx_needWHACK(s[i]); i++) ;
Branch: 4 branches
BranchTrueFalseTotal
for (i = 0; i < len && psx_isPRINT(s[i]) && !psx_needWHACK(s[i]); i++) ; 0 0 0
for (i = 0; i < len && psx_isPRINT(s[i]) && !psx_needWHACK(s[i]); i++) ; 0 0 0
for (i = 0; i < len && psx_isPRINT(s[i]) && !psx_needWHACK(s[i]); i++) ; 0 0 0
for (i = 0; i < len && psx_isPRINT(s[i]) && !psx_needWHACK(s[i]); i++) ; 0 0 0
504 0 return i;
505 }
506  
507 PERL_STATIC_INLINE STRLEN
508 0 _psx_utf8mb_len(pTHX_ const U8 *const s, const STRLEN len)
509 {
510 STRLEN charlen;
511 0 const U8 *str = s;
512 0 const U8 *end = s + len;
513 0 ▶ while ((charlen = isUTF8_CHAR((U8*)str, end)) > 1)
Branch: 1 branch
BranchTrueFalseTotal
while ((charlen = isUTF8_CHAR((U8*)str, end)) > 1) 0 0 0
514 0 str += charlen;
515 0 return str - s;
516 }
517  
518 /*
519 * Alternative to pv_escape() that seems more appropriate for warnings:
520 * - Doesn't escape utf-8 (assuming utf-8 is what kool kids use these days).
521 * - Escapes control characters, sigils, backslash, double quotes, non-utf-8.
522 * - Allows mixing utf-8 with garbage.
523 * - No fiddling with poorly documented magical flags.
524 */
525 static char *
526 1 _psx_pv_escape(pTHX_ SV *dsv, char const *const pv, const STRLEN len,
527 const STRLEN out_max, STRLEN *const consumed)
528 {
529 1 const char *fmt, *str = pv;
530 1 const char *const end = str + len;
531 1 STRLEN esclen, step, out_left = out_max;
532  
533 2 ▶ for (step = 1; str < end; str += step, step = 1) {
Branch: 1 branch
BranchTrueFalseTotal
for (step = 1; str < end; str += step, step = 1) { 1 1 2
534 1 char c = *str;
535 1 bool nq = FALSE;
536 1 ▶ if (psx_isCNTRL(c) || (nq = psx_needWHACK(c))) {
Branch: 5 branches
BranchTrueFalseTotal
if (psx_isCNTRL(c) || (nq = psx_needWHACK(c))) { 0 1 1
if (psx_isCNTRL(c) || (nq = psx_needWHACK(c))) { 0 0 0
if (psx_isCNTRL(c) || (nq = psx_needWHACK(c))) { 0 0 0
if (psx_isCNTRL(c) || (nq = psx_needWHACK(c))) { 0 0 0
if (psx_isCNTRL(c) || (nq = psx_needWHACK(c))) { 0 0 0
537 1 ▶ bool next_isdigit = str + 1 < end && psx_isDIGIT(*(str + 1));
Branch: 2 branches
BranchTrueFalseTotal
bool next_isdigit = str + 1 < end && psx_isDIGIT(*(str + 1)); 0 1 1
bool next_isdigit = str + 1 < end && psx_isDIGIT(*(str + 1)); 0 0 0
538 #ifndef EBCDIC
539 static const char *const ltrs = "abtn\0fr"; /* \v\e dropped on purpose. */
540 1 unsigned cm7 = c - 7;
541 1 ▶ char letter = cm7 < 7 ? ltrs[cm7] : nq ? c : 0;
Branch: 2 branches
BranchTrueFalseTotal
char letter = cm7 < 7 ? ltrs[cm7] : nq ? c : 0; 0 1 1
char letter = cm7 < 7 ? ltrs[cm7] : nq ? c : 0; 0 1 1
542 #else
543 char letter;
544 switch (c) {
545 case '\a': letter = 'a'; break; case '\b': letter = 'b'; break;
546 case '\t': letter = 't'; break; case '\n': letter = 'n'; break;
547 case '\f': letter = 'f'; break; case '\r': letter = 'r'; break;
548 default: letter = nq ? c : 0;
549 }
550 #endif
551 1 ▶ c = letter ? letter : c;
Branch: 1 branch
BranchTrueFalseTotal
c = letter ? letter : c; 0 1 1
552 1 ▶ fmt = letter ? "\\%c" : next_isdigit ? "\\%.3o" : "\\%o";
Branch: 2 branches
BranchTrueFalseTotal
fmt = letter ? "\\%c" : next_isdigit ? "\\%.3o" : "\\%o"; 1 0 1
fmt = letter ? "\\%c" : next_isdigit ? "\\%.3o" : "\\%o"; 0 1 1
553 1 ▶ esclen = letter ? 2 : next_isdigit ? 4 : !!(c & 0370) + !!(c & 0300) + 2;
Branch: 2 branches
BranchTrueFalseTotal
esclen = letter ? 2 : next_isdigit ? 4 : !!(c & 0370) + !!(c & 0300) + 2; 1 0 1
esclen = letter ? 2 : next_isdigit ? 4 : !!(c & 0370) + !!(c & 0300) + 2; 0 1 1
554 }
555 else {
556 0 STRLEN in_left = end - str;
557 0 ▶ in_left = out_max && out_left < in_left ? out_left : in_left;
Branch: 2 branches
BranchTrueFalseTotal
in_left = out_max && out_left < in_left ? out_left : in_left; 0 0 0
in_left = out_max && out_left < in_left ? out_left : in_left; 0 0 0
558 0 ▶ if (!in_left)
Branch: 1 branch
BranchTrueFalseTotal
if (!in_left) 0 0 0
559 0 break;
560 0 if ((esclen = _psx_isprint_len(str, in_left)) ||
561 0 (esclen = _psx_utf8mb_len(aTHX_ (U8*)str, in_left))) {
562 0 fmt = NULL;
563 0 step = esclen;
564 }
565 else {
566 0 fmt = "\\%.3o";
567 0 esclen = 4;
568 }
569 }
570 1 ▶ if (out_max) {
Branch: 1 branch
BranchTrueFalseTotal
if (out_max) { 1 0 1
571 1 ▶ if (out_left < esclen)
Branch: 1 branch
BranchTrueFalseTotal
if (out_left < esclen) 0 1 1
572 0 break;
573 1 out_left -= esclen;
574 }
575 1 ▶ if (fmt)
Branch: 1 branch
BranchTrueFalseTotal
if (fmt) 1 0 1
576 1 sv_catpvf(dsv, fmt, (unsigned char)c);
577 else
578 0 sv_catpvn(dsv, str, esclen);
579 }
580  
581 1 ▶ if (consumed)
Branch: 1 branch
BranchTrueFalseTotal
if (consumed) 1 0 1
582 1 *consumed = str - pv;
583  
584 1 return SvPVX(dsv);
585 }
586  
587 /*
588 * This IS_SAFE_PATHNAME amends a few shortcomings of Perl's original:
589 * - It rejects a trailing \0 just like Python does.
590 * - It limits the length of the warning and escapes control characters and
591 * non-utf-8 bytes to not mess up your terminal or logs.
592 * - It takes a CV instead of a string to figure out the non-aliased sub name.
593 */
594 #undef IS_SAFE_PATHNAME
595 #define IS_SAFE_PATHNAME(pv, len, cv) (LIKELY(!!(len)) && UNLIKELY(!!memchr((pv), 0, (len))) ? (_psx_warn_null_char(aTHX_ (pv), (len), (cv)), 0) : 1)
596 #ifdef WARN_SYSCALLS
597 # define PSX_WARNCAT WARN_SYSCALLS
598 #else
599 # define PSX_WARNCAT WARN_MISC
600 #endif
601 static void
602 1 _psx_warn_null_char(pTHX_ const char *const pv, const STRLEN len,
603 const CV *const cv)
604 {
605 1 ▶ if (ckWARN(PSX_WARNCAT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ckWARN(PSX_WARNCAT)) { 1 0 1
606 STRLEN consumed;
607 1 const char *mesg = "%s: embedded null character in path: \"%s\"%s";
608 1 const char *func = GvNAME(CvGV(cv)); /* Can this contain an embedded \0? */
609 1 SV *dsv = newSVpvs_flags("", SVs_TEMP);
610 1 const char *escaped = _psx_pv_escape(aTHX_ dsv, pv, len, 0xffff, &consumed);
611 1 ▶ const char *truncated = consumed < len ? " [truncated]" : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *truncated = consumed < len ? " [truncated]" : ""; 0 1 1
612 1 warn(mesg, func, escaped, truncated);
613 }
614 1 SETERRNO(ENOENT, LIB_INVARG); /* ENOENT feels wrong, but we follow Perl. */
615 1 }
616  
617 #define SvIsNEGATIVE(sv) _psx_SvIsNEGATIVE(aTHX_ sv)
618 static unsigned /* It's unsigned on purpose! */
619 54 _psx_SvIsNEGATIVE(pTHX_ SV *sv)
620 {
621 SV *tmpsv;
622 54 ▶ if (!sv)
Branch: 1 branch
BranchTrueFalseTotal
if (!sv) 1 53 54
623 1 return 0;
624 53 ▶ SvGETMAGIC(sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sv); 0 53 53
SvGETMAGIC(sv); 0 0 0
625 53 ▶ if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer)))
Branch: 5 branches
BranchTrueFalseTotal
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 0 53 53
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 0 0 0
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 0 53 53
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 0 0 0
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 0 0 0
626 0 sv = tmpsv;
627 53 ▶ if (!SvOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(sv)) 2 51 53
628 2 return 0;
629 51 ▶ if (SvIOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK(sv)) 51 0 51
630 51 ▶ return !SvIsUV(sv) && SvIVX(sv) < 0;
Branch: 2 branches
BranchTrueFalseTotal
return !SvIsUV(sv) && SvIVX(sv) < 0; 49 2 51
return !SvIsUV(sv) && SvIVX(sv) < 0; 14 35 49
631 0 ▶ if (SvNOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOK(sv)) 0 0 0
632 0 return SvNVX(sv) < 0;
633 0 ▶ if (SvPOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(sv)) 0 0 0
634 0 return !!(grok_number(SvPVX_const(sv), SvCUR(sv), NULL) & IS_NUMBER_NEG);
635 0 return 0;
636 }
637  
638 static int
639 70 _psx_looks_like_number(pTHX_ SV *sv)
640 {
641 SV *tmpsv;
642 70 ▶ if (!sv)
Branch: 1 branch
BranchTrueFalseTotal
if (!sv) 0 70 70
643 0 return 0;
644 70 ▶ SvGETMAGIC(sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sv); 0 70 70
SvGETMAGIC(sv); 0 0 0
645 70 ▶ if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer)))
Branch: 5 branches
BranchTrueFalseTotal
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 53 17 70
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 2 51 53
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 2 68 70
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 1 1 2
if (UNLIKELY(SvAMAGIC(sv)) && (tmpsv = AMG_CALLun(sv, numer))) 0 1 1
646 0 sv = tmpsv;
647 #if PERL_BCDVERSION >= 0x5008005
648 70 return looks_like_number(sv);
649 #else
650 if (SvPOK(sv) || SvPOKp(sv))
651 return looks_like_number(sv);
652 else
653 return (SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK));
654 #endif
655 }
656  
657 /* strnlen() shamelessly plagiarized from dietlibc (https://www.fefe.de/) */
658 static Size_t
659 0 _strnlen(const char *s, Size_t maxlen)
660 {
661 0 const char *n = (const char *)memchr(s, 0, maxlen);
662 0 ▶ if (!n)
Branch: 1 branch
BranchTrueFalseTotal
if (!n) 0 0 0
663 0 n = s + maxlen;
664 0 return n - s;
665 }
666  
667 /* _fmt_uint() shamelessly plagiarized from libowfat (https://www.fefe.de/) */
668 static unsigned
669 0 _fmt_uint(char *dest, UMax_t u)
670 {
671 unsigned len, len2;
672 UMax_t tmp;
673 /* count digits */
674 0 ▶ for (len=1, tmp=u; tmp>9; ++len)
Branch: 1 branch
BranchTrueFalseTotal
for (len=1, tmp=u; tmp>9; ++len) 0 0 0
675 0 tmp /= 10;
676 0 ▶ if (dest)
Branch: 1 branch
BranchTrueFalseTotal
if (dest) 0 0 0
677 0 ▶ for (tmp=u, dest+=len, len2=len+1; --len2; tmp/=10)
Branch: 1 branch
BranchTrueFalseTotal
for (tmp=u, dest+=len, len2=len+1; --len2; tmp/=10) 0 0 0
678 0 *--dest = (char)((tmp%10)+'0');
679 0 return len;
680 }
681  
682 static unsigned
683 0 _fmt_neg_int(char *dest, IMax_t i)
684 {
685 0 ▶ if (dest)
Branch: 1 branch
BranchTrueFalseTotal
if (dest) 0 0 0
686 0 *dest++ = '-';
687 0 return _fmt_uint(dest, (UMax_t)(-(i+1))+1) + 1;
688 }
689  
690 static SV*
691 0 _fmt_uint_2sv(pTHX_ UMax_t u)
692 {
693 char dest[40];
694 0 unsigned len = _fmt_uint(dest, u);
695 0 return newSVpvn(dest, len);
696 }
697  
698 static SV*
699 0 _fmt_neg_int_2sv(pTHX_ IMax_t i)
700 {
701 char dest[40];
702 0 unsigned len = _fmt_neg_int(dest, i);
703 0 return newSVpvn(dest, len);
704 }
705  
706 #ifndef CLANG_DIAG_IGNORE_STMT
707 # define CLANG_DIAG_IGNORE_STMT(x) NOOP
708 # define CLANG_DIAG_RESTORE_STMT NOOP
709 #endif
710 #ifndef GCC_DIAG_IGNORE_STMT
711 # define GCC_DIAG_IGNORE_STMT(x) NOOP
712 # define GCC_DIAG_RESTORE_STMT NOOP
713 #endif
714  
715 /* Push int_val as an IV, UV or PV depending on how big the value is. */
716 #define PUSH_INT_OR_PV(int_val) STMT_START { \
717 SV *piop_tmp_sv; \
718 CLANG_DIAG_IGNORE_STMT(-Wtautological-compare); \
719 GCC_DIAG_IGNORE_STMT(-Wtype-limits); \
720 if ((int_val) < 0) { \
721 if (LIKELY((IMax_t)(int_val) >= (IMax_t)IV_MIN)) \
722 piop_tmp_sv = newSViv((IV)(int_val)); \
723 else \
724 piop_tmp_sv = _fmt_neg_int_2sv(aTHX_ int_val); \
725 } \
726 else if (LIKELY((UMax_t)(int_val) <= (UMax_t)IV_MAX)) \
727 piop_tmp_sv = newSViv((IV)(int_val)); \
728 else if ((UMax_t)(int_val) <= (UMax_t)UV_MAX) \
729 piop_tmp_sv = newSVuv((UV)(int_val)); \
730 else \
731 piop_tmp_sv = _fmt_uint_2sv(aTHX_ int_val); \
732 GCC_DIAG_RESTORE_STMT; \
733 CLANG_DIAG_RESTORE_STMT; \
734 mPUSHs(piop_tmp_sv); \
735 } STMT_END
736  
737 #ifdef PSX2008_HAS_STAT
738 /* We return decimal strings for values outside the IV_MIN..UV_MAX range. */
739 static SV **
740 5 _push_stat_buf(pTHX_ SV **SP, struct stat *st)
741 {
742 5 ▶ PUSH_INT_OR_PV(st->st_dev);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_dev); 5 0 5
743 5 ▶ PUSH_INT_OR_PV(st->st_ino);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_ino); 5 0 5
744 5 PUSH_INT_OR_PV(st->st_mode);
745 5 ▶ PUSH_INT_OR_PV(st->st_nlink);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_nlink); 5 0 5
746 5 PUSH_INT_OR_PV(st->st_uid);
747 5 PUSH_INT_OR_PV(st->st_gid);
748 5 ▶ PUSH_INT_OR_PV(st->st_rdev);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_rdev); 5 0 5
749 5 ▶ PUSH_INT_OR_PV(st->st_size);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_size); 0 5 5
PUSH_INT_OR_PV(st->st_size); 5 0 5
750 5 ▶ PUSH_INT_OR_PV(st->st_atime);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_atime); 0 5 5
PUSH_INT_OR_PV(st->st_atime); 5 0 5
751 5 ▶ PUSH_INT_OR_PV(st->st_mtime);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_mtime); 0 5 5
PUSH_INT_OR_PV(st->st_mtime); 5 0 5
752 #ifdef PSX2008_HAS_ST_CTIME
753 5 ▶ PUSH_INT_OR_PV(st->st_ctime);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_ctime); 0 5 5
PUSH_INT_OR_PV(st->st_ctime); 5 0 5
754 #else
755 PUSHs(&PL_sv_undef);
756 #endif
757 /* Actually these come before the times but we follow core stat. */
758 #ifdef USE_STAT_BLOCKS
759 5 ▶ PUSH_INT_OR_PV(st->st_blksize);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_blksize); 0 5 5
PUSH_INT_OR_PV(st->st_blksize); 5 0 5
760 5 ▶ PUSH_INT_OR_PV(st->st_blocks);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_blocks); 0 5 5
PUSH_INT_OR_PV(st->st_blocks); 5 0 5
761 #else
762 PUSHs(&PL_sv_undef);
763 PUSHs(&PL_sv_undef);
764 #endif
765 #if defined(PSX2008_HAS_ST_ATIM)
766 5 ▶ PUSH_INT_OR_PV(st->st_atim.tv_nsec);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_atim.tv_nsec); 0 5 5
PUSH_INT_OR_PV(st->st_atim.tv_nsec); 5 0 5
767 5 ▶ PUSH_INT_OR_PV(st->st_mtim.tv_nsec);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_mtim.tv_nsec); 0 5 5
PUSH_INT_OR_PV(st->st_mtim.tv_nsec); 5 0 5
768 # ifdef PSX2008_HAS_ST_CTIME
769 5 ▶ PUSH_INT_OR_PV(st->st_ctim.tv_nsec);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->st_ctim.tv_nsec); 0 5 5
PUSH_INT_OR_PV(st->st_ctim.tv_nsec); 5 0 5
770 # else
771 PUSHs(&PL_sv_undef);
772 # endif
773 #elif defined(PSX2008_HAS_ST_ATIMENSEC)
774 PUSH_INT_OR_PV(st->st_atimensec);
775 PUSH_INT_OR_PV(st->st_mtimensec);
776 # ifdef PSX2008_HAS_ST_CTIME
777 PUSH_INT_OR_PV(st->st_ctimensec);
778 # else
779 PUSHs(&PL_sv_undef);
780 # endif
781 #endif
782  
783 5 return SP;
784 }
785  
786 #define RETURN_STAT_BUF(rv, buf) STMT_START { \
787 switch (GIMME_V) { \
788 case G_LIST: \
789 if ((rv) == 0) { \
790 EXTEND(SP, 16); \
791 SP = _push_stat_buf(aTHX_ SP, &(buf)); \
792 } \
793 break; \
794 default: \
795 PUSHs(boolSV((rv) == 0)); \
796 break; \
797 } \
798 } STMT_END
799 #endif
800  
801 #ifdef PSX2008_HAS_STATVFS
802 static SV **
803 2 _push_statvfs_buf(pTHX_ SV **SP, struct statvfs *st)
804 {
805 2 ▶ PUSH_INT_OR_PV(st->f_bsize);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_bsize); 2 0 2
806 2 ▶ PUSH_INT_OR_PV(st->f_frsize);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_frsize); 2 0 2
807 2 ▶ PUSH_INT_OR_PV(st->f_blocks);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_blocks); 2 0 2
808 2 ▶ PUSH_INT_OR_PV(st->f_bfree);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_bfree); 2 0 2
809 2 ▶ PUSH_INT_OR_PV(st->f_bavail);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_bavail); 2 0 2
810 2 ▶ PUSH_INT_OR_PV(st->f_files);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_files); 2 0 2
811 2 ▶ PUSH_INT_OR_PV(st->f_ffree);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_ffree); 2 0 2
812 2 ▶ PUSH_INT_OR_PV(st->f_favail);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_favail); 2 0 2
813 2 ▶ PUSH_INT_OR_PV(st->f_fsid);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_fsid); 2 0 2
814 2 ▶ PUSH_INT_OR_PV(st->f_flag);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_flag); 2 0 2
815 2 ▶ PUSH_INT_OR_PV(st->f_namemax);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_INT_OR_PV(st->f_namemax); 2 0 2
816  
817 2 return SP;
818 }
819  
820 #define RETURN_STATVFS_BUF(rv, buf) STMT_START { \
821 switch (GIMME_V) { \
822 case G_LIST: \
823 if (rv == 0) { \
824 EXTEND(SP, 11); \
825 SP = _push_statvfs_buf(aTHX_ SP, &(buf)); \
826 } \
827 break; \
828 default: \
829 PUSHs(boolSV(rv == 0)); \
830 break; \
831 } \
832 } STMT_END
833 #endif
834  
835 #ifdef PSX2008_NEED_PSX_FILENO
836 /* _nomg only means we save one SvGETMAGIC(sv) at the beginning. */
837 static int
838 70 _psx_fileno_nomg(pTHX_ SV *sv, int *sv_is_fd)
839 {
840 70 int fn = -1;
841  
842 /* On Solaris, AT_FDCWD is 0xffd19553 (4291925331), so don't do any integer
843 * range checks, just cast the SvIV to int and may the --force be with you.
844 * https://github.com/python/cpython/issues/60169
845 */
846 70 ▶ if (!SvOK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(sv)) { 0 70 70
847 0 ▶ if (sv_is_fd)
Branch: 1 branch
BranchTrueFalseTotal
if (sv_is_fd) 0 0 0
848 0 *sv_is_fd = 0;
849 }
850 else {
851 IO *io;
852 70 const int lln = _psx_looks_like_number(aTHX_ sv);
853 70 ▶ if (sv_is_fd)
Branch: 1 branch
BranchTrueFalseTotal
if (sv_is_fd) 6 64 70
854 6 *sv_is_fd = lln;
855 70 ▶ if (lln)
Branch: 1 branch
BranchTrueFalseTotal
if (lln) 16 54 70
856 16 fn = (int)SvIV(sv);
857 54 ▶ else if ((io = sv_2io(sv))) {
Branch: 1 branch
BranchTrueFalseTotal
else if ((io = sv_2io(sv))) { 53 0 53
858 /* Magic part taken from Perl 5.8.9's pp_fileno. */
859 53 ▶ const MAGIC *mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar);
Branch: 1 branch
BranchTrueFalseTotal
const MAGIC *mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar); 0 53 53
860 53 ▶ if (mg) {
Branch: 1 branch
BranchTrueFalseTotal
if (mg) { 0 53 53
861 0 dSP;
862 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
863 0 ▶ XPUSHs(SvTIED_obj((SV*)io, mg));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(SvTIED_obj((SV*)io, mg)); 0 0 0
XPUSHs(SvTIED_obj((SV*)io, mg)); 0 0 0
864 0 PUTBACK;
865 0 ENTER;
866 0 call_method("FILENO", G_SCALAR);
867 0 LEAVE;
868 0 SPAGAIN;
869 0 fn = (int)POPi;
870 0 PUTBACK;
871 }
872 53 ▶ else if (IoIFP(io)) /* from open() or sysopen() */
Branch: 1 branch
BranchTrueFalseTotal
else if (IoIFP(io)) /* from open() or sysopen() */ 40 13 53
873 40 fn = PerlIO_fileno(IoIFP(io));
874 13 ▶ else if (IoDIRP(io)) { /* from opendir() */
Branch: 1 branch
BranchTrueFalseTotal
else if (IoDIRP(io)) { /* from opendir() */ 13 0 13
875 #if defined(HAS_DIRFD) || defined(HAS_DIR_DD_FD)
876 13 fn = my_dirfd(IoDIRP(io));
877 #endif
878 }
879 }
880 }
881  
882 69 return fn;
883 }
884  
885 PERL_STATIC_INLINE int
886 61 _psx_fileno(pTHX_ SV *sv, int *sv_is_fd)
887 {
888 61 ▶ SvGETMAGIC(sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sv); 0 61 61
SvGETMAGIC(sv); 0 0 0
889 61 return _psx_fileno_nomg(aTHX_ sv, sv_is_fd);
890 }
891 #endif
892  
893 #if defined(PSX2008_HAS_EXECVEAT) || defined(PSX2008_HAS_FEXECVE)
894 /* We don't check for '\0' or '=' within args or env. Not our business. */
895 static void
896 4 _execve50c(pTHX_ int fd, const char *path, AV *args, SV *envsv, int flags)
897 {
898 Size_t argc, n;
899 char **argv, **envp;
900 4 char *empty_env[] = { NULL };
901 4 HV *envhv = NULL;
902  
903 # ifndef PSX2008_HAS_EXECVEAT
904 if (path) { SETERRNO(ENOSYS, SS$_UNSUPPORTED); return; }
905 # endif
906 # ifndef PSX2008_HAS_FEXECVE
907 if (!path) { SETERRNO(ENOSYS, SS$_UNSUPPORTED); return; }
908 # endif
909  
910 4 ▶ if (!SvIsUNDEF_onpurpose(envsv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIsUNDEF_onpurpose(envsv)) { 4 0 4
if (!SvIsUNDEF_onpurpose(envsv)) { 4 0 4
911 4 ▶ SvGETMAGIC(envsv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(envsv); 0 4 4
SvGETMAGIC(envsv); 0 0 0
912 4 ▶ if (SvROK(envsv) && SvTYPE(SvRV(envsv)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(envsv) && SvTYPE(SvRV(envsv)) == SVt_PVHV) 2 2 4
if (SvROK(envsv) && SvTYPE(SvRV(envsv)) == SVt_PVHV) 2 0 2
913 2 envhv = (HV*)SvRV(envsv);
914 else {
915 2 ▶ const char *func = path ? "execveat" : "fexecve";
Branch: 1 branch
BranchTrueFalseTotal
const char *func = path ? "execveat" : "fexecve"; 1 1 2
916 2 croak(PACKNAME "::%s: env is not a HASH reference: %" SVf_QUOTEDPREFIX,
917 func, SVfARG(envsv));
918 }
919 }
920  
921 /* Allocate memory for argv pointers; +1 for terminating NULL pointer. */
922 2 argc = av_count(args);
923 2 ▶ if (argc+1 == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (argc+1 == 0) 0 2 2
924 0 --argc;
925 2 ▶ if (((argc+1)*sizeof(char*))/sizeof(char*) != (argc+1))
Branch: 1 branch
BranchTrueFalseTotal
if (((argc+1)*sizeof(char*))/sizeof(char*) != (argc+1)) 0 2 2
926 0 goto TheZohan;
927 2 argv = (char**)safemalloc((argc+1)*sizeof(char*));
928 2 ▶ if (!argv)
Branch: 1 branch
BranchTrueFalseTotal
if (!argv) 0 2 2
929 0 goto TheZohan;
930 2 SAVEFREEPV(argv);
931 2 argv[argc] = NULL;
932  
933 /* Build argv string array from args array ref. */
934 3 ▶ for (n = 0; n < argc; n++) {
Branch: 1 branch
BranchTrueFalseTotal
for (n = 0; n < argc; n++) { 1 2 3
935 SV **argsv;
936 1 argv[n] = NULL;
937 1 argsv = av_fetch(args, n, 0);
938 1 ▶ if (!argsv)
Branch: 1 branch
BranchTrueFalseTotal
if (!argsv) 0 1 1
939 0 argv[n] = (char*)""; /* This is what Perl's exec() does for placeholders. */
940 else {
941 STRLEN cur;
942 1 (void)SvPV(*argsv, cur);
943 1 ▶ if (LIKELY(cur+1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(cur+1)) { 1 0 1
944 /* +1 for final '\0' to be on the safe side. */
945 1 ▶ argv[n] = SvGROW(*argsv, cur+1);
Branch: 2 branches
BranchTrueFalseTotal
argv[n] = SvGROW(*argsv, cur+1); 0 1 1
argv[n] = SvGROW(*argsv, cur+1); 0 0 0
946 1 argv[n][cur] = '\0';
947 }
948 else
949 0 goto TheZohan;
950 }
951 }
952  
953 2 ▶ if (!envhv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!envhv) { 0 2 2
954 extern char **environ;
955 0 ▶ envp = environ ? environ : empty_env;
Branch: 1 branch
BranchTrueFalseTotal
envp = environ ? environ : empty_env; 0 0 0
956 }
957 else {
958 Size_t envc;
959 /* Count envhv keys. */
960 2 ▶ if (!SvMAGICAL(envhv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvMAGICAL(envhv)) 2 0 2
961 2 ▶ envc = HvUSEDKEYS(envhv);
Branch: 1 branch
BranchTrueFalseTotal
envc = HvUSEDKEYS(envhv); 0 2 2
962 else {
963 /* HvUSEDKEYS() doesn't work for magic hashes (e.g. DB_File). */
964 0 hv_iterinit(envhv);
965 0 ▶ for (envc = 0; hv_iternext(envhv) && envc+1; envc++) {}
Branch: 2 branches
BranchTrueFalseTotal
for (envc = 0; hv_iternext(envhv) && envc+1; envc++) {} 0 0 0
for (envc = 0; hv_iternext(envhv) && envc+1; envc++) {} 0 0 0
966 }
967 2 ▶ if (envc+1 == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (envc+1 == 0) 0 2 2
968 0 --envc;
969 2 ▶ if (((envc+1)*sizeof(char*))/sizeof(char*) != (envc+1))
Branch: 1 branch
BranchTrueFalseTotal
if (((envc+1)*sizeof(char*))/sizeof(char*) != (envc+1)) 0 2 2
970 0 goto TheZohan;
971 2 envp = (char**)safemalloc((envc+1)*sizeof(char*));
972 2 ▶ if (!envp)
Branch: 1 branch
BranchTrueFalseTotal
if (!envp) 0 2 2
973 0 goto TheZohan;
974 2 SAVEFREEPV(envp);
975 2 envp[envc] = NULL;
976  
977 /* Build envp ("key=value") string array from envhv hash ref. Iterate at
978 * most envc times (envhv could be changed in another thread). */
979 2 hv_iterinit(envhv);
980 2 ▶ for (n = 0; n < envc; n++) {
Branch: 1 branch
BranchTrueFalseTotal
for (n = 0; n < envc; n++) { 0 2 2
981 I32 klen;
982 char *env_key;
983 SV *valsv;
984 0 envp[n] = NULL;
985 0 valsv = hv_iternextsv(envhv, &env_key, &klen);
986 0 ▶ if (!valsv) /* envhv shrunk along the way. */
Branch: 1 branch
BranchTrueFalseTotal
if (!valsv) /* envhv shrunk along the way. */ 0 0 0
987 0 break;
988 else {
989 char *env_ent;
990 STRLEN env_val_len;
991 /* klen < 0 means "utf8". klen == I32_MIN cannot happen because
992 * hash keys cannot be longer than I32_MAX, so -klen is safe. */
993 0 const STRLEN env_key_len = (klen < 0) ? -klen : klen;
994 0 const char *env_val = SvPV_const(valsv, env_val_len);
995  
996 0 STRLEN env_ent_len = env_key_len + env_val_len;
997 0 ▶ if (UNLIKELY(env_ent_len < env_key_len))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(env_ent_len < env_key_len)) 0 0 0
998 0 goto TheZohan;
999 0 env_ent_len += 2; /* +2 for '=' and terminating NUL byte. */
1000 0 ▶ if (UNLIKELY(env_ent_len < 2))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(env_ent_len < 2)) 0 0 0
1001 0 goto TheZohan;
1002  
1003 0 envp[n] = env_ent = (char*)safemalloc(env_ent_len);
1004 0 ▶ if (!env_ent)
Branch: 1 branch
BranchTrueFalseTotal
if (!env_ent) 0 0 0
1005 0 goto TheZohan;
1006 0 SAVEFREEPV(env_ent);
1007 0 env_ent[env_key_len] = '=';
1008 0 env_ent[env_ent_len-1] = '\0';
1009 0 Copy(env_key, env_ent, env_key_len, char);
1010 0 Copy(env_val, env_ent+env_key_len+1, env_val_len, char);
1011 }
1012 }
1013 }
1014  
1015 2 PERL_FLUSHALL_FOR_CHILD;
1016  
1017 /* These ifdefs only serve to silence dumb compilers who don't realize that
1018 * the returns at the top mean that this code is never reached. */
1019 2 ▶ if (path) {
Branch: 1 branch
BranchTrueFalseTotal
if (path) { 1 1 2
1020 # ifdef PSX2008_HAS_EXECVEAT
1021 1 execveat(fd, path, (char *const *)argv, (char *const *)envp, flags);
1022 # else
1023 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1024 # endif
1025 }
1026 else {
1027 # ifdef PSX2008_HAS_FEXECVE
1028 1 fexecve(fd, (char *const *)argv, (char *const *)envp);
1029 # else
1030 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1031 # endif
1032 }
1033 2 return;
1034  
1035 0 TheZohan:
1036 0 SETERRNO(E2BIG, SS$_BUFFEROVF);
1037 }
1038 #endif
1039  
1040 #ifndef PSX2008_HAS_PPOLL
1041 struct psx_ppollspec;
1042 #else
1043 struct psx_ppollspec {
1044 sigset_t *sigmask; /* sigmask argument for ppoll(). */
1045 struct timespec *tmo_p; /* tmo_p argument for ppoll(). */
1046 };
1047 #endif
1048  
1049 #if defined(PSX2008_HAS_POLL) || defined(PSX2008_HAS_PPOLL)
1050 static int
1051 6 _poll50c(pTHX_ SV *pollfds, int timeout, const struct psx_ppollspec *ppspec)
1052 {
1053 int rv;
1054 6 Size_t i, nfds = 0;
1055 6 AV *pollfds_av = NULL;
1056 /* Assume fds may be NULL if nfds is 0. POSIX is mute about this matter. */
1057 6 struct pollfd *fds = NULL;
1058  
1059 6 ▶ if (LIKELY(!!pollfds)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(!!pollfds)) { 6 0 6
1060 6 ▶ SvGETMAGIC(pollfds);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(pollfds); 0 6 6
SvGETMAGIC(pollfds); 0 0 0
1061 6 ▶ if (LIKELY(SvOK(pollfds))) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(SvOK(pollfds))) { 4 2 6
1062 4 ▶ if (!SvIsARRAY(pollfds)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIsARRAY(pollfds)) { 4 0 4
if (!SvIsARRAY(pollfds)) { 0 4 4
1063 0 ▶ const char *func = ppspec ? "ppoll" : "poll";
Branch: 1 branch
BranchTrueFalseTotal
const char *func = ppspec ? "ppoll" : "poll"; 0 0 0
1064 0 croak(PACKNAME "::%s: pollfds is not an ARRAY reference: %" SVf_QUOTEDPREFIX,
1065 func, SVfARG(pollfds));
1066 }
1067 4 pollfds_av = (AV*)SvRV(pollfds);
1068 4 nfds = av_count(pollfds_av);
1069 }
1070 }
1071  
1072 6 ▶ if (nfds) {
Branch: 1 branch
BranchTrueFalseTotal
if (nfds) { 2 4 6
1073 /* poll() expects nfds_t, av_count() returns Size_t, av_fetch() expects
1074 * SSize_t, so we'll accept only the smallest of these. */
1075 2 ▶ if (UNLIKELY((nfds_t)nfds != nfds || nfds > SSize_t_MAX)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY((nfds_t)nfds != nfds || nfds > SSize_t_MAX)) { 0 2 2
1076 0 SETERRNO(EINVAL, LIB_INVARG);
1077 0 return -1;
1078 }
1079 2 ▶ if (UNLIKELY((nfds*sizeof(*fds))/sizeof(*fds) != nfds)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY((nfds*sizeof(*fds))/sizeof(*fds) != nfds)) { 0 2 2
1080 0 SETERRNO(EINVAL, LIB_INVARG);
1081 0 return -1;
1082 }
1083 2 fds = (struct pollfd *)safemalloc(nfds*sizeof(*fds));
1084 2 ▶ if (!fds) {
Branch: 1 branch
BranchTrueFalseTotal
if (!fds) { 0 2 2
1085 0 SETERRNO(ENOMEM, SS$_INSFMEM);
1086 0 return -1;
1087 }
1088 2 SAVEFREEPV(fds);
1089 6 ▶ for (i = 0; i < nfds; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nfds; i++) { 4 2 6
1090 SV **pollfd;
1091 /* No-op defaults for undef and placeholders. */
1092 4 const struct pollfd initfd = {.fd=-1, .events=0, .revents=0};
1093 4 fds[i] = initfd;
1094 4 pollfd = av_fetch(pollfds_av, i, 0);
1095 4 ▶ if (!pollfd || (SvGETMAGIC(*pollfd), !SvOK(*pollfd)))
Branch: 4 branches
BranchTrueFalseTotal
if (!pollfd || (SvGETMAGIC(*pollfd), !SvOK(*pollfd))) 4 0 4
if (!pollfd || (SvGETMAGIC(*pollfd), !SvOK(*pollfd))) 0 4 4
if (!pollfd || (SvGETMAGIC(*pollfd), !SvOK(*pollfd))) 0 0 0
if (!pollfd || (SvGETMAGIC(*pollfd), !SvOK(*pollfd))) 0 4 4
1096 0 continue;
1097 4 ▶ if (!SvIsARRAY(*pollfd)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIsARRAY(*pollfd)) { 4 0 4
if (!SvIsARRAY(*pollfd)) { 0 4 4
1098 0 ▶ const char *func = ppspec ? "ppoll" : "poll";
Branch: 1 branch
BranchTrueFalseTotal
const char *func = ppspec ? "ppoll" : "poll"; 0 0 0
1099 0 croak(PACKNAME "::%s: pollfds[%" IVdf
1100 "] is not an ARRAY reference: %" SVf_QUOTEDPREFIX,
1101 func, (IV)i, SVfARG(*pollfd));
1102 }
1103 else {
1104 4 AV *pollfd_av = (AV*)SvRV(*pollfd);
1105 4 SV **pollfd_fd = av_fetch(pollfd_av, 0, 0);
1106 4 ▶ if (pollfd_fd) {
Branch: 1 branch
BranchTrueFalseTotal
if (pollfd_fd) { 4 0 4
1107 4 fds[i].fd = _psx_fileno(aTHX_ *pollfd_fd, NULL);
1108 4 ▶ if (fds[i].fd >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (fds[i].fd >= 0) { 4 0 4
1109 4 SV **pollfd_events = av_fetch(pollfd_av, 1, 0);
1110 4 ▶ if (pollfd_events)
Branch: 1 branch
BranchTrueFalseTotal
if (pollfd_events) 4 0 4
1111 4 fds[i].events = (short)(SvIV(*pollfd_events) & PERL_USHORT_MAX);
1112 }
1113 }
1114 }
1115 }
1116 }
1117  
1118 #ifndef PSX2008_HAS_PPOLL
1119 rv = poll(fds, nfds, timeout);
1120 #else
1121 6 rv = ppspec
1122 3 ? ppoll(fds, nfds, ppspec->tmo_p, ppspec->sigmask)
1123 6 ▶ : poll(fds, nfds, timeout);
Branch: 1 branch
BranchTrueFalseTotal
: poll(fds, nfds, timeout); 3 3 6
1124 #endif
1125  
1126 6 ▶ if (rv > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv > 0) { 2 4 6
1127 6 ▶ for (i = 0; i < nfds; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nfds; i++) { 4 2 6
1128 4 SV **pollfd = av_fetch(pollfds_av, i, 0);
1129 /* Paranoid safeguards against threads messing with pollfds_av. */
1130 4 ▶ if (!pollfd || (SvGETMAGIC(*pollfd), !SvIsARRAY(*pollfd)))
Branch: 6 branches
BranchTrueFalseTotal
if (!pollfd || (SvGETMAGIC(*pollfd), !SvIsARRAY(*pollfd))) 4 0 4
if (!pollfd || (SvGETMAGIC(*pollfd), !SvIsARRAY(*pollfd))) 0 4 4
if (!pollfd || (SvGETMAGIC(*pollfd), !SvIsARRAY(*pollfd))) 0 0 0
if (!pollfd || (SvGETMAGIC(*pollfd), !SvIsARRAY(*pollfd))) 4 0 4
if (!pollfd || (SvGETMAGIC(*pollfd), !SvIsARRAY(*pollfd))) 0 4 4
if (!pollfd || (SvGETMAGIC(*pollfd), !SvIsARRAY(*pollfd))) 0 4 4
1131 0 continue;
1132 else {
1133 4 AV *pollfd_av = (AV*)SvRV(*pollfd);
1134 /* Prevent sign-extension of revents to IV to avoid phantom flags. */
1135 4 SV *revents = newSViv((unsigned short)fds[i].revents);
1136 4 ▶ if (!av_store(pollfd_av, 2, revents)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!av_store(pollfd_av, 2, revents)) { 0 4 4
1137 0 ▶ if (LIKELY(SvMAGICAL(pollfd_av)))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(SvMAGICAL(pollfd_av))) 0 0 0
1138 0 mg_set(revents);
1139 0 SvREFCNT_dec_NN(revents);
1140 }
1141 }
1142 }
1143 }
1144  
1145 6 return rv;
1146 }
1147 #endif
1148  
1149 #ifdef PSX2008_HAS_READLINK
1150 static SV *
1151 2 _readlink50c(pTHX_ const char *path, const int *const dirfdp)
1152 {
1153 /*
1154 * CORE::readlink() is broken because it uses a fixed-size result buffer of
1155 * PATH_MAX bytes (the manpage explicitly advises against this). We use a
1156 * dynamically growing buffer instead, leaving it up to the file system how
1157 * long a symlink may be.
1158 */
1159 Size_t bufsize;
1160 SSize_t rv;
1161 char *buf;
1162 SV *ret_sv;
1163  
1164 /* If available, we use readlinkat() with AT_FDCWD instead of readlink() to
1165 * avoid a branch in the loop. */
1166 #ifdef PSX2008_HAS_READLINKAT
1167 /* Cast AT_FDCWD to int to cope with Solaris 0xffd19553 artwork.
1168 * https://github.com/python/cpython/issues/60169 */
1169 2 ▶ const int dirfd = dirfdp ? *dirfdp : (int)AT_FDCWD;
Branch: 1 branch
BranchTrueFalseTotal
const int dirfd = dirfdp ? *dirfdp : (int)AT_FDCWD; 1 1 2
1170 #else
1171 if (dirfdp) {
1172 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1173 return NULL;
1174 }
1175 #endif
1176  
1177 2 buf = NULL; /* Makes saferealloc() act like safemalloc() the first time. */
1178 2 for (bufsize = 255; ; bufsize = (bufsize << 1) | 1) {
1179 2 char *new_buf = (char*)saferealloc(buf, bufsize);
1180 2 ▶ if (!new_buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (!new_buf) { 0 2 2
1181 0 SETERRNO(ENOMEM, SS$_INSFMEM);
1182 0 goto FuckTheSkullOfGoogle;
1183 }
1184 2 buf = new_buf;
1185  
1186 #ifdef PSX2008_HAS_READLINKAT
1187 2 rv = readlinkat(dirfd, path, buf, bufsize);
1188 #else
1189 rv = readlink(path, buf, bufsize);
1190 #endif
1191  
1192 2 ▶ if (rv == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv == -1) { 0 2 2
1193 /* gnulib says on some systems ERANGE means bufsize is too small. The
1194 * "LIKELY" massively tightens the loop. No clue why. */
1195 0 ▶ if (LIKELY(errno != ERANGE))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(errno != ERANGE)) 0 0 0
1196 0 goto FuckTheSkullOfGoogle;
1197 }
1198 2 ▶ else if ((Size_t)rv < bufsize)
Branch: 1 branch
BranchTrueFalseTotal
else if ((Size_t)rv < bufsize) 2 0 2
1199 2 break;
1200 0 ▶ if (bufsize+1 == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (bufsize+1 == 0) 0 0 0
1201 0 goto MicrosoftMustDie;
1202 }
1203  
1204 2 buf[(Size_t)rv] = '\0';
1205 #if PERL_BCDVERSION >= 0x5035010
1206 2 ret_sv = newSV_type_mortal(SVt_PV);
1207 #else
1208 ret_sv = sv_2mortal(newSV_type(SVt_PV));
1209 #endif
1210 /* Put SvPOK_only() first to allow the compiler to merge it with
1211 * SvTEMP_on() which is the last thing newSV_type_mortal() does. */
1212 2 SvPOK_only(ret_sv);
1213 2 SvPV_set(ret_sv, buf);
1214 2 SvCUR_set(ret_sv, (Size_t)rv);
1215 2 SvLEN_set(ret_sv, bufsize);
1216 2 ▶ SvTAINTED_on(ret_sv);
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(ret_sv); 0 2 2
1217 2 return ret_sv;
1218  
1219 0 MicrosoftMustDie:
1220 0 SETERRNO(ENAMETOOLONG, RMS$_SYN);
1221 0 FuckTheSkullOfGoogle:
1222 0 Safefree(buf);
1223 0 return NULL;
1224 }
1225 #endif
1226  
1227 #if defined(PSX2008_HAS_READV) || defined(PSX2008_HAS_PREADV) \
1228 || defined(PSX2008_HAS_PREADV2)
1229 static void
1230 2 _free_iov(pTHX_ struct iovec *iov, Size_t cnt) {
1231 2 ▶ if (iov) {
Branch: 1 branch
BranchTrueFalseTotal
if (iov) { 2 0 2
1232 Size_t i;
1233 2 const struct iovec zero_iovec = {0};
1234 7 ▶ for (i = 0; i < cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { 5 2 7
1235 5 Safefree(iov[i].iov_base);
1236 5 iov[i] = zero_iovec;
1237 }
1238 }
1239 2 }
1240  
1241 /* We only use this function for an undef value. Non-undefs need special
1242 * treatment (see prepare_SV_for_RV() in sv.h). */
1243 void
1244 1 _upgrade_undef_sv2av(pTHX_ SV *sv)
1245 {
1246 1 ▶ ASSUME(!SvOK(sv));
Branch: 1 branch
BranchTrueFalseTotal
ASSUME(!SvOK(sv)); 0 1 1
1247  
1248 #if PERL_BCDVERSION >= 0x5035004
1249 1 sv_setrv_noinc(sv, (SV*)newAV());
1250 #else
1251 /* Since Perl 5.12 (5.11.0 to be precise), references are SVt_IV (and SVt_RV
1252 * is just an alias), but before that, SVt_RV was a separate type and
1253 * DEBUGGING perl whines 'Assertion ((svtype)((sv)->sv_flags & 0xff)) >=
1254 * SVt_RV failed.' */
1255 # if PERL_BCDVERSION >= 0x5011000
1256 sv_upgrade(sv, SVt_IV);
1257 # else
1258 sv_upgrade(sv, SVt_RV);
1259 # endif
1260 SvOK_off(sv);
1261 SvRV_set(sv, (SV*)newAV());
1262 SvROK_on(sv);
1263 #endif
1264 1 }
1265  
1266 static SSize_t
1267 8 _readv50c(pTHX_ int fd, SV *buffers, AV *sizes, SV *offset_sv, SV *flags_sv)
1268 {
1269 SSize_t rv;
1270 Size_t i, iovcnt;
1271 struct iovec *iov;
1272 8 ▶ const char *func = flags_sv ? "preadv2" : offset_sv ? "preadv" : "readv";
Branch: 2 branches
BranchTrueFalseTotal
const char *func = flags_sv ? "preadv2" : offset_sv ? "preadv" : "readv"; 8 0 8
const char *func = flags_sv ? "preadv2" : offset_sv ? "preadv" : "readv"; 3 5 8
1273  
1274 /* The prototype for buffers is \[@$] so that we can be called either with
1275 * @buffers or $buffers. @buffers gives us an array reference. $buffers
1276 * gives us a reference to a scalar (which in turn is hopefully an array
1277 * reference). In the latter case we need to resolve the argument twice to
1278 * get the array. */
1279 11 ▶ for (i = 0; i < 2; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 2; i++) { 11 0 11
1280 11 ▶ if (SvROK(buffers)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(buffers)) { 10 1 11
1281 10 buffers = SvRV(buffers);
1282 10 ▶ if (SvTRULYREADONLY(buffers))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRULYREADONLY(buffers)) 0 10 10
1283 0 croak(PACKNAME "::%s: Can't modify read-only buffers", func);
1284 10 ▶ if (SvTYPE(buffers) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(buffers) == SVt_PVAV) 6 4 10
1285 6 break;
1286 4 ▶ if (i == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i == 0) { 3 1 4
1287 3 ▶ if (!SvOK(buffers)) /* Make plain "my $buf" an array ref. */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(buffers)) /* Make plain "my $buf" an array ref. */ 1 2 3
1288 1 _upgrade_undef_sv2av(aTHX_ buffers);
1289 3 continue;
1290 }
1291 }
1292 2 croak(PACKNAME "::%s: buffers is not an array or array ref", func);
1293 }
1294  
1295 /* av_count() returns a Size_t but readv()'s iovcnt is an int so we check
1296 * for overflow. */
1297 6 iovcnt = av_count(sizes);
1298 6 ▶ if (iovcnt > PERL_INT_MAX || (iovcnt*sizeof(*iov))/sizeof(*iov) != iovcnt)
Branch: 2 branches
BranchTrueFalseTotal
if (iovcnt > PERL_INT_MAX || (iovcnt*sizeof(*iov))/sizeof(*iov) != iovcnt) 6 0 6
if (iovcnt > PERL_INT_MAX || (iovcnt*sizeof(*iov))/sizeof(*iov) != iovcnt) 0 6 6
1299 0 goto failEINVAL;
1300  
1301 6 iov = (struct iovec *)safecalloc(iovcnt, sizeof(*iov));
1302 6 ▶ if (iov)
Branch: 1 branch
BranchTrueFalseTotal
if (iov) 6 0 6
1303 6 SAVEFREEPV(iov);
1304 0 ▶ else if (iovcnt)
Branch: 1 branch
BranchTrueFalseTotal
else if (iovcnt) 0 0 0
1305 0 goto failENOMEM;
1306  
1307 27 ▶ for (i = 0; i < iovcnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < iovcnt; i++) { 22 5 27
1308 Size_t iov_len;
1309 void *iov_base;
1310 22 SV **size = av_fetch(sizes, i, 0);
1311 22 ▶ if (!size)
Branch: 1 branch
BranchTrueFalseTotal
if (!size) 0 22 22
1312 0 continue;
1313 22 ▶ if (UNLIKELY(SvIsNEGATIVE(*size))) { /* Performs 'get' magic. */
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(SvIsNEGATIVE(*size))) { /* Performs 'get' magic. */ 1 21 22
1314 1 _free_iov(aTHX_ iov, i);
1315 1 croak(PACKNAME "::%s: Negative count: sizes[%" PSX2008_SZuf
1316 "] = %" SVf_QUOTEDPREFIX,
1317 func, (PSX2008_SZuft)i, SVfARG(*size));
1318 }
1319 21 iov_len = SvSTRLEN(*size);
1320 21 ▶ if (!iov_len)
Branch: 1 branch
BranchTrueFalseTotal
if (!iov_len) 11 10 21
1321 11 continue;
1322 10 ▶ if (iov_len > SSize_t_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (iov_len > SSize_t_MAX) { 0 10 10
1323 0 _free_iov(aTHX_ iov, i);
1324 0 goto failEINVAL;
1325 }
1326 10 ▶ iov_base = safemalloc(TopUpLEN(iov_len));
Branch: 2 branches
BranchTrueFalseTotal
iov_base = safemalloc(TopUpLEN(iov_len)); 0 10 10
iov_base = safemalloc(TopUpLEN(iov_len)); 0 10 10
1327 10 ▶ if (!iov_base) {
Branch: 1 branch
BranchTrueFalseTotal
if (!iov_base) { 0 10 10
1328 0 _free_iov(aTHX_ iov, i);
1329 0 goto failENOMEM;
1330 }
1331 10 iov[i].iov_base = iov_base;
1332 10 iov[i].iov_len = iov_len;
1333 }
1334  
1335 5 ▶ if (!offset_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!offset_sv) { 2 3 5
1336 #ifdef PSX2008_HAS_READV
1337 2 rv = readv(fd, iov, (int)iovcnt);
1338 #else
1339 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1340 rv = -1;
1341 #endif
1342 }
1343 3 ▶ else if (!flags_sv) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!flags_sv) { 3 0 3
1344 #ifdef PSX2008_HAS_PREADV
1345 3 ▶ Off_t offset = SvIsUNDEF_onpurpose(offset_sv) ? 0 : SvOFFt(offset_sv);
Branch: 2 branches
BranchTrueFalseTotal
Off_t offset = SvIsUNDEF_onpurpose(offset_sv) ? 0 : SvOFFt(offset_sv); 3 0 3
Off_t offset = SvIsUNDEF_onpurpose(offset_sv) ? 0 : SvOFFt(offset_sv); 3 0 3
1346 3 rv = preadv(fd, iov, (int)iovcnt, offset);
1347 #else
1348 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1349 rv = -1;
1350 #endif
1351 }
1352 else {
1353 #ifdef PSX2008_HAS_PREADV2
1354 0 ▶ Off_t offset = SvIsUNDEF_onpurpose(offset_sv) ? 0 : SvOFFt(offset_sv);
Branch: 2 branches
BranchTrueFalseTotal
Off_t offset = SvIsUNDEF_onpurpose(offset_sv) ? 0 : SvOFFt(offset_sv); 0 0 0
Off_t offset = SvIsUNDEF_onpurpose(offset_sv) ? 0 : SvOFFt(offset_sv); 0 0 0
1355 0 ▶ int flags = SvIsUNDEF_onpurpose(flags_sv) ? 0 : (int)SvIV(flags_sv);
Branch: 2 branches
BranchTrueFalseTotal
int flags = SvIsUNDEF_onpurpose(flags_sv) ? 0 : (int)SvIV(flags_sv); 0 0 0
int flags = SvIsUNDEF_onpurpose(flags_sv) ? 0 : (int)SvIV(flags_sv); 0 0 0
1356 0 rv = preadv2(fd, iov, (int)iovcnt, offset, flags);
1357 #else
1358 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1359 rv = -1;
1360 #endif
1361 }
1362  
1363 5 ▶ if (rv < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv < 0) { 1 4 5
1364 1 _free_iov(aTHX_ iov, iovcnt);
1365 1 return rv;
1366 }
1367  
1368 4 av_extend((AV*)buffers, iovcnt);
1369  
1370 {
1371 SV *tmp_sv;
1372 4 Size_t pv_len, bytes_left = rv;
1373 20 ▶ for (i = 0; i < iovcnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < iovcnt; i++) { 16 4 20
1374 16 const Size_t iov_len = iov[i].iov_len;
1375 16 ▶ if (bytes_left >= iov_len)
Branch: 1 branch
BranchTrueFalseTotal
if (bytes_left >= iov_len) 16 0 16
1376 /* Current buffer filled completely (this includes an empty buffer). */
1377 16 pv_len = iov_len;
1378 else
1379 /* Current buffer filled partly. */
1380 0 pv_len = bytes_left;
1381 16 bytes_left -= pv_len;
1382  
1383 16 tmp_sv = newSV_type(SVt_PV);
1384 16 ▶ if (!tmp_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!tmp_sv) { 0 16 16
1385 0 _free_iov(aTHX_ iov + i, iovcnt - i);
1386 0 goto failENOMEM;
1387 }
1388  
1389 16 ▶ if (pv_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (pv_len) { 8 8 16
1390 8 char *iov_base = (char*)iov[i].iov_base;
1391 8 iov_base[pv_len] = '\0';
1392 8 SvPV_set(tmp_sv, iov_base);
1393 8 SvCUR_set(tmp_sv, pv_len);
1394 8 ▶ ASSUME(iov_len <= SSize_t_MAX);
Branch: 1 branch
BranchTrueFalseTotal
ASSUME(iov_len <= SSize_t_MAX); 0 8 8
1395 /* We allocated TopUpLEN(iov_len) bytes. */
1396 8 ▶ SvLEN_set(tmp_sv, TopUpLEN(iov_len));
Branch: 2 branches
BranchTrueFalseTotal
SvLEN_set(tmp_sv, TopUpLEN(iov_len)); 0 8 8
SvLEN_set(tmp_sv, TopUpLEN(iov_len)); 0 8 8
1397 }
1398 else {
1399 8 SvPV_set(tmp_sv, (char*)"");
1400 8 SvCUR_set(tmp_sv, 0);
1401 8 SvLEN_set(tmp_sv, 0); /* So PV won't get freed. */
1402 }
1403 16 SvPOK_only(tmp_sv);
1404 16 ▶ SvTAINTED_on(tmp_sv);
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(tmp_sv); 0 16 16
1405  
1406 16 ▶ if (!av_store((AV*)buffers, i, tmp_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!av_store((AV*)buffers, i, tmp_sv)) { 0 16 16
1407 0 ▶ if (LIKELY(SvMAGICAL(buffers)))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(SvMAGICAL(buffers))) 0 0 0
1408 0 mg_set(tmp_sv);
1409 0 SvREFCNT_dec_NN(tmp_sv);
1410 }
1411 }
1412 }
1413  
1414 4 return rv;
1415  
1416 0 failEINVAL:
1417 0 SETERRNO(EINVAL, LIB_INVARG);
1418 0 return -1;
1419 0 failENOMEM:
1420 0 SETERRNO(ENOMEM, SS$_INSFMEM);
1421 0 return -1;
1422 }
1423 #endif
1424  
1425 #ifdef PSX2008_HAS_WRITEV
1426 static int
1427 12 _psx_av2iov(pTHX_ AV *buffers, struct iovec **iov_dest)
1428 {
1429 Size_t i;
1430 struct iovec *iov;
1431  
1432 12 const Size_t iovcnt = av_count(buffers);
1433 /* av_count() returns a Size_t but writev()'s iovcnt is an int so we check
1434 * for overflow. */
1435 12 ▶ if (iovcnt > PERL_INT_MAX || (iovcnt*sizeof(*iov))/sizeof(*iov) != iovcnt) {
Branch: 2 branches
BranchTrueFalseTotal
if (iovcnt > PERL_INT_MAX || (iovcnt*sizeof(*iov))/sizeof(*iov) != iovcnt) { 12 0 12
if (iovcnt > PERL_INT_MAX || (iovcnt*sizeof(*iov))/sizeof(*iov) != iovcnt) { 0 12 12
1436 0 SETERRNO(EINVAL, LIB_INVARG);
1437 0 return -1;
1438 }
1439  
1440 12 *iov_dest = iov = (struct iovec *)safecalloc(iovcnt, sizeof(*iov));
1441 12 ▶ if (iov)
Branch: 1 branch
BranchTrueFalseTotal
if (iov) 12 0 12
1442 12 SAVEFREEPV(iov);
1443 0 ▶ else if (iovcnt) {
Branch: 1 branch
BranchTrueFalseTotal
else if (iovcnt) { 0 0 0
1444 0 SETERRNO(ENOMEM, SS$_INSFMEM);
1445 0 return -1;
1446 }
1447  
1448 43 ▶ for (i = 0; i < iovcnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < iovcnt; i++) { 36 7 43
1449 char *iov_base;
1450 Size_t iov_len;
1451 36 SV **av_elt = av_fetch(buffers, i, 0);
1452 36 ▶ if (!av_elt)
Branch: 1 branch
BranchTrueFalseTotal
if (!av_elt) 0 36 36
1453 0 continue;
1454 36 ▶ SvGETMAGIC(*av_elt);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(*av_elt); 0 36 36
SvGETMAGIC(*av_elt); 0 0 0
1455 36 ▶ if (!SvIsARRAY(*av_elt))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIsARRAY(*av_elt)) 12 24 36
if (!SvIsARRAY(*av_elt)) 0 12 12
1456 48 iov_base = SvPV(*av_elt, iov_len);
1457 else {
1458 SV **buf_pv, **buf_offset, **buf_len;
1459 12 AV *buf_av = (AV*)SvRV(*av_elt);
1460 12 const SSize_t buf_av_fill = AvFILL(buf_av);
1461  
1462 12 buf_pv = av_fetch(buf_av, 0, 0);
1463 12 ▶ if (!buf_pv)
Branch: 1 branch
BranchTrueFalseTotal
if (!buf_pv) 0 12 12
1464 0 continue;
1465 12 iov_base = SvPV(*buf_pv, iov_len);
1466  
1467 12 ▶ buf_offset = buf_av_fill > 0 ? av_fetch(buf_av, 1, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
buf_offset = buf_av_fill > 0 ? av_fetch(buf_av, 1, 0) : NULL; 12 0 12
1468 12 ▶ if (buf_offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (buf_offset) { 12 0 12
1469 /* Make neg 0 or SIZE_MAX (SvIsNEGATIVE is 0 or 1). */
1470 12 const STRLEN neg = ~(STRLEN)SvIsNEGATIVE(*buf_offset) + 1;
1471 12 STRLEN offset = SvSTRLEN(*buf_offset);
1472 12 offset += neg & iov_len; /* Handle negative offset w/o a branch. */
1473 12 ▶ if (offset <= iov_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (offset <= iov_len) { 7 5 12
1474 7 iov_len -= offset;
1475 7 iov_base += offset;
1476 }
1477 else
1478 5 croak("Offset %" SVf_QUOTEDPREFIX " outside string in "
1479 "buffers[%" PSX2008_SZuf "]", SVfARG(*buf_offset),
1480 (PSX2008_SZuft)i);
1481 }
1482  
1483 /* av_fetch() always returns non-NULL for magical arrays even if the
1484 * index is outside the array. That's why we have to check buf_av_fill,
1485 * or iov_len drops to zero if buf_len is omitted. */
1486 7 ▶ buf_len = buf_av_fill > 1 ? av_fetch(buf_av, 2, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
buf_len = buf_av_fill > 1 ? av_fetch(buf_av, 2, 0) : NULL; 0 7 7
1487 7 ▶ if (buf_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (buf_len) { 0 7 7
1488 0 ▶ if (!SvIsNEGATIVE(*buf_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvIsNEGATIVE(*buf_len)) { 0 0 0
1489 0 const STRLEN b_len = SvSTRLEN(*buf_len);
1490 0 iov_len = (b_len < iov_len) ? b_len : iov_len;
1491 }
1492 else
1493 0 croak("Negative length %" SVf_QUOTEDPREFIX " in "
1494 "buffers[%" PSX2008_SZuf "]", SVfARG(*buf_len),
1495 (PSX2008_SZuft)i);
1496 }
1497 }
1498  
1499 31 iov[i].iov_base = iov_base;
1500 31 iov[i].iov_len = iov_len;
1501 }
1502  
1503 7 return (int)iovcnt;
1504 }
1505 #endif
1506  
1507 #if defined(PSX2008_HAS_OPENAT) || defined(PSX2008_HAS_POSIX_OPENPT)
1508 /* Convert open() flags to POSIX "r", "a", "w" mode string. */
1509 static const char *
1510 3 _flags2raw(int flags)
1511 {
1512 3 int accmode = flags & O_ACCMODE;
1513 3 ▶ if (accmode == O_RDONLY)
Branch: 1 branch
BranchTrueFalseTotal
if (accmode == O_RDONLY) 0 3 3
1514 0 return "rb";
1515 #ifdef O_APPEND
1516 3 ▶ if (flags & O_APPEND)
Branch: 1 branch
BranchTrueFalseTotal
if (flags & O_APPEND) 0 3 3
1517 0 ▶ return (accmode == O_WRONLY) ? "ab" : "a+b";
Branch: 1 branch
BranchTrueFalseTotal
return (accmode == O_WRONLY) ? "ab" : "a+b"; 0 0 0
1518 #endif
1519 3 ▶ if (accmode == O_WRONLY)
Branch: 1 branch
BranchTrueFalseTotal
if (accmode == O_WRONLY) 0 3 3
1520 0 return "wb";
1521 3 ▶ if (accmode == O_RDWR)
Branch: 1 branch
BranchTrueFalseTotal
if (accmode == O_RDWR) 3 0 3
1522 3 return "r+b";
1523 0 return "";
1524 }
1525 #endif
1526  
1527 #if defined(PSX2008_HAS_FDOPEN) || defined(PSX2008_HAS_FDOPENDIR)
1528 static SV *
1529 4 _psx_fd_to_handle(pTHX_ int fd, const char *mode)
1530 {
1531 GV *gv;
1532 4 SV *rv = NULL;
1533 4 bool return_handle = FALSE;
1534  
1535 4 gv = newGVgen(PACKNAME);
1536 4 ▶ if (gv) {
Branch: 1 branch
BranchTrueFalseTotal
if (gv) { 4 0 4
1537 4 ▶ if (mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (mode) { 3 1 4
1538 # ifdef PSX2008_HAS_FDOPEN
1539 3 FILE *filep = fdopen(fd, mode);
1540 3 ▶ if (filep) {
Branch: 1 branch
BranchTrueFalseTotal
if (filep) { 3 0 3
1541 /* Should PerlIO_importFILE() fail, we have a nice little memory leak
1542 * since calling fclose() might irritate the caller. */
1543 3 PerlIO *pio = PerlIO_importFILE(filep, mode);
1544 3 ▶ if (pio) {
Branch: 1 branch
BranchTrueFalseTotal
if (pio) { 3 0 3
1545 3 ▶ if (do_open(gv, "+<&", 3, FALSE, 0, 0, pio))
Branch: 1 branch
BranchTrueFalseTotal
if (do_open(gv, "+<&", 3, FALSE, 0, 0, pio)) 3 0 3
1546 3 return_handle = TRUE;
1547 else
1548 0 PerlIO_releaseFILE(pio, filep);
1549 }
1550 }
1551 # else
1552 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1553 # endif
1554 }
1555 else {
1556 # ifdef PSX2008_HAS_FDOPENDIR
1557 1 DIR *dirp = fdopendir(fd);
1558 1 ▶ if (dirp) {
Branch: 1 branch
BranchTrueFalseTotal
if (dirp) { 1 0 1
1559 1 ▶ IO *io = GvIOn(gv);
Branch: 5 branches
BranchTrueFalseTotal
IO *io = GvIOn(gv); 1 0 1
IO *io = GvIOn(gv); 0 1 1
IO *io = GvIOn(gv); 0 0 0
IO *io = GvIOn(gv); 1 0 1
IO *io = GvIOn(gv); 0 1 1
1560 1 IoDIRP(io) = dirp;
1561 1 return_handle = TRUE;
1562 }
1563 # else
1564 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1565 # endif
1566 }
1567 }
1568  
1569 4 ▶ if (return_handle) {
Branch: 1 branch
BranchTrueFalseTotal
if (return_handle) { 4 0 4
1570 4 ▶ const char *io_class = mode ? "IO::File" : "IO::Dir";
Branch: 1 branch
BranchTrueFalseTotal
const char *io_class = mode ? "IO::File" : "IO::Dir"; 3 1 4
1571 4 HV *io_stash = gv_stashpv(io_class, 0);
1572 4 rv = sv_bless(sv_2mortal(newRV_inc((SV*)gv)), io_stash);
1573 }
1574  
1575 /* https://github.com/Perl/perl5/issues/9493 */
1576 4 ▶ if (gv)
Branch: 1 branch
BranchTrueFalseTotal
if (gv) 4 0 4
1577 4 (void) hv_delete(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), G_DISCARD);
1578  
1579 4 return rv;
1580 }
1581 #endif
1582  
1583 #ifdef PSX2008_HAS_CLOSE
1584 static int
1585 0 _psx_close(pTHX_ SV *sv)
1586 {
1587 IO *io;
1588 0 int rv = -1;
1589  
1590 0 ▶ SvGETMAGIC(sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sv); 0 0 0
SvGETMAGIC(sv); 0 0 0
1591 0 ▶ if (!SvOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(sv)) 0 0 0
1592 0 SETERRNO(EBADF, RMS_IFI);
1593 0 ▶ else if (_psx_looks_like_number(aTHX_ sv))
Branch: 1 branch
BranchTrueFalseTotal
else if (_psx_looks_like_number(aTHX_ sv)) 0 0 0
1594 0 rv = close((int)SvIV(sv));
1595 0 ▶ else if ((io = sv_2io(sv))) {
Branch: 1 branch
BranchTrueFalseTotal
else if ((io = sv_2io(sv))) { 0 0 0
1596 0 ▶ if (IoIFP(io))
Branch: 1 branch
BranchTrueFalseTotal
if (IoIFP(io)) 0 0 0
1597 0 rv = PerlIO_close(IoIFP(io));
1598 0 ▶ else if (IoDIRP(io)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (IoDIRP(io)) { 0 0 0
1599 #ifdef VOID_CLOSEDIR
1600 SETERRNO(0, 0);
1601 PerlDir_close(IoDIRP(io));
1602 rv = errno ? -1 : 0;
1603 #else
1604 0 rv = PerlDir_close(IoDIRP(io));
1605 #endif
1606 0 IoDIRP(io) = 0;
1607 }
1608 else
1609 0 SETERRNO(EBADF, RMS_IFI);
1610 }
1611 else
1612 0 SETERRNO(EBADF, RMS_IFI);
1613  
1614 0 return rv;
1615 }
1616 #endif
1617  
1618 #ifdef PSX2008_HAS_OPENAT
1619 static SV *
1620 8 _openat50c(pTHX_ SV *dirfdsv,
1621 const char *path, int flags, mode_t mode, HV *how_hv)
1622 {
1623 8 int dir_fd, path_fd, got_fd = 0;
1624  
1625 #ifndef PSX2008_HAS_OPENAT2
1626 if (how_hv) {
1627 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
1628 return NULL;
1629 }
1630 #endif
1631  
1632 8 ▶ SvGETMAGIC(dirfdsv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(dirfdsv); 0 8 8
SvGETMAGIC(dirfdsv); 0 0 0
1633 8 ▶ if (!SvOK(dirfdsv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(dirfdsv)) 1 7 8
1634 1 dir_fd = -1;
1635 7 ▶ else if (SvROK(dirfdsv) && SvTYPE(SvRV(dirfdsv)) <= SVt_PVMG)
Branch: 2 branches
BranchTrueFalseTotal
else if (SvROK(dirfdsv) && SvTYPE(SvRV(dirfdsv)) <= SVt_PVMG) 4 3 7
else if (SvROK(dirfdsv) && SvTYPE(SvRV(dirfdsv)) <= SVt_PVMG) 1 3 4
1636 /* Allow dirfdsv to be a reference to a scalar holding AT_FDCWD (IV/NV/PV)
1637 * to get a file handle instead of a file descriptor. */
1638 1 ▶ dir_fd = (SvIV(SvRV(dirfdsv)) == (IV)AT_FDCWD) ? (int)AT_FDCWD : -1;
Branch: 1 branch
BranchTrueFalseTotal
dir_fd = (SvIV(SvRV(dirfdsv)) == (IV)AT_FDCWD) ? (int)AT_FDCWD : -1; 1 0 1
1639 else
1640 6 dir_fd = _psx_fileno_nomg(aTHX_ dirfdsv, &got_fd);
1641  
1642 7 ▶ if (dir_fd == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (dir_fd == -1) { 1 6 7
1643 1 SETERRNO(EBADF, RMS_IFI);
1644 1 path_fd = -1;
1645 }
1646 6 ▶ else if (!how_hv) { /* openat() */
Branch: 1 branch
BranchTrueFalseTotal
else if (!how_hv) { /* openat() */ 6 0 6
1647 6 path_fd = openat(dir_fd, path, flags, mode);
1648 }
1649 #ifdef PSX2008_HAS_OPENAT2
1650 /* openat2() */
1651 else {
1652 0 SV** how_flags = hv_fetchs(how_hv, "flags", 0);
1653 0 SV** how_mode = hv_fetchs(how_hv, "mode", 0);
1654 0 SV** how_resolve = hv_fetchs(how_hv, "resolve", 0);
1655 0 struct open_how how = {
1656 0 ▶ .flags = how_flags ? SvUV(*how_flags) : 0,
Branch: 1 branch
BranchTrueFalseTotal
.flags = how_flags ? SvUV(*how_flags) : 0, 0 0 0
1657 0 ▶ .mode = how_mode ? SvUV(*how_mode) : 0,
Branch: 1 branch
BranchTrueFalseTotal
.mode = how_mode ? SvUV(*how_mode) : 0, 0 0 0
1658 0 ▶ .resolve = how_resolve ? SvUV(*how_resolve) : 0
Branch: 1 branch
BranchTrueFalseTotal
.resolve = how_resolve ? SvUV(*how_resolve) : 0 0 0 0
1659 };
1660 0 flags = (int)how.flags; /* flags needed for _psx_fd_to_handle() below. */
1661 0 path_fd = (int)syscall(SYS_openat2, dir_fd, path, &how, sizeof(how));
1662 }
1663 #endif
1664  
1665 7 ▶ if (path_fd < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (path_fd < 0) 1 6 7
1666 1 return NULL;
1667 6 ▶ else if (got_fd)
Branch: 1 branch
BranchTrueFalseTotal
else if (got_fd) 2 4 6
1668 /* If we were passed a file descriptor, return a file descriptor. */
1669 2 return sv_2mortal(newSViv((IV)path_fd));
1670 else {
1671 struct stat st;
1672 4 ▶ if (fstat(path_fd, &st) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (fstat(path_fd, &st) != 0) 0 4 4
1673 0 return NULL;
1674 else {
1675 4 ▶ const char *raw = S_ISDIR(st.st_mode) ? NULL : _flags2raw(flags);
Branch: 1 branch
BranchTrueFalseTotal
const char *raw = S_ISDIR(st.st_mode) ? NULL : _flags2raw(flags); 3 1 4
1676 4 return _psx_fd_to_handle(aTHX_ path_fd, raw);
1677 }
1678 }
1679 }
1680  
1681 #endif
1682  
1683 /* Macro for isalnum, isdigit, etc.
1684 * Contains the fix for https://github.com/Perl/perl5/issues/11148 which was
1685 * "solved" by them Perl guys by cowardly removing the functions from POSIX.
1686 */
1687 #define ISFUNC(isfunc) { \
1688 STRLEN len; \
1689 const unsigned char *s = (unsigned char *) SvPVbyte(charstring, len); \
1690 const unsigned char *e = s + len; \
1691 for (RETVAL = len ? 1 : 0; RETVAL && s < e; s++) \
1692 if (!isfunc(*s)) \
1693 RETVAL = 0; \
1694 }
1695  
1696 MODULE = POSIX::2008 PACKAGE = POSIX::2008
1697  
1698 PROTOTYPES: ENABLE
1699  
1700 INCLUDE: const-xs.inc
1701  
1702 BOOT:
1703 {
1704 }
1705  
1706 ## DESTROY is called when a file handle we created (e.g. in openat)
1707 ## is cleaned up. This is just a dummy to silence AUTOLOAD. We leave
1708 ## it up to Perl to take the necessary steps.
1709 void
1710 DESTROY(...);
1711 PPCODE:
1712  
1713 #ifdef PSX2008_HAS_ABORT
1714 void
1715 abort();
1716 PPCODE:
1717 /* Using PPCODE instead of an empty body avoids the (unnecessary)
1718 * XSRETURN_EMPTY epilog and saves quite a few bytes. */
1719 0 abort();
1720  
1721 #endif
1722  
1723 #ifdef PSX2008_HAS_SYNC
1724 void
1725 sync();
1726 PPCODE:
1727 0 sync();
1728  
1729 #endif
1730  
1731 #ifdef PSX2008_HAS_A64L
1732 long
1733 a64l(char *s);
1734  
1735 #endif
1736  
1737 #ifdef PSX2008_HAS_L64A
1738 char *
1739 l64a(long value);
1740  
1741 #endif
1742  
1743 #ifdef PSX2008_HAS_ALARM
1744 UV
1745 alarm(unsigned seconds);
1746  
1747 #endif
1748  
1749 #ifdef PSX2008_HAS_ATOF
1750 NV
1751 atof(const char *str);
1752  
1753 #endif
1754  
1755 #ifdef PSX2008_ATOI
1756 IV
1757 atoi(const char *str);
1758 CODE:
1759 0 ▶ RETVAL = PSX2008_ATOI(str);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PSX2008_ATOI(str); 0 0 0
1760 OUTPUT:
1761 RETVAL
1762  
1763 #endif
1764  
1765 #ifdef PSX2008_HAS_BASENAME
1766 void
1767 basename(SV *path);
1768 ALIAS:
1769 dirname = 1
1770 PPCODE:
1771 {
1772 SV *retval;
1773 STRLEN svpv_len;
1774 0 const char *cpath = SvPV_const(path, svpv_len);
1775 0 const STRLEN len = svpv_len;
1776 0 ▶ ASSUME(!!cpath);
Branch: 1 branch
BranchTrueFalseTotal
ASSUME(!!cpath); 0 0 0
1777 0 ▶ if (!IS_SAFE_PATHNAME(cpath, len, cv))
Branch: 3 branches
BranchTrueFalseTotal
if (!IS_SAFE_PATHNAME(cpath, len, cv)) 0 0 0
if (!IS_SAFE_PATHNAME(cpath, len, cv)) 0 0 0
if (!IS_SAFE_PATHNAME(cpath, len, cv)) 0 0 0
1778 0 retval = &PL_sv_undef;
1779 0 ▶ else if (!len)
Branch: 1 branch
BranchTrueFalseTotal
else if (!len) 0 0 0
1780 0 retval = newSVpvs_flags(".", SVs_TEMP);
1781 else {
1782 char *name;
1783 0 char *cpathcopy = savepvn(cpath, len);
1784 0 SAVEFREEPV(cpathcopy);
1785 0 ▶ name = (ix == 0) ? basename(cpathcopy) : dirname(cpathcopy);
Branch: 1 branch
BranchTrueFalseTotal
name = (ix == 0) ? basename(cpathcopy) : dirname(cpathcopy); 0 0 0
1786 0 ▶ if (!name)
Branch: 1 branch
BranchTrueFalseTotal
if (!name) 0 0 0
1787 0 retval = &PL_sv_undef;
1788 else {
1789 0 Size_t namelen = _strnlen(name, len);
1790 0 retval = newSVpvn_flags(name, namelen, SvUTF8(path) | SVs_TEMP);
1791 }
1792 }
1793 0 PUSHs(retval);
1794 }
1795  
1796 #endif
1797  
1798 #ifdef PSX2008_HAS_CATCLOSE
1799 SysRetTrue
1800 catclose(nl_catd catd);
1801  
1802 #endif
1803  
1804 #ifdef PSX2008_HAS_CATGETS
1805 char *
1806 catgets(nl_catd catd, int set_id, int msg_id, const char *dflt);
1807  
1808 #endif
1809  
1810 #ifdef PSX2008_HAS_CATOPEN
1811 void
1812 catopen(psx_safepath_t__fail_undef name, int flag);
1813 PPCODE:
1814 {
1815 0 nl_catd rv = catopen(name, flag);
1816 0 ▶ if (rv == (nl_catd)-1)
Branch: 1 branch
BranchTrueFalseTotal
if (rv == (nl_catd)-1) 0 0 0
1817 0 PUSHs(&PL_sv_undef);
1818 else
1819 0 mPUSHs(newSViv(PTR2IV(rv)));
1820 }
1821  
1822 #endif
1823  
1824 #ifdef PSX2008_HAS_CLOCK
1825 clock_t
1826 clock();
1827  
1828 #endif
1829  
1830 #ifdef PSX2008_HAS_CLOCK_GETCPUCLOCKID
1831 void
1832 clock_getcpuclockid(pid_t pid=0);
1833 PPCODE:
1834 {
1835 clockid_t clock_id;
1836 0 int rv = clock_getcpuclockid(pid, &clock_id);
1837 0 ▶ if (LIKELY(rv == 0))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(rv == 0)) 0 0 0
1838 0 ▶ PUSH_INT_OR_PV(clock_id);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(clock_id); 0 0 0
PUSH_INT_OR_PV(clock_id); 0 0 0
1839 else {
1840 0 SETERRNO(rv, rv);
1841 0 PUSHs(&PL_sv_undef);
1842 }
1843 }
1844  
1845 #endif
1846  
1847 #define PUSH_TIMESPEC(tspec, sp_ext) STMT_START { \
1848 switch (GIMME_V) { \
1849 case G_SCALAR: { \
1850 NV nv_sec = (NV)tspec.tv_sec + (NV)tspec.tv_nsec/1e9; \
1851 mPUSHs(newSVnv(nv_sec)); \
1852 break; \
1853 } \
1854 case G_LIST: \
1855 if (sp_ext) \
1856 EXTEND(SP, 1); \
1857 mPUSHs(newSViv(tspec.tv_sec)); \
1858 mPUSHs(newSViv(tspec.tv_nsec)); \
1859 break; \
1860 } \
1861 } STMT_END
1862  
1863 #ifdef PSX2008_HAS_CLOCK_GETRES
1864 void
1865 clock_getres(clockid_t clock_id=CLOCK_REALTIME);
1866 ALIAS:
1867 clock_gettime = 1
1868 PPCODE:
1869 {
1870 struct timespec res;
1871 0 int rv = (ix == 0)
1872 0 ? clock_getres(clock_id, &res)
1873 0 ▶ : clock_gettime(clock_id, &res);
Branch: 1 branch
BranchTrueFalseTotal
: clock_gettime(clock_id, &res); 0 0 0
1874 0 ▶ if (rv == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rv == 0) 0 0 0
1875 0 ▶ PUSH_TIMESPEC(res, 1);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_TIMESPEC(res, 1); 0 0 0
1876 }
1877  
1878 #endif
1879  
1880 #define LOOKS_LIKE_NV(sv) \
1881 ( \
1882 LIKELY(SvOK(sv)) && !SvIOK(sv) && \
1883 ( \
1884 SvNOK(sv) || \
1885 ( \
1886 (SvPOK(sv) || SvPOKp(sv)) \
1887 && (grok_number(SvPVX_const(sv), SvCUR(sv), NULL) & IS_NUMBER_NOT_INT) \
1888 ) \
1889 ) \
1890 )
1891  
1892 #if defined(Perl_isfinite) /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113959 */
1893 # define _psx_isnaninf(nv) (!Perl_isfinite(nv))
1894 #elif defined(Perl_isnan) && defined(Perl_isinf)
1895 # define _psx_isnaninf(nv) (Perl_isnan(nv) || Perl_isinf(nv))
1896 #else
1897 # define _psx_isnaninf(nv) ((nv)!=(nv) || ((nv) != 0.0 && (nv) == (nv)*2.0))
1898 #endif
1899 #if defined(Perl_floor)
1900 # define _psx_floor(nv) Perl_floor(nv)
1901 #else
1902 # define _psx_floor(nv) ((IMax_t)(nv) - (IMax_t)((nv) < (NV)(IMax_t)(nv)))
1903 #endif
1904  
1905 ## https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_08_05 says:
1906 ## The tv_nsec member is only valid if greater than or equal to zero,
1907 ## and less than the number of nanoseconds in a second (1000 million).
1908 ## The time interval described by this structure is
1909 ## (tv_sec * 10^9 + tv_nsec) nanoseconds.
1910 ## Therefore we must take the floor() of sec_nv to convert e.g. "-0.5"
1911 ## correctly as {tv_sec=-1, tv_nsec=500000000}. Linux forbids negative
1912 ## seconds but POSIX doesn't.
1913  
1914 #define TIMESPEC_FROM_NV_nomg(tspec, sec_sv) STMT_START { \
1915 const NV sec_nv = SvNV_nomg(sec_sv); \
1916 if (UNLIKELY(_psx_isnaninf(sec_nv))) { \
1917 tspec.tv_sec = 0; \
1918 tspec.tv_nsec = -1; \
1919 } \
1920 else { \
1921 tspec.tv_sec = (Time_t)_psx_floor(sec_nv); \
1922 tspec.tv_nsec = (long)((sec_nv - (NV)tspec.tv_sec)*1e9); \
1923 } \
1924 } STMT_END
1925  
1926 #define TIMESPEC_FROM_IV_nomg(tspec, sec_sv, nsec_long) STMT_START { \
1927 tspec.tv_sec = (Time_t)SvIV_nomg(sec_sv); \
1928 tspec.tv_nsec = nsec_long; \
1929 } STMT_END
1930  
1931 #ifdef PSX2008_HAS_CLOCK_NANOSLEEP
1932 void
1933 clock_nanosleep(clockid_t clock_id, int flags, SV *sec, long nsec=0);
1934 PROTOTYPE: $$@
1935 PPCODE:
1936 {
1937 int rv;
1938 struct timespec request;
1939 0 struct timespec remain = {0};
1940 0 ▶ SvGETMAGIC(sec);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sec); 0 0 0
SvGETMAGIC(sec); 0 0 0
1941 0 ▶ if (items == 3 && LOOKS_LIKE_NV(sec))
Branch: 7 branches
BranchTrueFalseTotal
if (items == 3 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 3 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 3 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 3 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 3 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 3 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 3 && LOOKS_LIKE_NV(sec)) 0 0 0
1942 0 ▶ TIMESPEC_FROM_NV_nomg(request, sec);
Branch: 1 branch
BranchTrueFalseTotal
TIMESPEC_FROM_NV_nomg(request, sec); 0 0 0
1943 else
1944 0 TIMESPEC_FROM_IV_nomg(request, sec, nsec);
1945 0 rv = clock_nanosleep(clock_id, flags, &request, &remain);
1946 0 ▶ if (rv)
Branch: 1 branch
BranchTrueFalseTotal
if (rv) 0 0 0
1947 0 SETERRNO(rv, rv);
1948 0 ▶ if (rv == 0 || rv == EINTR)
Branch: 2 branches
BranchTrueFalseTotal
if (rv == 0 || rv == EINTR) 0 0 0
if (rv == 0 || rv == EINTR) 0 0 0
1949 0 PUSH_TIMESPEC(remain, 0);
1950 }
1951  
1952 #endif
1953  
1954 #ifdef PSX2008_HAS_CLOCK_SETTIME
1955 void
1956 clock_settime(clockid_t clock_id, SV *sec, long nsec=0);
1957 PROTOTYPE: $@
1958 PPCODE:
1959 {
1960 struct timespec tp;
1961 0 ▶ SvGETMAGIC(sec);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sec); 0 0 0
SvGETMAGIC(sec); 0 0 0
1962 0 ▶ if (items == 2 && LOOKS_LIKE_NV(sec))
Branch: 7 branches
BranchTrueFalseTotal
if (items == 2 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 2 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 2 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 2 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 2 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 2 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 2 && LOOKS_LIKE_NV(sec)) 0 0 0
1963 0 ▶ TIMESPEC_FROM_NV_nomg(tp, sec);
Branch: 1 branch
BranchTrueFalseTotal
TIMESPEC_FROM_NV_nomg(tp, sec); 0 0 0
1964 else
1965 0 TIMESPEC_FROM_IV_nomg(tp, sec, nsec);
1966 0 ▶ if (LIKELY(clock_settime(clock_id, &tp) == 0))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(clock_settime(clock_id, &tp) == 0)) 0 0 0
1967 0 mPUSHp("0 but true", 10);
1968 else
1969 0 PUSHs(&PL_sv_undef);
1970 }
1971  
1972 #endif
1973  
1974 #ifdef PSX2008_HAS_NANOSLEEP
1975 void
1976 nanosleep(SV *sec, long nsec=0);
1977 PROTOTYPE: @
1978 PPCODE:
1979 {
1980 int rv;
1981 struct timespec request;
1982 0 struct timespec remain = {0};
1983 0 ▶ SvGETMAGIC(sec);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sec); 0 0 0
SvGETMAGIC(sec); 0 0 0
1984 0 ▶ if (items == 1 && LOOKS_LIKE_NV(sec))
Branch: 7 branches
BranchTrueFalseTotal
if (items == 1 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 1 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 1 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 1 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 1 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 1 && LOOKS_LIKE_NV(sec)) 0 0 0
if (items == 1 && LOOKS_LIKE_NV(sec)) 0 0 0
1985 0 ▶ TIMESPEC_FROM_NV_nomg(request, sec);
Branch: 1 branch
BranchTrueFalseTotal
TIMESPEC_FROM_NV_nomg(request, sec); 0 0 0
1986 else
1987 0 TIMESPEC_FROM_IV_nomg(request, sec, nsec);
1988 0 rv = nanosleep(&request, &remain);
1989 0 ▶ if (rv == 0 || errno == EINTR)
Branch: 2 branches
BranchTrueFalseTotal
if (rv == 0 || errno == EINTR) 0 0 0
if (rv == 0 || errno == EINTR) 0 0 0
1990 0 PUSH_TIMESPEC(remain, 0);
1991 }
1992  
1993 #endif
1994  
1995 #ifdef PSX2008_HAS_DLCLOSE
1996 SysRetTrue
1997 dlclose(void *handle);
1998  
1999 #endif
2000  
2001 #ifdef PSX2008_HAS_DLERROR
2002 char *
2003 dlerror();
2004  
2005 #endif
2006  
2007 #ifdef PSX2008_HAS_DLOPEN
2008 void
2009 dlopen(psx_safepath_t__fail_undef filename, int flags);
2010 PPCODE:
2011 {
2012 0 void *rv = dlopen(filename, flags);
2013 0 ▶ if (!rv)
Branch: 1 branch
BranchTrueFalseTotal
if (!rv) 0 0 0
2014 0 PUSHs(&PL_sv_undef);
2015 else
2016 0 mPUSHs(newSViv(PTR2IV(rv)));
2017 }
2018  
2019 #endif
2020  
2021 #ifdef PSX2008_HAS_DLSYM
2022 void
2023 dlsym(void *handle, const char *name);
2024 PPCODE:
2025 {
2026 0 void *rv = dlsym(handle, name);
2027 0 ▶ if (!rv)
Branch: 1 branch
BranchTrueFalseTotal
if (!rv) 0 0 0
2028 0 PUSHs(&PL_sv_undef);
2029 else
2030 0 mPUSHs(newSViv(PTR2IV(rv)));
2031 }
2032  
2033 #endif
2034  
2035 #ifdef PSX2008_HAS_FEGETROUND
2036 int
2037 fegetround();
2038  
2039 #endif
2040  
2041 #ifdef PSX2008_HAS_FESETROUND
2042 SysRetTrue
2043 fesetround(int rounding_mode);
2044  
2045 #endif
2046  
2047 #ifdef PSX2008_HAS_FECLEAREXCEPT
2048 SysRetTrue
2049 feclearexcept(int excepts);
2050  
2051 #endif
2052  
2053 #ifdef PSX2008_HAS_FERAISEEXCEPT
2054 SysRetTrue
2055 feraiseexcept(int excepts);
2056  
2057 #endif
2058  
2059 #ifdef PSX2008_HAS_FETESTEXCEPT
2060 int
2061 fetestexcept(int excepts);
2062  
2063 #endif
2064  
2065 #ifdef PSX2008_FFS
2066 IV
2067 ffs(IV i);
2068 CODE:
2069 0 ▶ RETVAL = PSX2008_FFS(i);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PSX2008_FFS(i); 0 0 0
2070 OUTPUT:
2071 RETVAL
2072  
2073 #endif
2074  
2075 #ifdef PSX2008_HAS_FNMATCH
2076 void
2077 fnmatch(const char *pattern, const char *string, int flags);
2078 PPCODE:
2079 {
2080 0 int rv = fnmatch(pattern, string, flags);
2081 0 ▶ if (LIKELY(rv == 0 || rv == FNM_NOMATCH))
Branch: 2 branches
BranchTrueFalseTotal
if (LIKELY(rv == 0 || rv == FNM_NOMATCH)) 0 0 0
if (LIKELY(rv == 0 || rv == FNM_NOMATCH)) 0 0 0
2082 0 mPUSHs(newSViv(rv));
2083 else
2084 0 PUSHs(&PL_sv_undef);
2085 }
2086  
2087 #endif
2088  
2089 #ifdef PSX2008_HAS_KILLPG
2090 SysRetTrue
2091 killpg(pid_t pgrp, int sig);
2092  
2093 #endif
2094  
2095 #ifdef PSX2008_HAS_RAISE
2096 SysRetTrue
2097 raise(int sig);
2098  
2099 #endif
2100  
2101 #ifdef PSX2008_HAS_GETDATE
2102 void
2103 getdate(const char *string);
2104 PPCODE:
2105 {
2106 0 struct tm *tm = getdate(string);
2107 0 ▶ if (tm) {
Branch: 1 branch
BranchTrueFalseTotal
if (tm) { 0 0 0
2108 0 ▶ EXTEND(SP, 9);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 9); 0 0 0
2109 0 mPUSHs(newSViv(tm->tm_sec));
2110 0 mPUSHs(newSViv(tm->tm_min));
2111 0 mPUSHs(newSViv(tm->tm_hour));
2112 0 mPUSHs(newSViv(tm->tm_mday));
2113 0 mPUSHs(newSViv(tm->tm_mon));
2114 0 mPUSHs(newSViv(tm->tm_year));
2115 0 mPUSHs(newSViv(tm->tm_wday));
2116 0 mPUSHs(newSViv(tm->tm_yday));
2117 0 mPUSHs(newSViv(tm->tm_isdst));
2118 }
2119 }
2120  
2121 #endif
2122  
2123 #ifdef PSX2008_HAS_GETDATE_ERR
2124 int
2125 getdate_err();
2126 CODE:
2127 0 ▶ RETVAL = getdate_err;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = getdate_err; 0 0 0
2128 OUTPUT:
2129 RETVAL
2130  
2131 #endif
2132  
2133 #ifdef PSX2008_HAS_STRPTIME
2134 #define TM_COUNT_MAX 11
2135 void
2136 strptime(const char *s, const char *format, ...);
2137 PROTOTYPE: $$@
2138 INIT:
2139 struct tm tm;
2140 char *remainder;
2141 Size_t i, tm_count;
2142 6 AV *tm_av = NULL;
2143 U8 gimme;
2144 PPCODE:
2145 {
2146 6 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 3 3 6
2147 3 ▶ if (items > TM_COUNT_MAX + 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > TM_COUNT_MAX + 2) { 0 3 3
2148 0 DumpDarkSuckerjerk:
2149 0 croak(PACKNAME "::strptime: Too many arguments");
2150 }
2151 3 SV *tm_arg = ST(2l);
2152 3 ▶ SvGETMAGIC(tm_arg);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(tm_arg); 0 3 3
SvGETMAGIC(tm_arg); 0 0 0
2153 3 ▶ if (SvIsARRAY(tm_arg)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIsARRAY(tm_arg)) { 3 0 3
if (SvIsARRAY(tm_arg)) { 3 0 3
2154 3 ▶ if (items == 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 3) 3 0 3
2155 3 tm_av = (AV*)SvRV(tm_arg);
2156 else
2157 0 goto DumpDarkSuckerjerk;
2158 }
2159 }
2160  
2161 6 ▶ tm_count = tm_av ? av_count(tm_av) : (Size_t)items - 2;
Branch: 1 branch
BranchTrueFalseTotal
tm_count = tm_av ? av_count(tm_av) : (Size_t)items - 2; 3 3 6
2162 6 tm_count = (tm_count > TM_COUNT_MAX) ? TM_COUNT_MAX : tm_count;
2163  
2164 /* Gather initial values in an int array to populate tm. For lack of
2165 * something better we use INT_MIN to denote undef values. */
2166 {
2167 6 int tm_ary[] = {
2168 PERL_INT_MIN, PERL_INT_MIN, PERL_INT_MIN,
2169 PERL_INT_MIN, PERL_INT_MIN, PERL_INT_MIN,
2170 PERL_INT_MIN, PERL_INT_MIN, PERL_INT_MIN,
2171 };
2172 #ifdef HAS_TM_TM_GMTOFF
2173 6 tm.tm_gmtoff = PERL_INT_MIN;
2174 #endif
2175 #ifdef HAS_TM_TM_ZONE
2176 6 tm.tm_zone = NULL;
2177 #endif
2178 6 ▶ for (i = 0; i < tm_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < tm_count; i++) { 0 6 6
2179 SV *tm_sv;
2180 0 ▶ if (!tm_av)
Branch: 1 branch
BranchTrueFalseTotal
if (!tm_av) 0 0 0
2181 0 tm_sv = ST(i+2);
2182 else {
2183 0 SV **av_elt = av_fetch(tm_av, i, 0);
2184 0 ▶ if (!av_elt)
Branch: 1 branch
BranchTrueFalseTotal
if (!av_elt) 0 0 0
2185 0 continue;
2186 0 tm_sv = *av_elt;
2187 }
2188 0 ▶ SvGETMAGIC(tm_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(tm_sv); 0 0 0
SvGETMAGIC(tm_sv); 0 0 0
2189 0 ▶ if (!SvOK(tm_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(tm_sv)) 0 0 0
2190 0 continue;
2191 0 ▶ if (i < 9)
Branch: 1 branch
BranchTrueFalseTotal
if (i < 9) 0 0 0
2192 0 tm_ary[i] = (int)SvIV(tm_sv);
2193 #ifdef HAS_TM_TM_GMTOFF
2194 0 ▶ else if (i == 9)
Branch: 1 branch
BranchTrueFalseTotal
else if (i == 9) 0 0 0
2195 0 tm.tm_gmtoff = (long)SvIV(tm_sv);
2196 #endif
2197 #ifdef HAS_TM_TM_ZONE
2198 0 ▶ else if (i == 10)
Branch: 1 branch
BranchTrueFalseTotal
else if (i == 10) 0 0 0
2199 0 tm.tm_zone = SvPV_nolen(tm_sv);
2200 #endif
2201 }
2202 6 tm.tm_sec = tm_ary[0]; tm.tm_min = tm_ary[1]; tm.tm_hour = tm_ary[2];
2203 6 tm.tm_mday = tm_ary[3]; tm.tm_mon = tm_ary[4]; tm.tm_year = tm_ary[5];
2204 6 tm.tm_wday = tm_ary[6]; tm.tm_yday = tm_ary[7]; tm.tm_isdst = tm_ary[8];
2205 }
2206  
2207 6 gimme = GIMME_V;
2208 6 remainder = strptime(s, format, &tm);
2209  
2210 6 ▶ if (!remainder) {
Branch: 1 branch
BranchTrueFalseTotal
if (!remainder) { 1 5 6
2211 1 ▶ if (gimme != G_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if (gimme != G_LIST) 1 0 1
2212 1 PUSHs(&PL_sv_undef);
2213 }
2214 else {
2215 /* Create SV array from struct tm turned into an int array. */
2216 #ifdef HAS_TM_TM_GMTOFF
2217 #define TM_ARY_TYPE long
2218 #define TM_GMTOFF_VAL tm.tm_gmtoff
2219 #else
2220 #define TM_ARY_TYPE int
2221 #define TM_GMTOFF_VAL PERL_INT_MIN
2222 #endif
2223 5 const TM_ARY_TYPE tm_ary[TM_COUNT_MAX] = {
2224 5 tm.tm_sec, tm.tm_min, tm.tm_hour,
2225 5 tm.tm_mday, tm.tm_mon, tm.tm_year,
2226 5 tm.tm_wday, tm.tm_yday, tm.tm_isdst,
2227 5 TM_GMTOFF_VAL,
2228 PERL_INT_MIN, /* tm_zone dummy so all sv_ary SVs default to undef. */
2229 };
2230 SV *sv_ary[TM_COUNT_MAX];
2231 5 ▶ if (LIKELY(tm_av || gimme == G_LIST)) {
Branch: 2 branches
BranchTrueFalseTotal
if (LIKELY(tm_av || gimme == G_LIST)) { 2 3 5
if (LIKELY(tm_av || gimme == G_LIST)) { 1 1 2
2232 #pragma GCC unroll 1 /* https://github.com/llvm/llvm-project/issues/42332 */
2233 48 ▶ for (i = 0; i < TM_COUNT_MAX; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < TM_COUNT_MAX; i++) { 44 4 48
2234 44 sv_ary[i] = sv_newmortal();
2235 44 ▶ if (tm_ary[i] != PERL_INT_MIN)
Branch: 1 branch
BranchTrueFalseTotal
if (tm_ary[i] != PERL_INT_MIN) 32 12 44
2236 32 sv_setiv(sv_ary[i], (IV)tm_ary[i]);
2237 }
2238 #ifdef HAS_TM_TM_ZONE
2239 4 ▶ if (LIKELY(!!tm.tm_zone))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(!!tm.tm_zone)) 0 4 4
2240 0 sv_setpv(sv_ary[10], tm.tm_zone);
2241 #endif
2242 }
2243 /* Populate tm_av argument and/or return values from sv_ary. */
2244 5 ▶ if (tm_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (tm_av) { 3 2 5
2245 3 av_extend(tm_av, TM_COUNT_MAX - 1);
2246 36 ▶ for (i = 0; i < TM_COUNT_MAX; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < TM_COUNT_MAX; i++) { 33 3 36
2247 33 SV *tm_sv = sv_ary[i];
2248 /* Increase refcount since we mortalized all SVs. */
2249 33 SvREFCNT_inc_simple_void_NN(tm_sv);
2250 33 ▶ if (!av_store((AV*)tm_av, i, tm_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!av_store((AV*)tm_av, i, tm_sv)) { 0 33 33
2251 0 ▶ if (LIKELY(SvMAGICAL(tm_av)))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(SvMAGICAL(tm_av))) 0 0 0
2252 0 mg_set(tm_sv);
2253 0 SvREFCNT_dec_NN(tm_sv);
2254 }
2255 }
2256 }
2257 5 ▶ if (gimme == G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (gimme == G_LIST) { 2 3 5
2258 2 ▶ EXTEND(SP, TM_COUNT_MAX);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, TM_COUNT_MAX); 0 2 2
2259 24 ▶ for (i = 0; i < TM_COUNT_MAX; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < TM_COUNT_MAX; i++) 22 2 24
2260 22 PUSHs(sv_ary[i]);
2261 }
2262 else
2263 3 mPUSHs(newSVuv(remainder - s));
2264 }
2265 }
2266  
2267 #endif
2268  
2269 #ifdef PSX2008_HAS_GETHOSTID
2270 long
2271 gethostid();
2272  
2273 #endif
2274  
2275 #ifdef PSX2008_HAS_GETHOSTNAME
2276 void
2277 gethostname();
2278 INIT:
2279 #if defined(HOST_NAME_MAX) && HOST_NAME_MAX > 256
2280 char name[HOST_NAME_MAX];
2281 #elif defined(MAXHOSTNAMELEN) && MAXHOSTNAMELEN > 256
2282 char name[MAXHOSTNAMELEN];
2283 #else
2284 char name[256];
2285 #endif
2286 PPCODE:
2287 {
2288 0 ▶ if (LIKELY(gethostname(name, sizeof(name)) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(gethostname(name, sizeof(name)) == 0)) { 0 0 0
2289 0 Size_t namelen = _strnlen(name, sizeof(name));
2290 0 mPUSHp(name, namelen);
2291 }
2292 else
2293 0 PUSHs(&PL_sv_undef);
2294 }
2295  
2296 #endif
2297  
2298 #ifdef PSX2008_HAS_GETITIMER
2299 void
2300 getitimer(int which);
2301 PPCODE:
2302 {
2303 struct itimerval value;
2304 0 ▶ if (getitimer(which, &value) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (getitimer(which, &value) == 0) { 0 0 0
2305 0 ▶ EXTEND(SP, 2); /* Stack already has room for 2 items. */
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); /* Stack already has room for 2 items. */ 0 0 0
2306 0 mPUSHs(newSViv(value.it_interval.tv_sec));
2307 0 mPUSHs(newSViv(value.it_interval.tv_usec));
2308 0 mPUSHs(newSViv(value.it_value.tv_sec));
2309 0 mPUSHs(newSViv(value.it_value.tv_usec));
2310 }
2311 }
2312  
2313 #endif
2314  
2315 #ifdef PSX2008_HAS_SETITIMER
2316 void
2317 setitimer(int which, \
2318 Time_t int_sec, long int_usec, \
2319 Time_t val_sec, long val_usec);
2320 PROTOTYPE: $@
2321 INIT:
2322 0 struct itimerval value = { {int_sec, int_usec}, {val_sec, val_usec} };
2323 struct itimerval ovalue;
2324 PPCODE:
2325 0 ▶ if (setitimer(which, &value, &ovalue) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (setitimer(which, &value, &ovalue) == 0) { 0 0 0
2326 /* We already know the stack is long enough. */
2327 0 mPUSHs(newSViv(ovalue.it_interval.tv_sec));
2328 0 mPUSHs(newSViv(ovalue.it_interval.tv_usec));
2329 0 mPUSHs(newSViv(ovalue.it_value.tv_sec));
2330 0 mPUSHs(newSViv(ovalue.it_value.tv_usec));
2331 }
2332  
2333 #endif
2334  
2335 #ifdef PSX2008_HAS_NICE
2336 void
2337 nice(int incr);
2338 INIT:
2339 0 SETERRNO(0, 0);
2340 PPCODE:
2341 {
2342 0 int rv = nice(incr);
2343 0 ▶ if (rv != -1 || errno == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (rv != -1 || errno == 0) 0 0 0
if (rv != -1 || errno == 0) 0 0 0
2344 0 mPUSHs(newSViv(rv));
2345 else
2346 0 PUSHs(&PL_sv_undef);
2347 }
2348  
2349 #endif
2350  
2351 #ifdef PSX2008_HAS_GETPRIORITY
2352 void
2353 getpriority(int which=PRIO_PROCESS, id_t who=0);
2354 INIT:
2355 0 SETERRNO(0, 0);
2356 PPCODE:
2357 {
2358 0 int rv = getpriority(which, who);
2359 0 ▶ if (rv != -1 || errno == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (rv != -1 || errno == 0) 0 0 0
if (rv != -1 || errno == 0) 0 0 0
2360 0 mPUSHs(newSViv(rv));
2361 else
2362 0 PUSHs(&PL_sv_undef);
2363 }
2364  
2365 #endif
2366  
2367 #ifdef PSX2008_HAS_SETPRIORITY
2368 SysRetTrue
2369 setpriority(int prio, int which=PRIO_PROCESS, id_t who=0);
2370  
2371 #endif
2372  
2373 #define RETURN_UTXENT { \
2374 if (utxent) { \
2375 Size_t len; \
2376 EXTEND(SP, 7); \
2377 len = _strnlen(utxent->ut_user, sizeof(utxent->ut_user)); \
2378 mPUSHp(utxent->ut_user, len); \
2379 len = _strnlen(utxent->ut_id, sizeof(utxent->ut_id)); \
2380 mPUSHp(utxent->ut_id, len); \
2381 len = _strnlen(utxent->ut_line, sizeof(utxent->ut_line)); \
2382 mPUSHp(utxent->ut_line, len); \
2383 mPUSHs(newSViv(utxent->ut_pid)); \
2384 mPUSHs(newSViv(utxent->ut_type)); \
2385 mPUSHs(newSViv(utxent->ut_tv.tv_sec)); \
2386 mPUSHs(newSViv(utxent->ut_tv.tv_usec)); \
2387 } \
2388 }
2389  
2390 #ifdef PSX2008_HAS_ENDUTXENT
2391 void
2392 endutxent();
2393 PPCODE:
2394 0 endutxent();
2395  
2396 #endif
2397  
2398 #ifdef PSX2008_HAS_GETUTXENT
2399 void
2400 getutxent();
2401 PPCODE:
2402 {
2403 0 struct utmpx *utxent = getutxent();
2404 0 ▶ RETURN_UTXENT;
Branch: 2 branches
BranchTrueFalseTotal
RETURN_UTXENT; 0 0 0
RETURN_UTXENT; 0 0 0
2405 }
2406  
2407 #endif
2408  
2409 #ifdef PSX2008_HAS_GETUTXID
2410 void
2411 getutxid(short ut_type, SV *ut_id=NULL);
2412 INIT:
2413 struct utmpx *utxent;
2414 0 struct utmpx utxent_req = {.ut_type=ut_type};
2415 0 const Size_t ut_id_size = sizeof(utxent_req.ut_id);
2416 PPCODE:
2417 {
2418 0 ▶ if (ut_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (ut_id) { 0 0 0
2419 STRLEN pvlen;
2420 0 const char *pv = SvPV_const(ut_id, pvlen);
2421 0 const STRLEN ut_id_len = ut_id_size < pvlen ? ut_id_size : pvlen;
2422 0 Copy(pv, utxent_req.ut_id, ut_id_len, char);
2423 }
2424 0 utxent = getutxid(&utxent_req);
2425 0 ▶ RETURN_UTXENT;
Branch: 2 branches
BranchTrueFalseTotal
RETURN_UTXENT; 0 0 0
RETURN_UTXENT; 0 0 0
2426 }
2427  
2428 #endif
2429  
2430 #ifdef PSX2008_HAS_GETUTXLINE
2431 void
2432 getutxline(SV *ut_line);
2433 INIT:
2434 struct utmpx *utxent;
2435 0 struct utmpx utxent_req = {0};
2436 0 const Size_t ut_line_size = sizeof(utxent_req.ut_line);
2437 PPCODE:
2438 {
2439 STRLEN pvlen;
2440 0 const char *pv = SvPV_const(ut_line, pvlen);
2441 0 const STRLEN ut_line_len = ut_line_size < pvlen ? ut_line_size : pvlen;
2442 0 Copy(pv, utxent_req.ut_line, ut_line_len, char);
2443 0 utxent = getutxline(&utxent_req);
2444 0 ▶ RETURN_UTXENT;
Branch: 2 branches
BranchTrueFalseTotal
RETURN_UTXENT; 0 0 0
RETURN_UTXENT; 0 0 0
2445 }
2446  
2447 #endif
2448  
2449 #ifdef PSX2008_HAS_SETUTXENT
2450 void
2451 setutxent();
2452 PPCODE:
2453 0 setutxent();
2454  
2455 #endif
2456  
2457 #ifdef PSX2008_HAS_DRAND48
2458 NV
2459 drand48();
2460  
2461 #endif
2462  
2463 #ifdef PSX2008_HAS_ERAND48
2464 void
2465 erand48(unsigned short X0, unsigned short X1, unsigned short X2);
2466 INIT:
2467 0 unsigned short xsubi[3] = { X0, X1, X2 };
2468 0 double result = erand48(xsubi);
2469 PPCODE:
2470 /* We already know the stack is long enough. */
2471 0 mPUSHs(newSVnv((NV)result));
2472 0 mPUSHs(newSVuv(xsubi[0]));
2473 0 mPUSHs(newSVuv(xsubi[1]));
2474 0 mPUSHs(newSVuv(xsubi[2]));
2475  
2476 #endif
2477  
2478 #ifdef PSX2008_HAS_JRAND48
2479 void
2480 jrand48(unsigned short X0, unsigned short X1, unsigned short X2);
2481 ALIAS:
2482 nrand48 = 1
2483 INIT:
2484 0 unsigned short xsubi[3] = { X0, X1, X2 };
2485 0 ▶ long result = (ix == 0) ? jrand48(xsubi) : nrand48(xsubi);
Branch: 1 branch
BranchTrueFalseTotal
long result = (ix == 0) ? jrand48(xsubi) : nrand48(xsubi); 0 0 0
2486 PPCODE:
2487 /* We already know the stack is long enough. */
2488 0 mPUSHs(newSViv((IV)result));
2489 0 mPUSHs(newSVuv(xsubi[0]));
2490 0 mPUSHs(newSVuv(xsubi[1]));
2491 0 mPUSHs(newSVuv(xsubi[2]));
2492  
2493 #endif
2494  
2495 #ifdef PSX2008_HAS_LRAND48
2496 long
2497 lrand48();
2498  
2499 #endif
2500  
2501 #ifdef PSX2008_HAS_MRAND48
2502 long
2503 mrand48();
2504  
2505 #endif
2506  
2507 #ifdef PSX2008_HAS_SEED48
2508 void
2509 seed48(unsigned short seed1, unsigned short seed2, unsigned short seed3);
2510 INIT:
2511 0 unsigned short seed16v[3] = { seed1, seed2, seed3 };
2512 0 unsigned short *old = seed48(seed16v);
2513 PPCODE:
2514 /* We already know the stack is long enough. */
2515 0 mPUSHs(newSVuv(old[0]));
2516 0 mPUSHs(newSVuv(old[1]));
2517 0 mPUSHs(newSVuv(old[2]));
2518  
2519 #endif
2520  
2521 #ifdef PSX2008_HAS_SRAND48
2522 void
2523 srand48(long seedval);
2524 PPCODE:
2525 0 srand48(seedval);
2526  
2527 #endif
2528  
2529 #ifdef PSX2008_HAS_RANDOM
2530 long
2531 random();
2532  
2533 #endif
2534  
2535 #ifdef PSX2008_HAS_SRANDOM
2536 void
2537 srandom(unsigned seed);
2538 PPCODE:
2539 0 srandom(seed);
2540  
2541 #endif
2542  
2543  
2544 #if defined(PSX2008_HAS_GETENTROPY)
2545 # define _psx_getentropy(buf, len) getentropy(buf, len)
2546 #elif defined(PSX2008_HAS_GETRANDOM)
2547 # define _psx_getrandom(buf, len) getrandom(buf, len, 0)
2548 #elif defined(PSX2008_HAS_GETRANDOM_SYS)
2549 # define _psx_getrandom(buf, len) syscall(SYS_getrandom, buf, len, 0)
2550 #elif defined(PSX2008_HAS_ARC4RANDOM_BUF)
2551 # define _psx_getentropy(buf, len) (arc4random_buf(buf, len), 0)
2552 #elif defined(PSX2008_HAS_BCRYPTGENRANDOM)
2553 # define _psx_getentropy(buf, len) \
2554 (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) ? -1 : 0)
2555 #elif defined(_psx_cpu_rand_step_ok)
2556 # define _psx_getentropy(buf, len) (ASSUME(!!buf), _cpu_rand50c(buf, len), 0)
2557 #endif
2558  
2559 #if defined(_psx_getentropy) || defined(_psx_getrandom)
2560 # ifdef _psx_cpu_rand_step_ok
2561 # define PSX_CPURAND_SIZE sizeof(_psx_cpu_rand_ret_t)
2562 # define PSX_GETENTROPY_SVLEN_ROUNDUP(l) \
2563 ((l) + (PSX_CPURAND_SIZE - ((l) % PSX_CPURAND_SIZE)) % PSX_CPURAND_SIZE)
2564 # else
2565 # define PSX_GETENTROPY_SVLEN_ROUNDUP(l) (l)
2566 # endif
2567 void
2568 getentropy(IV length);
2569 PPCODE:
2570 {
2571 8 ▶ if (UNLIKELY(length < 0 || length > GETENTROPY_MAX)) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNLIKELY(length < 0 || length > GETENTROPY_MAX)) { 6 2 8
if (UNLIKELY(length < 0 || length > GETENTROPY_MAX)) { 1 5 6
2572 3 SETERRNO(EINVAL, LIB_INVARG); /* Thus quoth POSIX. */
2573 3 MakeUndefGreatAgain:
2574 3 PUSHs(&PL_sv_undef);
2575 }
2576 else {
2577 5 STRLEN sv_len = PSX_GETENTROPY_SVLEN_ROUNDUP(length);
2578 5 SV *bufsv = sv_2mortal(newSV(sv_len + !sv_len));
2579 5 char *cbuf = SvPVX(bufsv);
2580 # if defined(_psx_getentropy)
2581 5 int rv = _psx_getentropy(cbuf, sv_len);
2582 5 cbuf[length] = '\0';
2583 5 ▶ if (rv < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rv < 0) 0 5 5
2584 0 goto MakeUndefGreatAgain;
2585 # else
2586 SSize_t rv;
2587 Size_t grlen = length;
2588 while (grlen) {
2589 while ((rv = _psx_getrandom(cbuf, grlen)) < 0)
2590 if (errno != EINTR)
2591 goto MakeUndefGreatAgain;
2592 if (rv == 0 || (Size_t)rv > grlen) {
2593 SETERRNO(EIO, SS$_ABORT);
2594 goto MakeUndefGreatAgain;
2595 }
2596 cbuf += rv;
2597 grlen -= rv;
2598 }
2599 *cbuf = '\0';
2600 # endif
2601 5 SvCUR_set(bufsv, length);
2602 5 SvPOK_only(bufsv);
2603 5 ▶ SvTAINTED_on(bufsv);
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(bufsv); 0 5 5
2604 5 PUSHs(bufsv);
2605 }
2606 }
2607  
2608 #endif
2609  
2610 #ifdef PSX2008_HAS_GETEGID
2611 gid_t
2612 getegid();
2613  
2614 #endif
2615  
2616 #ifdef PSX2008_HAS_GETEUID
2617 uid_t
2618 geteuid();
2619  
2620 #endif
2621  
2622 #ifdef PSX2008_HAS_GETGID
2623 gid_t
2624 getgid();
2625  
2626 #endif
2627  
2628 #ifdef PSX2008_HAS_GETUID
2629 uid_t
2630 getuid();
2631  
2632 #endif
2633  
2634 #ifdef PSX2008_HAS_GETSID
2635 pid_t
2636 getsid(pid_t pid=0);
2637  
2638 #endif
2639  
2640 #ifdef PSX2008_HAS_GETRESGID
2641 void
2642 getresgid();
2643 PPCODE:
2644 {
2645 gid_t rid, eid, sid;
2646 0 int rv = getresgid(&rid, &eid, &sid);
2647 0 ▶ if (LIKELY(rv == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(rv == 0)) { 0 0 0
2648 0 ▶ EXTEND(SP, 2); /* Stack already has room for 1 item. */
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); /* Stack already has room for 1 item. */ 0 0 0
2649 0 mPUSHs(newSVuv(rid));
2650 0 mPUSHs(newSVuv(eid));
2651 0 mPUSHs(newSVuv(sid));
2652 }
2653 }
2654  
2655 #endif
2656  
2657 #ifdef PSX2008_HAS_GETRESUID
2658 void
2659 getresuid();
2660 PPCODE:
2661 {
2662 uid_t rid, eid, sid;
2663 0 int rv = getresuid(&rid, &eid, &sid);
2664 0 ▶ if (LIKELY(rv == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(rv == 0)) { 0 0 0
2665 0 ▶ EXTEND(SP, 2); /* Stack already has room for 1 item. */
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); /* Stack already has room for 1 item. */ 0 0 0
2666 0 mPUSHs(newSVuv(rid));
2667 0 mPUSHs(newSVuv(eid));
2668 0 mPUSHs(newSVuv(sid));
2669 }
2670 }
2671  
2672 #endif
2673  
2674 #ifdef PSX2008_HAS_SETEGID
2675 SysRetTrue
2676 setegid(gid_t gid);
2677  
2678 #endif
2679  
2680 #ifdef PSX2008_HAS_SETEUID
2681 SysRetTrue
2682 seteuid(uid_t uid);
2683  
2684 #endif
2685  
2686 #ifdef PSX2008_HAS_SETGID
2687 SysRetTrue
2688 setgid(gid_t gid);
2689  
2690 #endif
2691  
2692 #ifdef PSX2008_HAS_SETREGID
2693 SysRetTrue
2694 setregid(gid_t rgid, gid_t egid);
2695  
2696 #endif
2697  
2698 #ifdef PSX2008_HAS_SETRESGID
2699 SysRetTrue
2700 setresgid(gid_t rgid, gid_t egid, gid_t sgid);
2701  
2702 #endif
2703  
2704 #ifdef PSX2008_HAS_SETREUID
2705 SysRetTrue
2706 setreuid(uid_t ruid, uid_t euid);
2707  
2708 #endif
2709  
2710 #ifdef PSX2008_HAS_SETRESUID
2711 SysRetTrue
2712 setresuid(uid_t ruid, uid_t euid, uid_t suid);
2713  
2714 #endif
2715  
2716 #ifdef PSX2008_HAS_SETSID
2717 pid_t
2718 setsid();
2719  
2720 #endif
2721  
2722 #ifdef PSX2008_HAS_SETUID
2723 SysRetTrue
2724 setuid(uid_t uid);
2725  
2726 #endif
2727  
2728 ## Ancient versions of xsubpp don't seem to understand "#elif defined ...".
2729  
2730 #ifdef PSX2008_HAS_SIGHOLD
2731 SysRetTrue
2732 sighold(int sig);
2733  
2734 #else
2735 #if defined(PSX2008_HAS_SIGEMPTYSET) && defined(PSX2008_HAS_SIGADDSET) \
2736 && defined(PSX2008_HAS_SIGPROCMASK)
2737 SysRetTrue
2738 sighold(int sig);
2739 CODE:
2740 {
2741 sigset_t set;
2742 if (LIKELY(sigemptyset(&set) == 0) && LIKELY(sigaddset(&set, sig) == 0))
2743 RETVAL = sigprocmask(SIG_BLOCK, &set, NULL);
2744 else
2745 RETVAL = -1;
2746 }
2747 OUTPUT:
2748 RETVAL
2749  
2750 #endif
2751 #endif
2752  
2753 #ifdef PSX2008_HAS_SIGIGNORE
2754 SysRetTrue
2755 sigignore(int sig);
2756  
2757 #else
2758 #if defined(PSX2008_HAS_SIGEMPTYSET) && defined(PSX2008_HAS_SIGACTION)
2759 SysRetTrue
2760 sigignore(int sig);
2761 CODE:
2762 {
2763 struct sigaction act;
2764 act.sa_handler = SIG_IGN;
2765 act.sa_flags = 0;
2766 if (LIKELY(sigemptyset(&act.sa_mask) == 0))
2767 RETVAL = sigaction(sig, &act, NULL);
2768 else
2769 RETVAL = -1;
2770 }
2771 OUTPUT:
2772 RETVAL
2773  
2774 #endif
2775 #endif
2776  
2777 #ifdef PSX2008_HAS_SIGPAUSE
2778 void
2779 sigpause(int sig);
2780 PPCODE:
2781 {
2782 0 (void)sigpause(sig);
2783 0 PUSHs(&PL_sv_undef);
2784 }
2785  
2786 #else
2787 #if defined(PSX2008_HAS_SIGPROCMASK) && defined(PSX2008_HAS_SIGDELSET) \
2788 && defined(PSX2008_HAS_SIGSUSPEND)
2789 void
2790 sigpause(int sig);
2791 PPCODE:
2792 {
2793 sigset_t set;
2794 if (LIKELY(sigprocmask(0, NULL, &set) == 0) &&
2795 LIKELY(sigdelset(&set, sig) == 0))
2796 (void)sigsuspend(&set);
2797 PUSHs(&PL_sv_undef);
2798 }
2799  
2800 #endif
2801 #endif
2802  
2803 #ifdef PSX2008_HAS_SIGRELSE
2804 SysRetTrue
2805 sigrelse(int sig);
2806  
2807 #else
2808 #if defined(PSX2008_HAS_SIGEMPTYSET) && defined(PSX2008_HAS_SIGADDSET) \
2809 && defined(PSX2008_HAS_SIGPROCMASK)
2810 SysRetTrue
2811 sigrelse(int sig);
2812 CODE:
2813 {
2814 sigset_t set;
2815 if (LIKELY(sigemptyset(&set) == 0) && LIKELY(sigaddset(&set, sig) == 0))
2816 RETVAL = sigprocmask(SIG_UNBLOCK, &set, NULL);
2817 else
2818 RETVAL = -1;
2819 }
2820 OUTPUT:
2821 RETVAL
2822  
2823 #endif
2824 #endif
2825  
2826 #ifdef PSX2008_HAS_PAUSE
2827 void
2828 pause();
2829 PPCODE:
2830 0 (void)pause();
2831 0 PUSHs(&PL_sv_undef);
2832  
2833 #endif
2834  
2835 #ifdef PSX2008_HAS_ACCEPT4
2836 void
2837 accept4(SV *sock, int flags);
2838 PPCODE:
2839 {
2840 SV *retval;
2841 int got_fd;
2842 0 int skt_fd = _psx_fileno(aTHX_ sock, &got_fd);
2843 0 int rv = accept4(skt_fd, NULL, NULL, flags);
2844 0 ▶ if (rv < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rv < 0) 0 0 0
2845 0 retval = &PL_sv_undef;
2846 0 ▶ else if (got_fd)
Branch: 1 branch
BranchTrueFalseTotal
else if (got_fd) 0 0 0
2847 0 retval = sv_2mortal(newSViv((IV)rv));
2848 0 ▶ else if ((retval = _psx_fd_to_handle(aTHX_ rv, "r+" SOCKET_OPEN_MODE)))
Branch: 1 branch
BranchTrueFalseTotal
else if ((retval = _psx_fd_to_handle(aTHX_ rv, "r+" SOCKET_OPEN_MODE))) 0 0 0
2849 ; /* OK. */
2850 else
2851 0 retval = &PL_sv_undef;
2852 0 PUSHs(retval);
2853 }
2854  
2855 #endif
2856  
2857 #ifdef PSX2008_HAS_DUP3
2858 void
2859 dup3(psx_fd_t oldfd, psx_fd_t newfd, int flags);
2860 PPCODE:
2861 {
2862 0 int rv = dup3(oldfd, newfd, flags);
2863 0 ▶ SV *retval = UNLIKELY(rv < 0) ? &PL_sv_undef : sv_2mortal(newSViv((IV)rv));
Branch: 1 branch
BranchTrueFalseTotal
SV *retval = UNLIKELY(rv < 0) ? &PL_sv_undef : sv_2mortal(newSViv((IV)rv)); 0 0 0
2864 0 PUSHs(retval);
2865 }
2866  
2867 #endif
2868  
2869 #ifdef PSX2008_HAS_PIPE2
2870 void
2871 pipe2(SV *flags);
2872 PPCODE:
2873 {
2874 0 int pipefd[2], rv, ret_fd = 0;
2875 0 ▶ SvGETMAGIC(flags);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(flags); 0 0 0
SvGETMAGIC(flags); 0 0 0
2876 0 ▶ if (SvROK(flags) && SvTYPE(SvRV(flags)) <= SVt_PVMG) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(flags) && SvTYPE(SvRV(flags)) <= SVt_PVMG) { 0 0 0
if (SvROK(flags) && SvTYPE(SvRV(flags)) <= SVt_PVMG) { 0 0 0
2877 0 flags = SvRV(flags);
2878 0 ▶ SvGETMAGIC(flags);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(flags); 0 0 0
SvGETMAGIC(flags); 0 0 0
2879 }
2880 else
2881 0 ret_fd = 1;
2882 0 rv = pipe2(pipefd, (int)SvIV_nomg(flags));
2883 0 ▶ if (rv == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv == 0) { 0 0 0
2884 0 ▶ if (ret_fd) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret_fd) { 0 0 0
2885 0 mPUSHs(newSViv((IV)pipefd[0]));
2886 0 mPUSHs(newSViv((IV)pipefd[1]));
2887 }
2888 else {
2889 0 SV *rdfh = _psx_fd_to_handle(aTHX_ pipefd[0], "r" PIPE_OPEN_MODE);
2890 0 SV *wrfh = _psx_fd_to_handle(aTHX_ pipefd[1], "w" PIPE_OPEN_MODE);
2891 0 ▶ if (rdfh && wrfh) {
Branch: 2 branches
BranchTrueFalseTotal
if (rdfh && wrfh) { 0 0 0
if (rdfh && wrfh) { 0 0 0
2892 0 PUSHs(rdfh);
2893 0 PUSHs(wrfh);
2894 }
2895 }
2896 }
2897 }
2898  
2899 #endif
2900  
2901 #ifdef PSX2008_HAS_PSIGNAL
2902 void
2903 psignal(int sig, const char *msg);
2904 PPCODE:
2905 0 psignal(sig, msg);
2906  
2907 #endif
2908  
2909 #ifdef PSX2008_HAS_STRSIGNAL
2910 char*
2911 strsignal(int sig);
2912  
2913 #endif
2914  
2915 #ifdef PSX2008_HAS_TIMER_CREATE
2916 timer_t
2917 timer_create(clockid_t clockid, SV *sig = NULL);
2918 PREINIT:
2919 0 ▶ struct sigevent sevp = {0};
Branch: 1 branch
BranchTrueFalseTotal
struct sigevent sevp = {0}; 0 0 0
2920 timer_t timerid;
2921 int rv;
2922 CODE:
2923 {
2924 0 ▶ if (sig) {
Branch: 1 branch
BranchTrueFalseTotal
if (sig) { 0 0 0
2925 if (SIGEV_SIGNAL)
2926 sevp.sigev_notify = SIGEV_SIGNAL;
2927 0 ▶ SvGETMAGIC(sig);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sig); 0 0 0
SvGETMAGIC(sig); 0 0 0
2928 0 sevp.sigev_signo = (int)SvIV(sig);
2929 }
2930 else if (SIGEV_NONE) {
2931 0 sevp.sigev_notify = SIGEV_NONE;
2932 }
2933 0 rv = timer_create(clockid, &sevp, &timerid);
2934 0 ▶ RETVAL = (rv == 0) ? timerid : (timer_t)0;
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = (rv == 0) ? timerid : (timer_t)0; 0 0 0
RETVAL = (rv == 0) ? timerid : (timer_t)0; 0 0 0
2935 }
2936 OUTPUT:
2937 RETVAL
2938  
2939 #endif
2940  
2941 #ifdef PSX2008_HAS_TIMER_DELETE
2942 SysRetTrue
2943 timer_delete(timer_t timerid);
2944  
2945 #endif
2946  
2947 #ifdef PSX2008_HAS_TIMER_GETOVERRUN
2948 SysRet0
2949 timer_getoverrun(timer_t timerid);
2950  
2951 #endif
2952  
2953 #ifdef PSX2008_HAS_TIMER_GETTIME
2954 void
2955 timer_gettime(timer_t timerid);
2956 PPCODE:
2957 {
2958 struct itimerspec curr_value;
2959 0 int rv = timer_gettime(timerid, &curr_value);
2960 0 ▶ if (rv == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv == 0) { 0 0 0
2961 0 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 0 0
2962 0 mPUSHs(newSViv(curr_value.it_interval.tv_sec));
2963 0 mPUSHs(newSViv(curr_value.it_interval.tv_nsec));
2964 0 mPUSHs(newSViv(curr_value.it_value.tv_sec));
2965 0 mPUSHs(newSViv(curr_value.it_value.tv_nsec));
2966 }
2967 }
2968  
2969 #endif
2970  
2971 #ifdef PSX2008_HAS_TIMER_SETTIME
2972 void
2973 timer_settime(timer_t timerid, int flags, \
2974 Time_t interval_sec, long interval_nsec, \
2975 Time_t initial_sec=-1, long initial_nsec=-1);
2976 PROTOTYPE: $$@
2977 PREINIT:
2978 struct itimerspec new_value, old_value;
2979 int rv;
2980 PPCODE:
2981 {
2982 0 new_value.it_interval.tv_sec = interval_sec;
2983 0 new_value.it_interval.tv_nsec = interval_nsec;
2984 0 ▶ if (initial_sec < 0 || initial_nsec < 0)
Branch: 2 branches
BranchTrueFalseTotal
if (initial_sec < 0 || initial_nsec < 0) 0 0 0
if (initial_sec < 0 || initial_nsec < 0) 0 0 0
2985 0 new_value.it_value = new_value.it_interval;
2986 else {
2987 0 new_value.it_value.tv_sec = initial_sec;
2988 0 new_value.it_value.tv_nsec = initial_nsec;
2989 }
2990  
2991 0 rv = timer_settime(timerid, flags, &new_value, &old_value);
2992 0 ▶ if (rv == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv == 0) { 0 0 0
2993 0 mPUSHs(newSViv(old_value.it_interval.tv_sec));
2994 0 mPUSHs(newSViv(old_value.it_interval.tv_nsec));
2995 0 mPUSHs(newSViv(old_value.it_value.tv_sec));
2996 0 mPUSHs(newSViv(old_value.it_value.tv_nsec));
2997 }
2998 }
2999  
3000 #endif
3001  
3002 ## I/O-related functions
3003 ########################
3004  
3005 #ifdef PSX2008_HAS_CHDIR
3006 SysRetTrue
3007 chdir(SV *what);
3008 CODE:
3009 {
3010 2 ▶ SvGETMAGIC(what);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(what); 0 2 2
SvGETMAGIC(what); 0 0 0
3011 2 ▶ if (!SvOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(what)) { 0 2 2
3012 0 SETERRNO(ENOENT, RMS$_DNF);
3013 0 RETVAL = -1;
3014 }
3015 2 ▶ else if (SvPOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvPOK(what)) { 2 0 2
3016 STRLEN len;
3017 2 const char *path = SvPV_nomg_const(what, len);
3018 2 ▶ RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chdir(path) : -1;
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chdir(path) : -1; 2 0 2
RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chdir(path) : -1; 0 2 2
RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chdir(path) : -1; 2 0 2
3019 }
3020 else {
3021 #ifdef PSX2008_HAS_FCHDIR
3022 0 int fd = _psx_fileno_nomg(aTHX_ what, NULL);
3023 0 RETVAL = fchdir(fd);
3024 #else
3025 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
3026 RETVAL = -1;
3027 #endif
3028 }
3029 }
3030 OUTPUT:
3031 RETVAL
3032  
3033 #endif
3034  
3035 #ifdef PSX2008_HAS_CHMOD
3036 SysRetTrue
3037 chmod(SV *what, mode_t mode);
3038 CODE:
3039 {
3040 0 ▶ SvGETMAGIC(what);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(what); 0 0 0
SvGETMAGIC(what); 0 0 0
3041 0 ▶ if (!SvOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(what)) { 0 0 0
3042 0 SETERRNO(ENOENT, RMS$_FNF);
3043 0 RETVAL = -1;
3044 }
3045 0 ▶ else if (SvPOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvPOK(what)) { 0 0 0
3046 STRLEN len;
3047 0 const char *path = SvPV_nomg_const(what, len);
3048 0 ▶ RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chmod(path, mode) : -1;
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chmod(path, mode) : -1; 0 0 0
RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chmod(path, mode) : -1; 0 0 0
RETVAL = IS_SAFE_PATHNAME(path, len, cv) ? chmod(path, mode) : -1; 0 0 0
3049 }
3050 else {
3051 #ifdef PSX2008_HAS_FCHMOD
3052 0 int fd = _psx_fileno_nomg(aTHX_ what, NULL);
3053 0 RETVAL = fchmod(fd, mode);
3054 #else
3055 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
3056 RETVAL = -1;
3057 #endif
3058 }
3059 }
3060 OUTPUT:
3061 RETVAL
3062  
3063 #endif
3064  
3065 #ifdef PSX2008_HAS_CHOWN
3066 SysRetTrue
3067 chown(SV *what, uid_t owner, gid_t group);
3068 CODE:
3069 {
3070 0 ▶ SvGETMAGIC(what);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(what); 0 0 0
SvGETMAGIC(what); 0 0 0
3071 0 ▶ if (!SvOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(what)) { 0 0 0
3072 0 SETERRNO(ENOENT, RMS$_FNF);
3073 0 RETVAL = -1;
3074 }
3075 0 ▶ else if (SvPOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvPOK(what)) { 0 0 0
3076 STRLEN len;
3077 0 const char *path = SvPV_nomg_const(what, len);
3078 0 ▶ RETVAL = IS_SAFE_PATHNAME(path, len, cv)
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = IS_SAFE_PATHNAME(path, len, cv) 0 0 0
3079 0 ▶ ? chown(path, owner, group)
Branch: 1 branch
BranchTrueFalseTotal
? chown(path, owner, group) 0 0 0
3080 0 ▶ : -1;
Branch: 1 branch
BranchTrueFalseTotal
: -1; 0 0 0
3081 }
3082 else {
3083 #ifdef PSX2008_HAS_FCHOWN
3084 0 int fd = _psx_fileno_nomg(aTHX_ what, NULL);
3085 0 RETVAL = fchown(fd, owner, group);
3086 #else
3087 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
3088 RETVAL = -1;
3089 #endif
3090 }
3091 }
3092 OUTPUT:
3093 RETVAL
3094  
3095 #endif
3096  
3097 #ifdef PSX2008_HAS_CONFSTR
3098 void
3099 confstr(int name);
3100 INIT:
3101 0 SETERRNO(0, 0);
3102 PPCODE:
3103 {
3104 0 Size_t len = confstr(name, NULL, 0);
3105 0 ▶ if (!len && errno)
Branch: 2 branches
BranchTrueFalseTotal
if (!len && errno) 0 0 0
if (!len && errno) 0 0 0
3106 0 PUSHs(&PL_sv_undef);
3107 else {
3108 0 SV *bufsv = sv_2mortal(newSV(len + !len));
3109 0 char *cbuf = SvPVX(bufsv);
3110  
3111 0 (void)confstr(name, cbuf, len);
3112 0 cbuf[len] = '\0';
3113  
3114 0 SvCUR_set(bufsv, len - !!len);
3115 0 SvPOK_only(bufsv);
3116 0 ▶ SvTAINTED_on(bufsv);
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(bufsv); 0 0 0
3117 0 PUSHs(bufsv);
3118 }
3119 }
3120  
3121 #endif
3122  
3123 #ifdef PSX2008_HAS_PATHCONF
3124 void
3125 pathconf(SV *what, int name);
3126 PPCODE:
3127 {
3128 0 long rv = -1;
3129 0 ▶ SvGETMAGIC(what);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(what); 0 0 0
SvGETMAGIC(what); 0 0 0
3130 0 SETERRNO(0, 0); /* SvGETMAGIC() might have set errno. */
3131 0 ▶ if (UNLIKELY(!SvOK(what)))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(!SvOK(what))) 0 0 0
3132 0 SETERRNO(ENOENT, RMS_FNF);
3133 0 ▶ else if (SvPOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvPOK(what)) { 0 0 0
3134 STRLEN len;
3135 0 const char *path = SvPV_nomg_const(what, len);
3136 0 ▶ rv = IS_SAFE_PATHNAME(path, len, cv) ? pathconf(path, name) : -1;
Branch: 3 branches
BranchTrueFalseTotal
rv = IS_SAFE_PATHNAME(path, len, cv) ? pathconf(path, name) : -1; 0 0 0
rv = IS_SAFE_PATHNAME(path, len, cv) ? pathconf(path, name) : -1; 0 0 0
rv = IS_SAFE_PATHNAME(path, len, cv) ? pathconf(path, name) : -1; 0 0 0
3137 }
3138 else {
3139 #ifdef PSX2008_HAS_FPATHCONF
3140 0 int fd = _psx_fileno_nomg(aTHX_ what, NULL);
3141 0 SETERRNO(0, 0); /* _psx_fileno() might have set errno. */
3142 0 rv = fpathconf(fd, name);
3143 #else
3144 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
3145 #endif
3146 }
3147 0 ▶ if (rv < 0 && errno != 0)
Branch: 2 branches
BranchTrueFalseTotal
if (rv < 0 && errno != 0) 0 0 0
if (rv < 0 && errno != 0) 0 0 0
3148 0 PUSHs(&PL_sv_undef);
3149 else
3150 0 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 0 0
PUSH_INT_OR_PV(rv); 0 0 0
3151 }
3152  
3153 #endif
3154  
3155 #ifdef PSX2008_HAS_SYSCONF
3156 void
3157 sysconf(int name);
3158 PPCODE:
3159 {
3160 long rv;
3161 0 SETERRNO(0, 0);
3162 0 rv = sysconf(name);
3163 0 ▶ if (rv < 0 && errno != 0)
Branch: 2 branches
BranchTrueFalseTotal
if (rv < 0 && errno != 0) 0 0 0
if (rv < 0 && errno != 0) 0 0 0
3164 0 PUSHs(&PL_sv_undef);
3165 else
3166 0 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 0 0
PUSH_INT_OR_PV(rv); 0 0 0
3167 }
3168  
3169 #endif
3170  
3171 #ifdef PSX2008_HAS_TRUNCATE
3172 SysRetTrue
3173 truncate(SV *what, Off_t length);
3174 CODE:
3175 {
3176 2 ▶ SvGETMAGIC(what);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(what); 0 2 2
SvGETMAGIC(what); 0 0 0
3177 2 ▶ if (UNLIKELY(!SvOK(what))) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(!SvOK(what))) { 0 2 2
3178 0 SETERRNO(ENOENT, RMS_FNF);
3179 0 RETVAL = -1;
3180 }
3181 2 ▶ else if (SvPOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvPOK(what)) { 1 1 2
3182 STRLEN len;
3183 1 const char *path = SvPV_nomg_const(what, len);
3184 2 ▶ RETVAL = IS_SAFE_PATHNAME(path, len, cv)
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = IS_SAFE_PATHNAME(path, len, cv) 0 1 1
3185 3 ▶ ? truncate(path, length)
Branch: 1 branch
BranchTrueFalseTotal
? truncate(path, length) 1 0 1
3186 1 ▶ : -1;
Branch: 1 branch
BranchTrueFalseTotal
: -1; 1 0 1
3187 }
3188 else {
3189 #ifdef PSX2008_HAS_FTRUNCATE
3190 1 int fd = _psx_fileno_nomg(aTHX_ what, NULL);
3191 1 RETVAL = ftruncate(fd, length);
3192 #else
3193 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
3194 RETVAL = -1;
3195 #endif
3196 }
3197 }
3198 OUTPUT:
3199 RETVAL
3200  
3201 #endif
3202  
3203 #ifdef PSX2008_HAS_LCHOWN
3204 SysRetTrue
3205 lchown(psx_safepath_t__fail_undef path, uid_t owner, gid_t group);
3206  
3207 #endif
3208  
3209 #ifdef PSX2008_HAS_ACCESS
3210 SysRetTrue
3211 access(psx_safepath_t__fail_undef path, int mode);
3212  
3213 #endif
3214  
3215 #ifdef PSX2008_HAS_FDATASYNC
3216 SysRetTrue
3217 fdatasync(psx_fd_t fd);
3218  
3219 #endif
3220  
3221 #ifdef PSX2008_HAS_FSYNC
3222 SysRetTrue
3223 fsync(psx_fd_t fd);
3224  
3225 #endif
3226  
3227 #ifdef PSX2008_HAS_STAT
3228 void
3229 stat(SV *what);
3230 INIT:
3231 2 int rv = -1;
3232 struct stat buf;
3233 PPCODE:
3234 {
3235 2 ▶ SvGETMAGIC(what);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(what); 0 2 2
SvGETMAGIC(what); 0 0 0
3236 2 ▶ if (UNLIKELY(!SvOK(what)))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(!SvOK(what))) 0 2 2
3237 0 SETERRNO(ENOENT, RMS_FNF);
3238 2 ▶ else if (SvPOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvPOK(what)) { 1 1 2
3239 STRLEN len;
3240 1 const char *path = SvPV_nomg_const(what, len);
3241 1 ▶ rv = IS_SAFE_PATHNAME(path, len, cv) ? stat(path, &buf) : -1;
Branch: 3 branches
BranchTrueFalseTotal
rv = IS_SAFE_PATHNAME(path, len, cv) ? stat(path, &buf) : -1; 1 0 1
rv = IS_SAFE_PATHNAME(path, len, cv) ? stat(path, &buf) : -1; 0 1 1
rv = IS_SAFE_PATHNAME(path, len, cv) ? stat(path, &buf) : -1; 1 0 1
3242 }
3243 else {
3244 #ifdef PSX2008_HAS_FSTAT
3245 1 int fd = _psx_fileno_nomg(aTHX_ what, NULL);
3246 1 rv = fstat(fd, &buf);
3247 #else
3248 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
3249 #endif
3250 }
3251 2 ▶ RETURN_STAT_BUF(rv, buf);
Branch: 4 branches
BranchTrueFalseTotal
RETURN_STAT_BUF(rv, buf); 2 0 2
RETURN_STAT_BUF(rv, buf); 2 0 2
RETURN_STAT_BUF(rv, buf); 0 2 2
RETURN_STAT_BUF(rv, buf); 0 0 0
3252 }
3253  
3254 #endif
3255  
3256 #ifdef PSX2008_HAS_LSTAT
3257 void
3258 lstat(psx_safepath_t__fail_false_or_empty path);
3259 PPCODE:
3260 {
3261 struct stat buf;
3262 1 int rv = lstat(path, &buf);
3263 1 ▶ RETURN_STAT_BUF(rv, buf);
Branch: 4 branches
BranchTrueFalseTotal
RETURN_STAT_BUF(rv, buf); 1 0 1
RETURN_STAT_BUF(rv, buf); 1 0 1
RETURN_STAT_BUF(rv, buf); 0 1 1
RETURN_STAT_BUF(rv, buf); 0 0 0
3264 }
3265  
3266 #endif
3267  
3268 #ifdef PSX2008_HAS_STATVFS
3269 void
3270 statvfs(SV *what);
3271 INIT:
3272 2 int rv = -1;
3273 struct statvfs buf;
3274 PPCODE:
3275 {
3276 2 ▶ SvGETMAGIC(what);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(what); 0 2 2
SvGETMAGIC(what); 0 0 0
3277 2 ▶ if (!SvOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(what)) { 0 2 2
3278 0 SETERRNO(ENOENT, RMS_FNF);
3279 }
3280 2 ▶ else if (SvPOK(what)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvPOK(what)) { 1 1 2
3281 STRLEN len;
3282 1 const char *path = SvPV_nomg_const(what, len);
3283 1 ▶ rv = IS_SAFE_PATHNAME(path, len, cv) ? statvfs(path, &buf) : -1;
Branch: 3 branches
BranchTrueFalseTotal
rv = IS_SAFE_PATHNAME(path, len, cv) ? statvfs(path, &buf) : -1; 1 0 1
rv = IS_SAFE_PATHNAME(path, len, cv) ? statvfs(path, &buf) : -1; 0 1 1
rv = IS_SAFE_PATHNAME(path, len, cv) ? statvfs(path, &buf) : -1; 1 0 1
3284 }
3285 else {
3286 #ifdef PSX2008_HAS_FSTATVFS
3287 1 int fd = _psx_fileno_nomg(aTHX_ what, NULL);
3288 1 rv = fstatvfs(fd, &buf);
3289 #else
3290 SETERRNO(ENOSYS, SS$_UNSUPPORTED);
3291 #endif
3292 }
3293 2 ▶ RETURN_STATVFS_BUF(rv, buf);
Branch: 4 branches
BranchTrueFalseTotal
RETURN_STATVFS_BUF(rv, buf); 2 0 2
RETURN_STATVFS_BUF(rv, buf); 2 0 2
RETURN_STATVFS_BUF(rv, buf); 0 2 2
RETURN_STATVFS_BUF(rv, buf); 0 0 0
3294 }
3295  
3296 #endif
3297  
3298 #ifdef PSX2008_HAS_ISATTY
3299 int
3300 isatty(psx_fd_t fd);
3301  
3302 #endif
3303  
3304 #ifdef PSX2008_HAS_ISALNUM
3305 int
3306 isalnum(SV *charstring);
3307 CODE:
3308 129 ▶ ISFUNC(isalnum)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isalnum) 1 124 125
ISFUNC(isalnum) 126 3 129
ISFUNC(isalnum) 125 1 126
3309 OUTPUT:
3310 RETVAL
3311  
3312 #endif
3313  
3314 #ifdef PSX2008_HAS_ISALPHA
3315 int
3316 isalpha(SV *charstring);
3317 CODE:
3318 109 ▶ ISFUNC(isalpha)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isalpha) 1 104 105
ISFUNC(isalpha) 106 3 109
ISFUNC(isalpha) 105 1 106
3319 OUTPUT:
3320 RETVAL
3321  
3322 #endif
3323  
3324 #ifdef PSX2008_HAS_ISASCII
3325 int
3326 isascii(SV *charstring);
3327 CODE:
3328 261 ▶ ISFUNC(isascii)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isascii) 1 256 257
ISFUNC(isascii) 258 3 261
ISFUNC(isascii) 257 1 258
3329 OUTPUT:
3330 RETVAL
3331  
3332 #endif
3333  
3334 #ifdef PSX2008_HAS_ISBLANK
3335 int
3336 isblank(SV *charstring);
3337 CODE:
3338 9 ▶ ISFUNC(isblank)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isblank) 1 4 5
ISFUNC(isblank) 6 3 9
ISFUNC(isblank) 5 1 6
3339 OUTPUT:
3340 RETVAL
3341  
3342 #endif
3343  
3344 #ifdef PSX2008_HAS_ISCNTRL
3345 int
3346 iscntrl(SV *charstring);
3347 CODE:
3348 69 ▶ ISFUNC(iscntrl)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(iscntrl) 1 64 65
ISFUNC(iscntrl) 66 3 69
ISFUNC(iscntrl) 65 1 66
3349 OUTPUT:
3350 RETVAL
3351  
3352 #endif
3353  
3354 #ifdef PSX2008_HAS_ISDIGIT
3355 int
3356 isdigit(SV *charstring);
3357 CODE:
3358 25 ▶ ISFUNC(isdigit)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isdigit) 1 20 21
ISFUNC(isdigit) 22 3 25
ISFUNC(isdigit) 21 1 22
3359 OUTPUT:
3360 RETVAL
3361  
3362 #endif
3363  
3364 #ifdef PSX2008_HAS_ISGRAPH
3365 int
3366 isgraph(SV *charstring);
3367 CODE:
3368 195 ▶ ISFUNC(isgraph)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isgraph) 1 190 191
ISFUNC(isgraph) 192 3 195
ISFUNC(isgraph) 191 1 192
3369 OUTPUT:
3370 RETVAL
3371  
3372 #endif
3373  
3374 #ifdef PSX2008_HAS_ISLOWER
3375 int
3376 islower(SV *charstring);
3377 CODE:
3378 57 ▶ ISFUNC(islower)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(islower) 1 52 53
ISFUNC(islower) 54 3 57
ISFUNC(islower) 53 1 54
3379 OUTPUT:
3380 RETVAL
3381  
3382 #endif
3383  
3384 #ifdef PSX2008_HAS_ISPRINT
3385 int
3386 isprint(SV *charstring);
3387 CODE:
3388 197 ▶ ISFUNC(isprint)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isprint) 1 192 193
ISFUNC(isprint) 194 3 197
ISFUNC(isprint) 193 1 194
3389 OUTPUT:
3390 RETVAL
3391  
3392 #endif
3393  
3394 #ifdef PSX2008_HAS_ISPUNCT
3395 int
3396 ispunct(SV *charstring);
3397 CODE:
3398 71 ▶ ISFUNC(ispunct)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(ispunct) 1 66 67
ISFUNC(ispunct) 68 3 71
ISFUNC(ispunct) 67 1 68
3399 OUTPUT:
3400 RETVAL
3401  
3402 #endif
3403  
3404 #ifdef PSX2008_HAS_ISSPACE
3405 int
3406 isspace(SV *charstring);
3407 CODE:
3408 17 ▶ ISFUNC(isspace)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isspace) 1 12 13
ISFUNC(isspace) 14 3 17
ISFUNC(isspace) 13 1 14
3409 OUTPUT:
3410 RETVAL
3411  
3412 #endif
3413  
3414 #ifdef PSX2008_HAS_ISUPPER
3415 int
3416 isupper(SV *charstring);
3417 CODE:
3418 57 ▶ ISFUNC(isupper)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isupper) 1 52 53
ISFUNC(isupper) 54 3 57
ISFUNC(isupper) 53 1 54
3419 OUTPUT:
3420 RETVAL
3421  
3422 #endif
3423  
3424 #ifdef PSX2008_HAS_ISXDIGIT
3425 int
3426 isxdigit(SV *charstring);
3427 CODE:
3428 55 ▶ ISFUNC(isxdigit)
Branch: 3 branches
BranchTrueFalseTotal
ISFUNC(isxdigit) 1 50 51
ISFUNC(isxdigit) 52 3 55
ISFUNC(isxdigit) 51 1 52
3429 OUTPUT:
3430 RETVAL
3431  
3432 #endif
3433  
3434 #ifdef PSX2008_HAS_MKDTEMP
3435 void
3436 mkdtemp(SV *template_sv);
3437 PPCODE:
3438 {
3439 STRLEN len;
3440 0 const char *ctmp = SvPV_const(template_sv, len);
3441 0 ▶ if (!IS_SAFE_PATHNAME(ctmp, len, cv))
Branch: 3 branches
BranchTrueFalseTotal
if (!IS_SAFE_PATHNAME(ctmp, len, cv)) 0 0 0
if (!IS_SAFE_PATHNAME(ctmp, len, cv)) 0 0 0
if (!IS_SAFE_PATHNAME(ctmp, len, cv)) 0 0 0
3442 0 PUSHs(&PL_sv_undef);
3443 else {
3444 /* Copy the original template to avoid overwriting it. */
3445 0 SV *tmpsv = newSVpvn_flags(ctmp, len, SvUTF8(template_sv) | SVs_TEMP);
3446 0 char *dtemp = mkdtemp(SvPVX(tmpsv));
3447 0 ▶ PUSHs(LIKELY(!!dtemp) ? tmpsv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(LIKELY(!!dtemp) ? tmpsv : &PL_sv_undef); 0 0 0
3448 }
3449 }
3450  
3451 #endif
3452  
3453 #ifdef PSX2008_HAS_MKSTEMP
3454 void
3455 mkstemp(SV *template_sv);
3456 PPCODE:
3457 {
3458 STRLEN len;
3459 0 const char *ctmp = SvPV_const(template_sv, len);
3460 0 ▶ if (IS_SAFE_PATHNAME(ctmp, len, cv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (IS_SAFE_PATHNAME(ctmp, len, cv)) { 0 0 0
if (IS_SAFE_PATHNAME(ctmp, len, cv)) { 0 0 0
if (IS_SAFE_PATHNAME(ctmp, len, cv)) { 0 0 0
3461 /* Copy the original template to avoid overwriting it. */
3462 0 SV *tmpsv = newSVpvn_flags(ctmp, len, SvUTF8(template_sv) | SVs_TEMP);
3463 0 int fd = mkstemp(SvPVX(tmpsv));
3464 0 ▶ if (LIKELY(fd >= 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(fd >= 0)) { 0 0 0
3465 0 mPUSHs(newSViv(fd));
3466 0 PUSHs(tmpsv);
3467 }
3468 }
3469 }
3470  
3471 #endif
3472  
3473 #ifdef PSX2008_HAS_MKOSTEMP
3474 void
3475 mkostemp(SV *template_sv, int flags);
3476 PPCODE:
3477 {
3478 STRLEN len;
3479 0 const char *ctmp = SvPV_const(template_sv, len);
3480 0 ▶ if (IS_SAFE_PATHNAME(ctmp, len, cv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (IS_SAFE_PATHNAME(ctmp, len, cv)) { 0 0 0
if (IS_SAFE_PATHNAME(ctmp, len, cv)) { 0 0 0
if (IS_SAFE_PATHNAME(ctmp, len, cv)) { 0 0 0
3481 /* Copy the original template to avoid overwriting it. */
3482 0 SV *tmpsv = newSVpvn_flags(ctmp, len, SvUTF8(template_sv) | SVs_TEMP);
3483 0 int fd = mkostemp(SvPVX(tmpsv), flags);
3484 0 ▶ if (LIKELY(fd >= 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(fd >= 0)) { 0 0 0
3485 0 mPUSHs(newSViv(fd));
3486 0 PUSHs(tmpsv);
3487 }
3488 }
3489 }
3490  
3491 #endif
3492  
3493 #if defined(PSX2008_HAS_FDOPEN)
3494 void
3495 fdopen(IV fd, const char *mode);
3496 PPCODE:
3497 {
3498 0 SV *rv = NULL;
3499 0 ▶ if (UNLIKELY(fd < 0 || fd > PERL_INT_MAX))
Branch: 2 branches
BranchTrueFalseTotal
if (UNLIKELY(fd < 0 || fd > PERL_INT_MAX)) 0 0 0
if (UNLIKELY(fd < 0 || fd > PERL_INT_MAX)) 0 0 0
3500 0 SETERRNO(EBADF, RMS_IFI);
3501 0 ▶ else if (UNLIKELY(!mode || !*mode))
Branch: 2 branches
BranchTrueFalseTotal
else if (UNLIKELY(!mode || !*mode)) 0 0 0
else if (UNLIKELY(!mode || !*mode)) 0 0 0
3502 0 SETERRNO(EINVAL, LIB_INVARG);
3503 else
3504 0 rv = _psx_fd_to_handle(aTHX_ (int)fd, mode);
3505 0 ▶ PUSHs(rv ? rv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(rv ? rv : &PL_sv_undef); 0 0 0
3506 }
3507  
3508 #endif
3509  
3510 #if defined(PSX2008_HAS_FDOPENDIR)
3511 void
3512 fdopendir(IV fd);
3513 PPCODE:
3514 {
3515 0 SV *rv = NULL;
3516 0 ▶ if (UNLIKELY(fd < 0 || fd > PERL_INT_MAX))
Branch: 2 branches
BranchTrueFalseTotal
if (UNLIKELY(fd < 0 || fd > PERL_INT_MAX)) 0 0 0
if (UNLIKELY(fd < 0 || fd > PERL_INT_MAX)) 0 0 0
3517 0 SETERRNO(EBADF, RMS_IFI);
3518 else
3519 0 rv = _psx_fd_to_handle(aTHX_ (int)fd, NULL);
3520 0 ▶ PUSHs(rv ? rv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(rv ? rv : &PL_sv_undef); 0 0 0
3521 }
3522  
3523 #endif
3524  
3525  
3526 ##
3527 ## POSIX::open(), read() and write() return "0 but true" for 0, which
3528 ## is not quite what you would expect. We return a real 0.
3529 ##
3530  
3531 #ifdef PSX2008_HAS_CREAT
3532 SysRet0
3533 creat(psx_safepath_t__fail_undef path, mode_t mode=0666)
3534  
3535 #endif
3536  
3537 #ifdef PSX2008_HAS_OPEN
3538 SysRet0
3539 open(psx_safepath_t__fail_undef path, int oflag=O_RDONLY, mode_t mode=0666);
3540  
3541 #endif
3542  
3543 #ifdef PSX2008_HAS_OPENAT
3544 void
3545 openat(SV *dirfdsv, psx_safepath_t__fail_undef path, int flags=O_RDONLY, \
3546 mode_t mode=0666);
3547 PPCODE:
3548 {
3549 8 SV *rv = _openat50c(aTHX_ dirfdsv, path, flags, mode, NULL);
3550 7 ▶ PUSHs(rv ? rv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(rv ? rv : &PL_sv_undef); 6 1 7
3551 }
3552  
3553 #endif
3554  
3555 #ifdef PSX2008_HAS_OPENAT2
3556 void
3557 openat2(SV *dirfdsv, psx_safepath_t__fail_undef path, HV *how);
3558 PPCODE:
3559 {
3560 0 SV *rv = _openat50c(aTHX_ dirfdsv, path, 0, 0, how);
3561 0 ▶ PUSHs(rv ? rv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(rv ? rv : &PL_sv_undef); 0 0 0
3562 }
3563  
3564 #endif
3565  
3566 #ifdef PSX2008_HAS_CLOSE
3567 SysRetTrue
3568 close(SV *fd);
3569 CODE:
3570 0 RETVAL = _psx_close(aTHX_ fd);
3571 OUTPUT:
3572 RETVAL
3573  
3574 #endif
3575  
3576 #ifdef PSX2008_HAS_FACCESSAT
3577 SysRetTrue
3578 faccessat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, int amode, \
3579 int flags=0);
3580  
3581 #endif
3582  
3583 #ifdef PSX2008_HAS_FCHMODAT
3584 SysRetTrue
3585 fchmodat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, mode_t mode, \
3586 int flags=0);
3587  
3588 #endif
3589  
3590 #ifdef PSX2008_HAS_FCHOWNAT
3591 SysRetTrue
3592 fchownat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, uid_t owner, \
3593 gid_t group, int flags=0);
3594  
3595 #endif
3596  
3597 #ifdef PSX2008_HAS_FSTATAT
3598 void
3599 fstatat(psx_fd_t dirfd, psx_safepath_t__fail_false_or_empty path, int flags=0);
3600 PPCODE:
3601 {
3602 struct stat buf;
3603 2 int rv = fstatat(dirfd, path, &buf, flags);
3604 2 ▶ RETURN_STAT_BUF(rv, buf);
Branch: 4 branches
BranchTrueFalseTotal
RETURN_STAT_BUF(rv, buf); 2 0 2
RETURN_STAT_BUF(rv, buf); 2 0 2
RETURN_STAT_BUF(rv, buf); 0 2 2
RETURN_STAT_BUF(rv, buf); 0 0 0
3605 }
3606  
3607 #endif
3608  
3609 #ifdef PSX2008_HAS_LINK
3610 SysRetTrue
3611 link(psx_safepath_t__fail_undef oldpath, psx_safepath_t__fail_undef newpath);
3612  
3613 #endif
3614  
3615 #ifdef PSX2008_HAS_LINKAT
3616 SysRetTrue
3617 linkat(psx_fd_t olddirfd, psx_safepath_t__fail_undef oldpath, \
3618 psx_fd_t newdirfd, psx_safepath_t__fail_undef newpath, int flags=0);
3619  
3620 #endif
3621  
3622 #ifdef PSX2008_HAS_MKDIR
3623 SysRetTrue
3624 mkdir(psx_safepath_t__fail_undef path, mode_t mode=0777);
3625  
3626 #endif
3627  
3628 #ifdef PSX2008_HAS_MKDIRAT
3629 SysRetTrue
3630 mkdirat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, mode_t mode);
3631  
3632 #endif
3633  
3634 #ifdef PSX2008_HAS_MKFIFO
3635 SysRetTrue
3636 mkfifo(psx_safepath_t__fail_undef path, mode_t mode);
3637  
3638 #endif
3639  
3640 #ifdef PSX2008_HAS_MKFIFOAT
3641 SysRetTrue
3642 mkfifoat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, mode_t mode);
3643  
3644 #endif
3645  
3646 #ifdef PSX2008_HAS_MKNOD
3647 SysRetTrue
3648 mknod(psx_safepath_t__fail_undef path, mode_t mode, dev_t dev);
3649  
3650 #endif
3651  
3652 #ifdef PSX2008_HAS_MKNODAT
3653 SysRetTrue
3654 mknodat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, mode_t mode, dev_t dev);
3655  
3656 #endif
3657  
3658 #ifdef PSX2008_HAS_READLINK
3659 void
3660 readlink(psx_safepath_t__fail_undef path);
3661 PPCODE:
3662 {
3663 1 SV *rv = _readlink50c(aTHX_ path, NULL);
3664 1 ▶ PUSHs(rv ? rv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(rv ? rv : &PL_sv_undef); 1 0 1
3665 }
3666  
3667 #endif
3668  
3669 #ifdef PSX2008_HAS_READLINKAT
3670 void
3671 readlinkat(psx_fd_t dirfd, psx_safepath_t__fail_undef path);
3672 PPCODE:
3673 {
3674 1 SV *rv = _readlink50c(aTHX_ path, &dirfd);
3675 1 ▶ PUSHs(rv ? rv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(rv ? rv : &PL_sv_undef); 1 0 1
3676 }
3677  
3678 #endif
3679  
3680 #ifdef PSX2008_HAS_REALPATH
3681 char *
3682 realpath(psx_safepath_t__fail_undef path);
3683 CODE:
3684 1 RETVAL = realpath(path, NULL);
3685 OUTPUT:
3686 RETVAL
3687 CLEANUP:
3688 1 free(RETVAL);
3689  
3690 #endif
3691  
3692 #ifdef PSX2008_HAS_SYMLINK
3693 SysRetTrue
3694 symlink(psx_safepath_t__fail_undef target, psx_safepath_t__fail_undef linkpath);
3695  
3696 #endif
3697  
3698 #ifdef PSX2008_HAS_SYMLINKAT
3699 SysRetTrue
3700 symlinkat(psx_safepath_t__fail_undef target, psx_fd_t newdirfd, \
3701 psx_safepath_t__fail_undef linkpath);
3702  
3703 #endif
3704  
3705 #ifdef PSX2008_HAS_UTIMENSAT
3706 SysRetTrue
3707 utimensat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, int flags = 0, \
3708 Time_t atime_sec = 0, long atime_nsec = UTIME_NOW, \
3709 Time_t mtime_sec = 0, long mtime_nsec = UTIME_NOW);
3710 PROTOTYPE: $$;$@
3711 INIT:
3712 0 const struct timespec times[2] = { { atime_sec, atime_nsec },
3713 { mtime_sec, mtime_nsec } };
3714 CODE:
3715 0 RETVAL = utimensat(dirfd, path, times, flags);
3716 OUTPUT:
3717 RETVAL
3718  
3719 #endif
3720  
3721 #ifdef PSX2008_HAS_READ
3722 void
3723 read(psx_fd_t fd, SV *buf, SV *count);
3724 PREINIT:
3725 SSize_t rv;
3726 Size_t nbytes;
3727 char *cbuf;
3728 PPCODE:
3729 {
3730 3 ▶ if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */ 1 2 3
3731 1 croak(PACKNAME "::read: Negative count: %" SVf_QUOTEDPREFIX, SVfARG(count));
3732 2 nbytes = SvSTRLEN(count);
3733 2 ▶ nbytes = (nbytes > SSize_t_MAX) ? SSize_t_MAX : nbytes;
Branch: 1 branch
BranchTrueFalseTotal
nbytes = (nbytes > SSize_t_MAX) ? SSize_t_MAX : nbytes; 2 0 2
3734 2 ▶ if (UNLIKELY(SvTRULYREADONLY(buf))) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(SvTRULYREADONLY(buf))) { 0 2 2
3735 0 ▶ if (nbytes)
Branch: 1 branch
BranchTrueFalseTotal
if (nbytes) 0 0 0
3736 0 croak(PACKNAME "::read: Can't modify read-only buf");
3737 0 cbuf = NULL;
3738 }
3739 else {
3740 2 ▶ if (!SvPOK(buf))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvPOK(buf)) 1 1 2
3741 1 SvPVCLEAR(buf);
3742 (void)SvPV_force_nomg_nolen(buf);
3743 /* +1 for final '\0' to be on the safe side. */
3744 2 ▶ cbuf = SvGROW(buf, nbytes+1);
Branch: 2 branches
BranchTrueFalseTotal
cbuf = SvGROW(buf, nbytes+1); 2 0 2
cbuf = SvGROW(buf, nbytes+1); 0 2 2
3745 }
3746 2 rv = read(fd, cbuf, nbytes);
3747 2 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 2 2
3748 0 PUSHs(&PL_sv_undef);
3749 else {
3750 2 ▶ if (cbuf) {
Branch: 1 branch
BranchTrueFalseTotal
if (cbuf) { 2 0 2
3751 2 cbuf[rv] = '\0';
3752 2 SvCUR_set(buf, rv);
3753 2 SvPOK_only(buf);
3754 2 ▶ SvTAINTED_on(buf);
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(buf); 0 2 2
3755 2 ▶ SvSETMAGIC(buf);
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(buf); 0 2 2
3756 }
3757 2 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 2 2
PUSH_INT_OR_PV(rv); 2 0 2
3758 }
3759 }
3760  
3761 #endif
3762  
3763 #ifdef PSX2008_HAS_WRITE
3764 void
3765 write(psx_fd_t fd, SV *buf, SV *count=NULL);
3766 PROTOTYPE: DISABLE
3767 PPCODE:
3768 {
3769 3 ▶ if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */ 1 2 3
3770 1 croak(PACKNAME "::write: Negative count: %" SVf_QUOTEDPREFIX, SVfARG(count));
3771 else {
3772 SSize_t rv;
3773 Size_t buflen;
3774 2 const char *cbuf = SvPV_const(buf, buflen);
3775 2 Size_t nbytes = buflen;
3776 2 ▶ if (!SvIsUNDEF_onpurpose(count)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIsUNDEF_onpurpose(count)) { 1 1 2
if (!SvIsUNDEF_onpurpose(count)) { 1 0 1
3777 1 STRLEN ct = SvSTRLEN(count);
3778 1 nbytes = (nbytes > ct) ? ct : nbytes;
3779 }
3780 2 ▶ nbytes = (nbytes > SSize_t_MAX) ? SSize_t_MAX : nbytes;
Branch: 1 branch
BranchTrueFalseTotal
nbytes = (nbytes > SSize_t_MAX) ? SSize_t_MAX : nbytes; 2 0 2
3781 2 rv = write(fd, cbuf, nbytes);
3782 2 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 2 2
3783 0 PUSHs(&PL_sv_undef);
3784 else
3785 2 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 2 2
PUSH_INT_OR_PV(rv); 2 0 2
3786 }
3787 }
3788  
3789 #endif
3790  
3791 #ifdef PSX2008_HAS_READV
3792 void
3793 readv(psx_fd_t fd, SV *buffers, AV *sizes);
3794 PROTOTYPE: $\[@$]$
3795 PPCODE:
3796 {
3797 5 SSize_t rv = _readv50c(aTHX_ fd, buffers, sizes, NULL, NULL);
3798 2 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 2 2
3799 0 PUSHs(&PL_sv_undef);
3800 else
3801 2 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 2 2
PUSH_INT_OR_PV(rv); 2 0 2
3802 }
3803  
3804 #endif
3805  
3806 #ifdef PSX2008_HAS_PREADV
3807 void
3808 preadv(psx_fd_t fd, SV *buffers, AV *sizes, SV *offset=NULL);
3809 PROTOTYPE: $\[@$]$;$
3810 PPCODE:
3811 {
3812 3 SSize_t rv = _readv50c(aTHX_ fd, buffers, sizes, offset, NULL);
3813 3 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 1 2 3
3814 1 PUSHs(&PL_sv_undef);
3815 else
3816 2 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 2 2
PUSH_INT_OR_PV(rv); 2 0 2
3817 }
3818  
3819 #endif
3820  
3821  
3822 #ifdef PSX2008_HAS_PREADV2
3823 void
3824 preadv2(psx_fd_t fd, SV *buffers, AV *sizes, SV *offset=NULL, SV *flags=NULL);
3825 PROTOTYPE: $\[@$]$;$$
3826 PPCODE:
3827 {
3828 0 SSize_t rv = _readv50c(aTHX_ fd, buffers, sizes, offset, flags);
3829 0 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 0 0
3830 0 PUSHs(&PL_sv_undef);
3831 else
3832 0 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 0 0
PUSH_INT_OR_PV(rv); 0 0 0
3833 }
3834  
3835 #endif
3836  
3837 #ifdef PSX2008_HAS_WRITEV
3838 void
3839 writev(psx_fd_t fd, AV *buffers);
3840 PPCODE:
3841 {
3842 struct iovec *iov;
3843 10 int iovcnt = _psx_av2iov(aTHX_ buffers, &iov);
3844 5 ▶ SSize_t rv = LIKELY(iovcnt >= 0) ? writev(fd, iov, iovcnt) : -1;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t rv = LIKELY(iovcnt >= 0) ? writev(fd, iov, iovcnt) : -1; 5 0 5
3845 5 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 5 5
3846 0 PUSHs(&PL_sv_undef);
3847 else
3848 5 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 5 5
PUSH_INT_OR_PV(rv); 5 0 5
3849 }
3850  
3851 #endif
3852  
3853 #ifdef PSX2008_HAS_PWRITEV
3854 void
3855 pwritev(psx_fd_t fd, AV *buffers, SV *offset=NULL);
3856 PPCODE:
3857 {
3858 struct iovec *iov;
3859 2 ▶ Off_t offs = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset);
Branch: 2 branches
BranchTrueFalseTotal
Off_t offs = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 2 0 2
Off_t offs = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 2 0 2
3860 2 int iovcnt = _psx_av2iov(aTHX_ buffers, &iov);
3861 2 ▶ SSize_t rv = LIKELY(iovcnt >= 0) ? pwritev(fd, iov, iovcnt, offs) : -1;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t rv = LIKELY(iovcnt >= 0) ? pwritev(fd, iov, iovcnt, offs) : -1; 2 0 2
3862 2 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 2 2
3863 0 PUSHs(&PL_sv_undef);
3864 else
3865 2 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 2 2
PUSH_INT_OR_PV(rv); 2 0 2
3866 }
3867  
3868 #endif
3869  
3870 #ifdef PSX2008_HAS_PWRITEV2
3871 void
3872 pwritev2(psx_fd_t fd, AV *buffers, SV *offset=NULL, SV *flags=NULL);
3873 PPCODE:
3874 {
3875 struct iovec *iov;
3876 0 ▶ Off_t offs = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset);
Branch: 2 branches
BranchTrueFalseTotal
Off_t offs = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 0 0 0
Off_t offs = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 0 0 0
3877 0 ▶ int i_flags = SvIsUNDEF_onpurpose(flags) ? 0 : (int)SvIV(flags);
Branch: 2 branches
BranchTrueFalseTotal
int i_flags = SvIsUNDEF_onpurpose(flags) ? 0 : (int)SvIV(flags); 0 0 0
int i_flags = SvIsUNDEF_onpurpose(flags) ? 0 : (int)SvIV(flags); 0 0 0
3878 0 int iovcnt = _psx_av2iov(aTHX_ buffers, &iov);
3879 0 SSize_t rv =
3880 0 ▶ LIKELY(iovcnt >= 0) ? pwritev2(fd, iov, iovcnt, offs, i_flags) : -1;
Branch: 1 branch
BranchTrueFalseTotal
LIKELY(iovcnt >= 0) ? pwritev2(fd, iov, iovcnt, offs, i_flags) : -1; 0 0 0
3881 0 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 0 0
3882 0 PUSHs(&PL_sv_undef);
3883 else
3884 0 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 0 0
PUSH_INT_OR_PV(rv); 0 0 0
3885 }
3886  
3887 #endif
3888  
3889 #ifdef PSX2008_HAS_PREAD
3890 void
3891 pread(psx_fd_t fd, SV *buf, SV *count, SV *offset=NULL, SV *buf_offset=NULL);
3892 PREINIT:
3893 char *cbuf;
3894 Off_t f_offset;
3895 Size_t b_offset, nbytes;
3896 SSize_t rv;
3897 PPCODE:
3898 {
3899 5 ▶ if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */ 1 4 5
3900 1 croak(PACKNAME "::pread: Negative count: %" SVf_QUOTEDPREFIX, SVfARG(count));
3901  
3902 4 nbytes = SvSTRLEN(count);
3903 4 ▶ if (nbytes > SSize_t_MAX)
Branch: 1 branch
BranchTrueFalseTotal
if (nbytes > SSize_t_MAX) 0 4 4
3904 0 nbytes = SSize_t_MAX;
3905  
3906 4 ▶ if (UNLIKELY(SvTRULYREADONLY(buf))) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(SvTRULYREADONLY(buf))) { 0 4 4
3907 0 ▶ if (nbytes)
Branch: 1 branch
BranchTrueFalseTotal
if (nbytes) 0 0 0
3908 0 croak(PACKNAME "::pread: Can't modify read-only buf");
3909 0 cbuf = NULL;
3910 0 b_offset = 0;
3911 }
3912 else {
3913 Size_t cbuflen, new_len;
3914  
3915 4 ▶ if (!SvPOK(buf))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvPOK(buf)) 1 3 4
3916 1 SvPVCLEAR(buf);
3917 (void)SvPV_force_nomg(buf, cbuflen);
3918  
3919 /* Ensure buf_offset results in a valid string index. */
3920 4 ▶ if (SvIsUNDEF_onpurpose(buf_offset))
Branch: 2 branches
BranchTrueFalseTotal
if (SvIsUNDEF_onpurpose(buf_offset)) 2 2 4
if (SvIsUNDEF_onpurpose(buf_offset)) 0 2 2
3921 2 b_offset = 0;
3922 else {
3923 2 const bool neg = SvIsNEGATIVE(buf_offset) != 0;
3924 2 b_offset = SvSTRLEN(buf_offset);
3925 2 ▶ if (neg) {
Branch: 1 branch
BranchTrueFalseTotal
if (neg) { 2 0 2
3926 2 b_offset += cbuflen;
3927 2 ▶ if (b_offset > cbuflen)
Branch: 1 branch
BranchTrueFalseTotal
if (b_offset > cbuflen) 2 0 2
3928 2 croak(PACKNAME "::pread: buf_offset %" SVf_QUOTEDPREFIX " outside string",
3929 SVfARG(buf_offset));
3930 }
3931 }
3932  
3933 2 new_len = b_offset + nbytes;
3934 2 ▶ if (new_len < b_offset || new_len+1 == 0) /* Overflow check. */
Branch: 2 branches
BranchTrueFalseTotal
if (new_len < b_offset || new_len+1 == 0) /* Overflow check. */ 2 0 2
if (new_len < b_offset || new_len+1 == 0) /* Overflow check. */ 0 2 2
3935 0 croak(PACKNAME "::pread: buf_offset[%" SVf_QUOTEDPREFIX
3936 "] + count[%" SVf_QUOTEDPREFIX "] is too big for a Perl string",
3937 SVfARG(buf_offset), SVfARG(count));
3938  
3939 /* +1 for final '\0' to be on the safe side. */
3940 2 ▶ cbuf = SvGROW(buf, new_len+1);
Branch: 2 branches
BranchTrueFalseTotal
cbuf = SvGROW(buf, new_len+1); 2 0 2
cbuf = SvGROW(buf, new_len+1); 0 2 2
3941  
3942 /* Pad buffer with zeros if b_offset is past the buffer. */
3943 2 ▶ if (b_offset > cbuflen)
Branch: 1 branch
BranchTrueFalseTotal
if (b_offset > cbuflen) 0 2 2
3944 0 Zero(cbuf + cbuflen, b_offset - cbuflen, char);
3945 }
3946  
3947 /* Now fscking finally read teh data! */
3948 2 ▶ f_offset = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset);
Branch: 2 branches
BranchTrueFalseTotal
f_offset = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 2 0 2
f_offset = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 2 0 2
3949 2 rv = pread(fd, cbuf + b_offset, nbytes, f_offset);
3950  
3951 2 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 2 2
3952 0 PUSHs(&PL_sv_undef);
3953 else {
3954 2 ▶ if (cbuf) {
Branch: 1 branch
BranchTrueFalseTotal
if (cbuf) { 2 0 2
3955 2 cbuf[b_offset + rv] = '\0';
3956 2 SvCUR_set(buf, b_offset + rv);
3957 2 SvPOK_only(buf);
3958 2 ▶ SvTAINTED_on(buf);
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(buf); 0 2 2
3959 2 ▶ SvSETMAGIC(buf);
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(buf); 0 2 2
3960 }
3961 2 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 2 2
PUSH_INT_OR_PV(rv); 2 0 2
3962 }
3963 }
3964  
3965 #endif
3966  
3967 #ifdef PSX2008_HAS_PWRITE
3968 void
3969 pwrite(psx_fd_t fd, SV *buf, \
3970 SV *count=NULL, SV *offset=NULL, SV *buf_offset=NULL);
3971 PREINIT:
3972 Off_t f_offset;
3973 Size_t b_offset;
3974 SSize_t rv;
3975 PPCODE:
3976 {
3977 STRLEN svpv_len;
3978 7 const char *cbuf = SvPV_const(buf, svpv_len);
3979 7 STRLEN nbytes = svpv_len;
3980  
3981 /* Ensure buf_offset results in a valid string index. This is slightly
3982 * different from pread() because we can't allow offsets beyond the buffer
3983 * at all (zero is okay, though). */
3984 7 ▶ if (SvIsUNDEF_onpurpose(buf_offset))
Branch: 2 branches
BranchTrueFalseTotal
if (SvIsUNDEF_onpurpose(buf_offset)) 4 3 7
if (SvIsUNDEF_onpurpose(buf_offset)) 0 4 4
3985 3 b_offset = 0;
3986 else {
3987 /* See _psx_av2iov() for all the magic involved. */
3988 4 const STRLEN neg = ~(STRLEN)SvIsNEGATIVE(buf_offset) + 1;
3989 4 b_offset = SvSTRLEN(buf_offset);
3990 4 b_offset += neg & nbytes;
3991 4 nbytes -= b_offset;
3992 4 ▶ if (nbytes > nbytes + b_offset)
Branch: 1 branch
BranchTrueFalseTotal
if (nbytes > nbytes + b_offset) 4 0 4
3993 4 croak(PACKNAME "::pwrite: buf_offset %" SVf_QUOTEDPREFIX " outside string",
3994 SVfARG(buf_offset));
3995 }
3996  
3997 3 ▶ if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(SvIsNEGATIVE(count))) /* Performs 'get' magic. */ 1 2 3
3998 1 croak(PACKNAME "::pwrite: Negative count: %" SVf_QUOTEDPREFIX, SVfARG(count));
3999  
4000 2 ▶ if (!SvIsUNDEF_onpurpose(count)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIsUNDEF_onpurpose(count)) { 2 0 2
if (!SvIsUNDEF_onpurpose(count)) { 0 2 2
4001 0 const STRLEN ct = SvSTRLEN(count);
4002 0 ▶ if (nbytes > ct)
Branch: 1 branch
BranchTrueFalseTotal
if (nbytes > ct) 0 0 0
4003 0 nbytes = ct;
4004 }
4005 2 ▶ if (nbytes > SSize_t_MAX)
Branch: 1 branch
BranchTrueFalseTotal
if (nbytes > SSize_t_MAX) 0 2 2
4006 0 nbytes = SSize_t_MAX;
4007  
4008 2 ▶ f_offset = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset);
Branch: 2 branches
BranchTrueFalseTotal
f_offset = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 2 0 2
f_offset = SvIsUNDEF_onpurpose(offset) ? 0 : SvOFFt(offset); 2 0 2
4009 2 rv = pwrite(fd, cbuf + b_offset, nbytes, f_offset);
4010  
4011 2 ▶ if (UNLIKELY(rv < 0))
Branch: 1 branch
BranchTrueFalseTotal
if (UNLIKELY(rv < 0)) 0 2 2
4012 0 PUSHs(&PL_sv_undef);
4013 else
4014 2 ▶ PUSH_INT_OR_PV(rv);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(rv); 0 2 2
PUSH_INT_OR_PV(rv); 2 0 2
4015 }
4016  
4017 #endif
4018  
4019 #ifdef PSX2008_HAS_POSIX_FADVISE
4020 void
4021 posix_fadvise(psx_fd_t fd, Off_t offset, Off_t len, int advice);
4022 PPCODE:
4023 {
4024 0 int rv = posix_fadvise(fd, offset, len, advice);
4025 0 ▶ if (LIKELY(rv == 0))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(rv == 0)) 0 0 0
4026 0 mPUSHp("0 but true", 10);
4027 else {
4028 0 SETERRNO(rv, rv);
4029 0 PUSHs(&PL_sv_undef);
4030 }
4031 }
4032  
4033 #endif
4034  
4035 #ifdef PSX2008_HAS_POSIX_FALLOCATE
4036 void
4037 posix_fallocate(psx_fd_t fd, Off_t offset, Off_t len);
4038 PPCODE:
4039 {
4040 0 int rv = posix_fallocate(fd, offset, len);
4041 0 ▶ if (LIKELY(rv == 0))
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(rv == 0)) 0 0 0
4042 0 mPUSHp("0 but true", 10);
4043 else {
4044 0 SETERRNO(rv, rv);
4045 0 PUSHs(&PL_sv_undef);
4046 }
4047 }
4048  
4049 #endif
4050  
4051 #ifdef PSX2008_HAS_POSIX_OPENPT
4052 void
4053 posix_openpt(int flags=O_RDWR);
4054 PPCODE:
4055 {
4056 0 const char *raw = _flags2raw(flags);
4057 0 int fd = posix_openpt(flags);
4058 0 ▶ SV *rv = LIKELY(fd >= 0) ? _psx_fd_to_handle(aTHX_ fd, raw) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *rv = LIKELY(fd >= 0) ? _psx_fd_to_handle(aTHX_ fd, raw) : NULL; 0 0 0
4059 0 ▶ PUSHs(rv ? rv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(rv ? rv : &PL_sv_undef); 0 0 0
4060 }
4061  
4062 #endif
4063  
4064 #ifdef PSX2008_HAS_GRANTPT
4065 SysRetTrue
4066 grantpt(psx_fd_t fd);
4067  
4068 #endif
4069  
4070 #ifdef PSX2008_HAS_UNLOCKPT
4071 SysRetTrue
4072 unlockpt(psx_fd_t fd);
4073  
4074 #endif
4075  
4076 #ifdef PSX2008_HAS_PTSNAME
4077 void
4078 ptsname(psx_fd_t fd);
4079 PPCODE:
4080 {
4081 # ifdef PSX2008_HAS_PTSNAME_R
4082 char name[MAXPATHLEN];
4083 0 int rv = ptsname_r(fd, name, sizeof(name));
4084 0 ▶ if (LIKELY(rv == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(rv == 0)) { 0 0 0
4085 0 Size_t namelen = _strnlen(name, sizeof(name));
4086 0 mPUSHp(name, namelen);
4087 }
4088 else {
4089 /* Some implementations return -1 on error and set errno. */
4090 0 ▶ if (rv > 0) SETERRNO(rv, rv);
Branch: 1 branch
BranchTrueFalseTotal
if (rv > 0) SETERRNO(rv, rv); 0 0 0
4091 0 PUSHs(&PL_sv_undef);
4092 }
4093 # else
4094 char *name = ptsname(fd);
4095 if (LIKELY(!!name)) {
4096 Size_t namelen = _strnlen(name, MAXPATHLEN);
4097 mPUSHp(name, namelen);
4098 }
4099 else
4100 PUSHs(&PL_sv_undef);
4101 # endif
4102 }
4103  
4104 #endif
4105  
4106 #ifdef PSX2008_HAS_TTYNAME
4107 void
4108 ttyname(psx_fd_t fd);
4109 PPCODE:
4110 {
4111 # ifdef PSX2008_HAS_TTYNAME_R
4112 char name[MAXPATHLEN];
4113 0 int rv = ttyname_r(fd, name, sizeof(name));
4114 0 ▶ if (LIKELY(rv == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (LIKELY(rv == 0)) { 0 0 0
4115 0 Size_t namelen = _strnlen(name, sizeof(name));
4116 0 mPUSHp(name, namelen);
4117 }
4118 else {
4119 0 SETERRNO(rv, rv);
4120 0 PUSHs(&PL_sv_undef);
4121 }
4122 # else
4123 char *name = ttyname(fd);
4124 if (LIKELY(!!name)) {
4125 Size_t namelen = _strnlen(name, MAXPATHLEN);
4126 mPUSHp(name, namelen);
4127 }
4128 else
4129 PUSHs(&PL_sv_undef);
4130 # endif
4131 }
4132  
4133 #endif
4134  
4135 ##
4136 ## POSIX::remove() is incorrectly implemented as:
4137 ## '(-d $_[0]) ? CORE::rmdir($_[0]) : CORE::unlink($_[0])'.
4138 ##
4139 ## If $_[0] is a symlink to a directory, POSIX::remove() fails with ENOTDIR
4140 ## from rmdir() instead of removing the symlink (POSIX requires remove() to
4141 ## be equivalent to unlink() for non-directories).
4142 ##
4143 ## This could be fixed like this (correct errno check depends on OS):
4144 ## 'unlink $_[0] or ($!{EISDIR} or $!{EPERM}) and rmdir $_[0]'
4145 ##
4146 ## Or just use the actual library call like we do here.
4147 ##
4148  
4149 #if defined(__linux__) || defined(__CYGWIN__)
4150 #define UNLINK_ISDIR_ERRNO (errno == EISDIR)
4151 #elif !defined(_WIN32)
4152 #define UNLINK_ISDIR_ERRNO (errno == EISDIR || errno == EPERM)
4153 #else
4154 #define UNLINK_ISDIR_ERRNO (errno == EISDIR || errno == EPERM || errno == EACCES)
4155 #endif
4156  
4157 #if !defined(PSX2008_HAS_REMOVE) || (defined(_WIN32) && !defined(__CYGWIN__))
4158 # if defined(PSX2008_HAS_UNLINK) && defined(PSX2008_HAS_RMDIR)
4159 void
4160 remove(psx_safepath_t__fail_undef path);
4161 PPCODE:
4162 if (unlink(path) == 0 || (UNLINK_ISDIR_ERRNO && rmdir(path) == 0))
4163 mPUSHp("0 but true", 10);
4164 else
4165 PUSHs(&PL_sv_undef);
4166  
4167 # else
4168  
4169 # endif
4170 #else
4171 SysRetTrue
4172 remove(psx_safepath_t__fail_undef path);
4173  
4174 #endif
4175  
4176 #ifdef PSX2008_HAS_UNLINKAT
4177 void
4178 removeat(psx_fd_t dirfd, psx_safepath_t__fail_undef path);
4179 PPCODE:
4180 0 ▶ if (unlinkat(dirfd, path, 0) == 0
Branch: 1 branch
BranchTrueFalseTotal
if (unlinkat(dirfd, path, 0) == 0 0 0 0
4181 0 ▶ || (UNLINK_ISDIR_ERRNO && unlinkat(dirfd, path, AT_REMOVEDIR) == 0))
Branch: 2 branches
BranchTrueFalseTotal
|| (UNLINK_ISDIR_ERRNO && unlinkat(dirfd, path, AT_REMOVEDIR) == 0)) 0 0 0
|| (UNLINK_ISDIR_ERRNO && unlinkat(dirfd, path, AT_REMOVEDIR) == 0)) 0 0 0
4182 0 mPUSHp("0 but true", 10);
4183 else
4184 0 PUSHs(&PL_sv_undef);
4185  
4186 #endif
4187  
4188 #ifdef PSX2008_HAS_RENAME
4189 SysRetTrue
4190 rename(psx_safepath_t__fail_undef oldpath, psx_safepath_t__fail_undef newpath);
4191  
4192 #endif
4193  
4194 #ifdef PSX2008_HAS_RENAMEAT
4195 SysRetTrue
4196 renameat(psx_fd_t olddirfd, psx_safepath_t__fail_undef oldpath, \
4197 psx_fd_t newdirfd, psx_safepath_t__fail_undef newpath);
4198  
4199 #endif
4200  
4201 #ifdef PSX2008_HAS_RENAMEAT2
4202 SysRetTrue
4203 renameat2(psx_fd_t olddirfd, psx_safepath_t__fail_undef oldpath, \
4204 psx_fd_t newdirfd, psx_safepath_t__fail_undef newpath, \
4205 unsigned int flags=0);
4206  
4207 #endif
4208  
4209 #ifdef PSX2008_HAS_RMDIR
4210 SysRetTrue
4211 rmdir(psx_safepath_t__fail_undef path);
4212  
4213 #endif
4214  
4215 #ifdef PSX2008_HAS_UNLINK
4216 SysRetTrue
4217 unlink(psx_safepath_t__fail_undef path);
4218  
4219 #endif
4220  
4221 #ifdef PSX2008_HAS_UNLINKAT
4222 SysRetTrue
4223 unlinkat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, int flags=0);
4224  
4225 #endif
4226  
4227 #ifdef PSX2008_HAS_FUTIMENS
4228 SysRetTrue
4229 futimens(psx_fd_t fd, \
4230 Time_t atime_sec = 0, long atime_nsec = UTIME_NOW, \
4231 Time_t mtime_sec = 0, long mtime_nsec = UTIME_NOW);
4232 PROTOTYPE: $@
4233 INIT:
4234 0 const struct timespec times[2] = { { atime_sec, atime_nsec },
4235 { mtime_sec, mtime_nsec } };
4236 CODE:
4237 0 RETVAL = futimens(fd, times);
4238 OUTPUT:
4239 RETVAL
4240  
4241 #endif
4242  
4243 #ifdef PSX2008_HAS_EXECVEAT
4244 void
4245 execveat(psx_fd_t dirfd, psx_safepath_t__fail_undef path, \
4246 AV *args, SV *env=NULL, int flags=0);
4247 PPCODE:
4248 {
4249 2 _execve50c(aTHX_ dirfd, path, args, env, flags);
4250 1 PUSHs(&PL_sv_undef);
4251 }
4252  
4253 #endif
4254  
4255 #ifdef PSX2008_HAS_FEXECVE
4256 void
4257 fexecve(psx_fd_t fd, AV *args, SV *env=NULL);
4258 PPCODE:
4259 {
4260 2 _execve50c(aTHX_ fd, NULL, args, env, 0);
4261 1 PUSHs(&PL_sv_undef);
4262 }
4263  
4264 #endif
4265  
4266 #ifdef PSX2008_HAS_POLL
4267 void
4268 poll(SV *pollfds, int timeout=-1);
4269 PPCODE:
4270 {
4271 3 int rv = _poll50c(aTHX_ pollfds, timeout, NULL);
4272 3 mPUSHs(newSViv(rv));
4273 }
4274  
4275 #endif
4276  
4277 #ifdef PSX2008_HAS_PPOLL
4278 void
4279 ppoll(SV *pollfds, SV *timeout=NULL, SV *sigmask=NULL);
4280 PREINIT:
4281 int rv;
4282 3 struct timespec tmo = {0};
4283 3 ▶ struct psx_ppollspec ppspec = {0};
Branch: 1 branch
BranchTrueFalseTotal
struct psx_ppollspec ppspec = {0}; 0 3 3
4284 PPCODE:
4285 {
4286 /* See POSIX::sigprocmask(). Can't be wrong [TM]. */
4287 3 ▶ if (sigmask && SvOK(sigmask)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sigmask && SvOK(sigmask)) { 0 3 3
if (sigmask && SvOK(sigmask)) { 0 0 0
4288 0 ▶ if (sv_isa(sigmask, "POSIX::SigSet")) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isa(sigmask, "POSIX::SigSet")) { 0 0 0
4289 #if PERL_BCDVERSION >= 0x5016000
4290 0 ppspec.sigmask = (sigset_t*)SvPV_nolen(SvRV(sigmask));
4291 #else
4292 IV tmp = SvIV((SV*)SvRV(sigmask));
4293 ppspec.sigmask = INT2PTR(sigset_t*, tmp);
4294 #endif
4295 }
4296 else
4297 0 croak(PACKNAME "::ppoll: sigmask is not a POSIX::SigSet");
4298 }
4299 3 ▶ if (timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (timeout) { 3 0 3
4300 3 ▶ SvGETMAGIC(timeout);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(timeout); 0 3 3
SvGETMAGIC(timeout); 0 0 0
4301 3 ▶ if (SvOK(timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(timeout)) { 3 0 3
4302 3 ppspec.tmo_p = &tmo;
4303 3 ▶ if (SvIsARRAY(timeout)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIsARRAY(timeout)) { 0 3 3
if (SvIsARRAY(timeout)) { 0 0 0
4304 SV **sec_sv, **nsec_sv;
4305 0 AV *timeout_av = (AV*)SvRV(timeout);
4306 0 sec_sv = av_fetch(timeout_av, 0, 0);
4307 0 ▶ if (sec_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (sec_sv) 0 0 0
4308 0 tmo.tv_sec = SvIV(*sec_sv);
4309 0 nsec_sv = av_fetch(timeout_av, 1, 0);
4310 0 ▶ if (nsec_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (nsec_sv) 0 0 0
4311 0 tmo.tv_nsec = SvIV(*nsec_sv);
4312 }
4313 3 ▶ else if (LOOKS_LIKE_NV(timeout))
Branch: 6 branches
BranchTrueFalseTotal
else if (LOOKS_LIKE_NV(timeout)) 3 0 3
else if (LOOKS_LIKE_NV(timeout)) 0 3 3
else if (LOOKS_LIKE_NV(timeout)) 0 0 0
else if (LOOKS_LIKE_NV(timeout)) 0 0 0
else if (LOOKS_LIKE_NV(timeout)) 0 0 0
else if (LOOKS_LIKE_NV(timeout)) 0 0 0
4314 0 ▶ TIMESPEC_FROM_NV_nomg(tmo, timeout);
Branch: 1 branch
BranchTrueFalseTotal
TIMESPEC_FROM_NV_nomg(tmo, timeout); 0 0 0
4315 else
4316 3 TIMESPEC_FROM_IV_nomg(tmo, timeout, 0);
4317 }
4318 }
4319 3 rv = _poll50c(aTHX_ pollfds, 0, &ppspec);
4320 3 mPUSHs(newSViv(rv));
4321 }
4322  
4323 #endif
4324  
4325 ## Integer and real number arithmetic
4326 #####################################
4327  
4328 ## We rely on Makefile.PL to set HAS_xxL/Q only if long double or quadmath
4329 ## is actually in use (i.e. USE_LONG_DOUBLE/USE_QUADMATH). For most math
4330 ## functions we use the existence of sqrtl/q to decide which variant to use.
4331 ############################################################################
4332  
4333 #ifdef PSX2008_ABS
4334 IV
4335 abs(IV i)
4336 CODE:
4337 0 ▶ RETVAL = PSX2008_ABS(i);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PSX2008_ABS(i); 0 0 0
4338 OUTPUT:
4339 RETVAL
4340  
4341 #endif
4342  
4343 #ifdef PSX2008_HAS_ACOS
4344 NV
4345 acos(NV x);
4346 CODE:
4347 # if defined(PSX2008_HAS_SQRTQ)
4348 RETVAL = acosq(x);
4349 # elif defined(PSX2008_HAS_SQRTL)
4350 RETVAL = acosl(x);
4351 # else
4352 2 ▶ RETVAL = acos(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = acos(x); 0 2 2
4353 # endif
4354 OUTPUT:
4355 RETVAL
4356  
4357 #endif
4358  
4359 #ifdef PSX2008_HAS_ACOSH
4360 NV
4361 acosh(NV x);
4362 CODE:
4363 # if defined(PSX2008_HAS_SQRTQ)
4364 RETVAL = acoshq(x);
4365 # elif defined(PSX2008_HAS_SQRTL)
4366 RETVAL = acoshl(x);
4367 # else
4368 2 ▶ RETVAL = acosh(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = acosh(x); 0 2 2
4369 # endif
4370 OUTPUT:
4371 RETVAL
4372  
4373 #endif
4374  
4375 #ifdef PSX2008_HAS_ASIN
4376 NV
4377 asin(NV x);
4378 CODE:
4379 # if defined(PSX2008_HAS_SQRTQ)
4380 RETVAL = asinq(x);
4381 # elif defined(PSX2008_HAS_SQRTL)
4382 RETVAL = asinl(x);
4383 # else
4384 4 ▶ RETVAL = asin(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = asin(x); 0 4 4
4385 # endif
4386 OUTPUT:
4387 RETVAL
4388  
4389 #endif
4390  
4391 #ifdef PSX2008_HAS_ASINH
4392 NV
4393 asinh(NV x);
4394 CODE:
4395 # if defined(PSX2008_HAS_SQRTQ)
4396 RETVAL = asinhq(x);
4397 # elif defined(PSX2008_HAS_SQRTL)
4398 RETVAL = asinhl(x);
4399 # else
4400 4 ▶ RETVAL = asinh(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = asinh(x); 0 4 4
4401 # endif
4402 OUTPUT:
4403 RETVAL
4404  
4405 #endif
4406  
4407 #ifdef PSX2008_HAS_ATAN
4408 NV
4409 atan(NV x);
4410 CODE:
4411 # if defined(PSX2008_HAS_SQRTQ)
4412 RETVAL = atanq(x);
4413 # elif defined(PSX2008_HAS_SQRTL)
4414 RETVAL = atanl(x);
4415 # else
4416 5 ▶ RETVAL = atan(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = atan(x); 0 5 5
4417 # endif
4418 OUTPUT:
4419 RETVAL
4420  
4421 #endif
4422  
4423 #ifdef PSX2008_HAS_ATAN2
4424 NV
4425 atan2(NV y, NV x);
4426 CODE:
4427 # if defined(PSX2008_HAS_SQRTQ)
4428 RETVAL = atan2q(y, x);
4429 # elif defined(PSX2008_HAS_SQRTL)
4430 RETVAL = atan2l(y, x);
4431 # else
4432 5 ▶ RETVAL = atan2(y, x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = atan2(y, x); 0 5 5
4433 # endif
4434 OUTPUT:
4435 RETVAL
4436  
4437 #endif
4438  
4439 #ifdef PSX2008_HAS_ATANH
4440 NV
4441 atanh(NV x);
4442 CODE:
4443 # if defined(PSX2008_HAS_SQRTQ)
4444 RETVAL = atanhq(x);
4445 # elif defined(PSX2008_HAS_SQRTL)
4446 RETVAL = atanhl(x);
4447 # else
4448 4 ▶ RETVAL = atanh(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = atanh(x); 0 4 4
4449 # endif
4450 OUTPUT:
4451 RETVAL
4452  
4453 #endif
4454  
4455 #ifdef PSX2008_HAS_CBRT
4456 NV
4457 cbrt(NV x);
4458 CODE:
4459 # if defined(PSX2008_HAS_SQRTQ)
4460 RETVAL = cbrtq(x);
4461 # elif defined(PSX2008_HAS_SQRTL)
4462 RETVAL = cbrtl(x);
4463 # else
4464 2 ▶ RETVAL = cbrt(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = cbrt(x); 0 2 2
4465 # endif
4466 OUTPUT:
4467 RETVAL
4468  
4469 #endif
4470  
4471 #ifdef PSX2008_HAS_CEIL
4472 NV
4473 ceil(NV x);
4474 CODE:
4475 # if defined(PSX2008_HAS_SQRTQ)
4476 RETVAL = ceilq(x);
4477 # elif defined(PSX2008_HAS_SQRTL)
4478 RETVAL = ceill(x);
4479 # else
4480 1 ▶ RETVAL = ceil(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ceil(x); 0 1 1
4481 # endif
4482 OUTPUT:
4483 RETVAL
4484  
4485 #endif
4486  
4487 #ifdef PSX2008_HAS_COPYSIGN
4488 NV
4489 copysign(NV x, NV y);
4490 CODE:
4491 # if defined(PSX2008_HAS_SQRTQ)
4492 RETVAL = copysignq(x, y);
4493 # elif defined(PSX2008_HAS_SQRTL)
4494 RETVAL = copysignl(x, y);
4495 # else
4496 0 ▶ RETVAL = copysign(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = copysign(x, y); 0 0 0
4497 # endif
4498 OUTPUT:
4499 RETVAL
4500  
4501 #endif
4502  
4503 #ifdef PSX2008_HAS_COS
4504 NV
4505 cos(NV x);
4506 CODE:
4507 # if defined(PSX2008_HAS_SQRTQ)
4508 RETVAL = cosq(x);
4509 # elif defined(PSX2008_HAS_SQRTL)
4510 RETVAL = cosl(x);
4511 # else
4512 4 ▶ RETVAL = cos(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = cos(x); 0 4 4
4513 # endif
4514 OUTPUT:
4515 RETVAL
4516  
4517 #endif
4518  
4519 #ifdef PSX2008_HAS_COSH
4520 NV
4521 cosh(NV x);
4522 CODE:
4523 # if defined(PSX2008_HAS_SQRTQ)
4524 RETVAL = coshq(x);
4525 # elif defined(PSX2008_HAS_SQRTL)
4526 RETVAL = coshl(x);
4527 # else
4528 4 ▶ RETVAL = cosh(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = cosh(x); 0 4 4
4529 # endif
4530 OUTPUT:
4531 RETVAL
4532  
4533 #endif
4534  
4535 #ifdef PSX2008_DIV
4536 void
4537 div(IV numer, IV denom);
4538 PPCODE:
4539 {
4540 0 PSX2008_DIV_T result = PSX2008_DIV(numer, denom);
4541 0 mPUSHs(newSViv(result.quot));
4542 0 mPUSHs(newSViv(result.rem));
4543 }
4544  
4545 #endif
4546  
4547 #ifdef PSX2008_HAS_ERF
4548 NV
4549 erf(NV x);
4550 CODE:
4551 # if defined(PSX2008_HAS_SQRTQ)
4552 RETVAL = erfq(x);
4553 # elif defined(PSX2008_HAS_ERFL)
4554 RETVAL = erfl(x);
4555 # else
4556 4 ▶ RETVAL = erf(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = erf(x); 0 4 4
4557 # endif
4558 OUTPUT:
4559 RETVAL
4560  
4561 #endif
4562  
4563 #ifdef PSX2008_HAS_ERFC
4564 NV
4565 erfc(NV x);
4566 CODE:
4567 # if defined(PSX2008_HAS_SQRTQ)
4568 RETVAL = erfcq(x);
4569 # elif defined(PSX2008_HAS_ERFCL)
4570 RETVAL = erfcl(x);
4571 # else
4572 2 ▶ RETVAL = erfc(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = erfc(x); 0 2 2
4573 # endif
4574 OUTPUT:
4575 RETVAL
4576  
4577 #endif
4578  
4579 #ifdef PSX2008_HAS_EXP
4580 NV
4581 exp(NV x);
4582 CODE:
4583 # if defined(PSX2008_HAS_SQRTQ)
4584 RETVAL = expq(x);
4585 # elif defined(PSX2008_HAS_SQRTL)
4586 RETVAL = expl(x);
4587 # else
4588 2 ▶ RETVAL = exp(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = exp(x); 0 2 2
4589 # endif
4590 OUTPUT:
4591 RETVAL
4592  
4593 #endif
4594  
4595 #if defined(PSX2008_HAS_EXP2) && (!defined(USE_QUADMATH) || defined(PSX2008_HAS_EXP2Q))
4596 NV
4597 exp2(NV x);
4598 CODE:
4599 # if defined(PSX2008_HAS_EXP2Q)
4600 RETVAL = exp2q(x);
4601 # elif defined(PSX2008_HAS_SQRTL)
4602 RETVAL = exp2l(x);
4603 # else
4604 3 ▶ RETVAL = exp2(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = exp2(x); 0 3 3
4605 # endif
4606 OUTPUT:
4607 RETVAL
4608  
4609 #endif
4610  
4611 #ifdef PSX2008_HAS_EXPM1
4612 NV
4613 expm1(NV x);
4614 CODE:
4615 # if defined(PSX2008_HAS_SQRTQ)
4616 RETVAL = expm1q(x);
4617 # elif defined(PSX2008_HAS_SQRTL)
4618 RETVAL = expm1l(x);
4619 # else
4620 2 ▶ RETVAL = expm1(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = expm1(x); 0 2 2
4621 # endif
4622 OUTPUT:
4623 RETVAL
4624  
4625 #endif
4626  
4627 #ifdef PSX2008_HAS_FABS
4628 NV
4629 fabs(NV x);
4630 CODE:
4631 # if defined(PSX2008_HAS_SQRTQ)
4632 RETVAL = fabsq(x);
4633 # elif defined(PSX2008_HAS_SQRTL)
4634 RETVAL = fabsl(x);
4635 # else
4636 4 ▶ RETVAL = fabs(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = fabs(x); 0 4 4
4637 # endif
4638 OUTPUT:
4639 RETVAL
4640  
4641 #endif
4642  
4643 #ifdef PSX2008_HAS_FDIM
4644 NV
4645 fdim(NV x, NV y);
4646 CODE:
4647 # if defined(PSX2008_HAS_SQRTQ)
4648 RETVAL = fdimq(x, y);
4649 # elif defined(PSX2008_HAS_SQRTL)
4650 RETVAL = fdiml(x, y);
4651 # else
4652 2 ▶ RETVAL = fdim(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = fdim(x, y); 0 2 2
4653 # endif
4654 OUTPUT:
4655 RETVAL
4656  
4657 #endif
4658  
4659 #ifdef PSX2008_HAS_FLOOR
4660 NV
4661 floor(NV x);
4662 CODE:
4663 # if defined(PSX2008_HAS_SQRTQ)
4664 RETVAL = floorq(x);
4665 # elif defined(PSX2008_HAS_SQRTL)
4666 RETVAL = floorl(x);
4667 # else
4668 2 ▶ RETVAL = floor(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = floor(x); 0 2 2
4669 # endif
4670 OUTPUT:
4671 RETVAL
4672  
4673 #endif
4674  
4675 #ifdef PSX2008_HAS_FMA
4676 NV
4677 fma(NV x, NV y, NV z);
4678 CODE:
4679 # if defined(PSX2008_HAS_SQRTQ)
4680 RETVAL = fmaq(x, y, z);
4681 # elif defined(PSX2008_HAS_SQRTL)
4682 RETVAL = fmal(x, y, z);
4683 # else
4684 2 ▶ RETVAL = fma(x, y, z);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = fma(x, y, z); 0 2 2
4685 # endif
4686 OUTPUT:
4687 RETVAL
4688  
4689 #endif
4690  
4691 #ifdef PSX2008_HAS_FMAX
4692 NV
4693 fmax(NV x, NV y);
4694 CODE:
4695 # if defined(PSX2008_HAS_SQRTQ)
4696 RETVAL = fmaxq(x, y);
4697 # elif defined(PSX2008_HAS_SQRTL)
4698 RETVAL = fmaxl(x, y);
4699 # else
4700 2 ▶ RETVAL = fmax(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = fmax(x, y); 0 2 2
4701 # endif
4702 OUTPUT:
4703 RETVAL
4704  
4705 #endif
4706  
4707 #ifdef PSX2008_HAS_FMIN
4708 NV
4709 fmin(NV x, NV y);
4710 CODE:
4711 # if defined(PSX2008_HAS_SQRTQ)
4712 RETVAL = fminq(x, y);
4713 # elif defined(PSX2008_HAS_SQRTL)
4714 RETVAL = fminl(x, y);
4715 # else
4716 2 ▶ RETVAL = fmin(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = fmin(x, y); 0 2 2
4717 # endif
4718 OUTPUT:
4719 RETVAL
4720  
4721 #endif
4722  
4723 #ifdef PSX2008_HAS_FMOD
4724 NV
4725 fmod(NV x, NV y);
4726 CODE:
4727 # if defined(PSX2008_HAS_SQRTQ)
4728 RETVAL = fmodq(x, y);
4729 # elif defined(PSX2008_HAS_SQRTL)
4730 RETVAL = fmodl(x, y);
4731 # else
4732 1 ▶ RETVAL = fmod(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = fmod(x, y); 0 1 1
4733 # endif
4734 OUTPUT:
4735 RETVAL
4736  
4737 #endif
4738  
4739 #ifdef PSX2008_HAS_FPCLASSIFY
4740 int
4741 fpclassify(NV x);
4742  
4743 #endif
4744  
4745 #ifdef PSX2008_HAS_FREXP
4746 void
4747 frexp(NV x);
4748 PPCODE:
4749 {
4750 NV fr;
4751 int exp;
4752 # if defined(PSX2008_HAS_SQRTQ)
4753 fr = frexpq(x, &exp);
4754 # elif defined(PSX2008_HAS_SQRTL)
4755 fr = frexpl(x, &exp);
4756 # else
4757 1 fr = frexp(x, &exp);
4758 # endif
4759 1 mPUSHs(newSVnv(fr));
4760 1 mPUSHs(newSVnv(exp));
4761 }
4762  
4763 #endif
4764  
4765 #ifdef PSX2008_HAS_HYPOT
4766 NV
4767 hypot(NV x, NV y);
4768 CODE:
4769 # if defined(PSX2008_HAS_SQRTQ)
4770 RETVAL = hypotq(x, y);
4771 # elif defined(PSX2008_HAS_SQRTL)
4772 RETVAL = hypotl(x, y);
4773 # else
4774 1 ▶ RETVAL = hypot(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = hypot(x, y); 0 1 1
4775 # endif
4776 OUTPUT:
4777 RETVAL
4778  
4779 #endif
4780  
4781 #ifdef PSX2008_HAS_ILOGB
4782 NV
4783 ilogb(NV x);
4784 CODE:
4785 # if defined(PSX2008_HAS_SQRTQ)
4786 RETVAL = ilogbq(x);
4787 # elif defined(PSX2008_HAS_SQRTL)
4788 RETVAL = ilogbl(x);
4789 # else
4790 2 ▶ RETVAL = ilogb(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ilogb(x); 0 2 2
4791 # endif
4792 OUTPUT:
4793 RETVAL
4794  
4795 #endif
4796  
4797 #ifdef PSX2008_HAS_ISFINITE
4798 int
4799 isfinite(NV x);
4800 CODE:
4801 # if defined(PSX2008_HAS_FINITEQ)
4802 RETVAL = finiteq(x);
4803 # elif defined(PSX2008_HAS_ISFINITEL)
4804 RETVAL = isfinitel(x);
4805 # else
4806 4 ▶ RETVAL = isfinite(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = isfinite(x); 0 4 4
4807 # endif
4808 OUTPUT:
4809 RETVAL
4810  
4811 #endif
4812  
4813 #ifdef PSX2008_HAS_ISINF
4814 int
4815 isinf(NV x);
4816 CODE:
4817 # if defined(PSX2008_HAS_ISINFQ)
4818 RETVAL = isinfq(x);
4819 # elif defined(PSX2008_HAS_ISINFL)
4820 RETVAL = isinfl(x);
4821 # else
4822 4 ▶ RETVAL = isinf(x);
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = isinf(x); 2 2 4
RETVAL = isinf(x); 1 1 2
RETVAL = isinf(x); 0 4 4
4823 # endif
4824 OUTPUT:
4825 RETVAL
4826  
4827 #endif
4828  
4829 #ifdef PSX2008_HAS_ISNAN
4830 int
4831 isnan(NV x);
4832 CODE:
4833 # if defined(PSX2008_HAS_ISNANQ)
4834 RETVAL = isnanq(x);
4835 # elif defined(PSX2008_HAS_ISNANL)
4836 RETVAL = isnanl(x);
4837 # else
4838 4 ▶ RETVAL = isnan(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = isnan(x); 0 4 4
4839 # endif
4840 OUTPUT:
4841 RETVAL
4842  
4843 #endif
4844  
4845 #ifdef PSX2008_HAS_ISNORMAL
4846 int
4847 isnormal(NV x);
4848  
4849 #endif
4850  
4851 #ifdef PSX2008_HAS_ISLESS
4852 int
4853 isless(NV x, NV y);
4854  
4855 #endif
4856  
4857 #ifdef PSX2008_HAS_ISLESSEQUAL
4858 int
4859 islessequal(NV x, NV y);
4860  
4861 #endif
4862  
4863 #ifdef PSX2008_HAS_ISGREATEREQUAL
4864 int
4865 isgreaterequal(NV x, NV y);
4866  
4867 #endif
4868  
4869 #ifdef PSX2008_HAS_ISLESSGREATER
4870 int
4871 islessgreater(NV x, NV y);
4872  
4873 #endif
4874  
4875 #ifdef PSX2008_HAS_ISUNORDERED
4876 int
4877 isunordered(NV x, NV y);
4878  
4879 #endif
4880  
4881 #ifdef PSX2008_HAS_J0
4882 NV
4883 j0(NV x);
4884 CODE:
4885 # if defined(PSX2008_HAS_SQRTQ)
4886 RETVAL = j0q(x);
4887 # elif defined(PSX2008_HAS_J0L) && !defined(__MINGW32__)
4888 RETVAL = j0l(x);
4889 # else
4890 3 ▶ RETVAL = j0(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = j0(x); 0 3 3
4891 # endif
4892 OUTPUT:
4893 RETVAL
4894  
4895 #endif
4896  
4897 #ifdef PSX2008_HAS_J1
4898 NV
4899 j1(NV x);
4900 CODE:
4901 # if defined(PSX2008_HAS_SQRTQ)
4902 RETVAL = j1q(x);
4903 # elif defined(PSX2008_HAS_J1L) && !defined(__MINGW32__)
4904 RETVAL = j1l(x);
4905 # else
4906 3 ▶ RETVAL = j1(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = j1(x); 0 3 3
4907 # endif
4908 OUTPUT:
4909 RETVAL
4910  
4911 #endif
4912  
4913 #if defined(PSX2008_HAS_JN)
4914 NV
4915 jn(int n, NV x);
4916 CODE:
4917 # if defined(PSX2008_HAS_SQRTQ)
4918 RETVAL = jnq(n, x);
4919 # elif defined(PSX2008_HAS_JNL) && !defined(__MINGW32__)
4920 RETVAL = jnl(n, x);
4921 # else
4922 3 ▶ RETVAL = jn(n, x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = jn(n, x); 0 3 3
4923 # endif
4924 OUTPUT:
4925 RETVAL
4926  
4927 #endif
4928  
4929 #if defined(PSX2008_HAS_LDEXP)
4930 NV
4931 ldexp(NV x, int exp);
4932 CODE:
4933 # if defined(PSX2008_HAS_SQRTQ)
4934 RETVAL = ldexpq(x, exp);
4935 # elif defined(PSX2008_HAS_SQRTL)
4936 RETVAL = ldexpl(x, exp);
4937 # else
4938 2 ▶ RETVAL = ldexp(x, exp);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ldexp(x, exp); 0 2 2
4939 # endif
4940 OUTPUT:
4941 RETVAL
4942  
4943 #endif
4944  
4945 #ifdef PSX2008_HAS_LGAMMA
4946 NV
4947 lgamma(NV x);
4948 CODE:
4949 # if defined(PSX2008_HAS_SQRTQ)
4950 RETVAL = lgammaq(x);
4951 # elif defined(PSX2008_HAS_LGAMMAL)
4952 RETVAL = lgammal(x);
4953 # else
4954 2 ▶ RETVAL = lgamma(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = lgamma(x); 0 2 2
4955 # endif
4956 OUTPUT:
4957 RETVAL
4958  
4959 #endif
4960  
4961 #ifdef PSX2008_HAS_LOG
4962 NV
4963 log(NV x);
4964 CODE:
4965 # if defined(PSX2008_HAS_SQRTQ)
4966 RETVAL = logq(x);
4967 # elif defined(PSX2008_HAS_SQRTL)
4968 RETVAL = logl(x);
4969 # else
4970 2 ▶ RETVAL = log(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = log(x); 0 2 2
4971 # endif
4972 OUTPUT:
4973 RETVAL
4974  
4975 #endif
4976  
4977 #ifdef PSX2008_HAS_LOG10
4978 NV
4979 log10(NV x);
4980 CODE:
4981 # if defined(PSX2008_HAS_SQRTQ)
4982 RETVAL = log10q(x);
4983 # elif defined(PSX2008_HAS_SQRTL)
4984 RETVAL = log10l(x);
4985 # else
4986 2 ▶ RETVAL = log10(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = log10(x); 0 2 2
4987 # endif
4988 OUTPUT:
4989 RETVAL
4990  
4991 #endif
4992  
4993 #ifdef PSX2008_HAS_LOG1P
4994 NV
4995 log1p(NV x);
4996 CODE:
4997 # if defined(PSX2008_HAS_SQRTQ)
4998 RETVAL = log1pq(x);
4999 # elif defined(PSX2008_HAS_SQRTL)
5000 RETVAL = log1pl(x);
5001 # else
5002 2 ▶ RETVAL = log1p(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = log1p(x); 0 2 2
5003 # endif
5004 OUTPUT:
5005 RETVAL
5006  
5007 #endif
5008  
5009 #ifdef PSX2008_HAS_LOG2
5010 NV
5011 log2(NV x);
5012 CODE:
5013 # if defined(PSX2008_HAS_SQRTQ)
5014 RETVAL = log2q(x);
5015 # elif defined(PSX2008_HAS_SQRTL)
5016 RETVAL = log2l(x);
5017 # else
5018 2 ▶ RETVAL = log2(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = log2(x); 0 2 2
5019 # endif
5020 OUTPUT:
5021 RETVAL
5022  
5023 #endif
5024  
5025 #if defined(PSX2008_HAS_LOGB) && (!defined(USE_QUADMATH) || defined(PSX2008_HAS_LOGBQ))
5026 NV
5027 logb(NV x);
5028 CODE:
5029 # if defined(PSX2008_HAS_LOGBQ)
5030 RETVAL = logbq(x);
5031 # elif defined(PSX2008_HAS_SQRTL)
5032 RETVAL = logbl(x);
5033 # else
5034 2 ▶ RETVAL = logb(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = logb(x); 0 2 2
5035 # endif
5036 OUTPUT:
5037 RETVAL
5038  
5039 #endif
5040  
5041 #ifdef PSX2008_HAS_LRINT
5042 void
5043 lrint(NV x);
5044 PPCODE:
5045 {
5046 # if defined(PSX2008_HAS_LLRINTQ)
5047 long long ret = llrintq(x);
5048 # elif defined(PSX2008_HAS_LRINTQ)
5049 long ret = lrintq(x);
5050 # elif defined(PSX2008_HAS_LLRINTL)
5051 long long ret = llrintl(x);
5052 # elif defined(PSX2008_HAS_LRINTL)
5053 long ret = lrintl(x);
5054 # elif defined(PSX2008_HAS_LLRINT)
5055 2 long long ret = llrint(x);
5056 # else
5057 long ret = lrint(x);
5058 # endif
5059 2 ▶ PUSH_INT_OR_PV(ret);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(ret); 0 2 2
PUSH_INT_OR_PV(ret); 2 0 2
5060 }
5061  
5062 #endif
5063  
5064 #ifdef PSX2008_HAS_LROUND
5065 void
5066 lround(NV x);
5067 PPCODE:
5068 {
5069 # if defined(PSX2008_HAS_LLROUNDQ)
5070 long long ret = llroundq(x);
5071 # elif defined(PSX2008_HAS_LROUNDQ)
5072 long ret = lroundq(x);
5073 # elif defined(PSX2008_HAS_LLROUNDL)
5074 long long ret = llroundl(x);
5075 # elif defined(PSX2008_HAS_LROUNDL)
5076 long ret = lroundl(x);
5077 # elif defined(PSX2008_HAS_LLROUND)
5078 2 long long ret = llround(x);
5079 # else
5080 long ret = lround(x);
5081 # endif
5082 2 ▶ PUSH_INT_OR_PV(ret);
Branch: 2 branches
BranchTrueFalseTotal
PUSH_INT_OR_PV(ret); 0 2 2
PUSH_INT_OR_PV(ret); 2 0 2
5083 }
5084  
5085 #endif
5086  
5087 #ifdef PSX2008_HAS_NEARBYINT
5088 NV
5089 nearbyint(NV x);
5090 CODE:
5091 # if defined(PSX2008_HAS_SQRTQ)
5092 RETVAL = nearbyintq(x);
5093 # elif defined(PSX2008_HAS_SQRTL)
5094 RETVAL = nearbyintl(x);
5095 # else
5096 2 ▶ RETVAL = nearbyint(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = nearbyint(x); 0 2 2
5097 # endif
5098 OUTPUT:
5099 RETVAL
5100  
5101 #endif
5102  
5103 #ifdef PSX2008_HAS_NEXTAFTER
5104 NV
5105 nextafter(NV x, NV y);
5106 CODE:
5107 # if defined(PSX2008_HAS_SQRTQ)
5108 RETVAL = nextafterq(x, y);
5109 # elif defined(PSX2008_HAS_SQRTL)
5110 RETVAL = nextafterl(x, y);
5111 # else
5112 2 ▶ RETVAL = nextafter(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = nextafter(x, y); 0 2 2
5113 # endif
5114 OUTPUT:
5115 RETVAL
5116  
5117 #endif
5118  
5119 #if defined(PSX2008_HAS_NEXTTOWARD) && (!defined(USE_QUADMATH) || defined(PSX2008_HAS_NEXTTOWARDQ))
5120 NV
5121 nexttoward(NV x, NV y);
5122 CODE:
5123 # if defined(PSX2008_HAS_NEXTTOWARDQ)
5124 RETVAL = nexttowardq(x, y);
5125 # elif defined(PSX2008_HAS_SQRTL)
5126 RETVAL = nexttowardl(x, y);
5127 # else
5128 2 ▶ RETVAL = nexttoward(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = nexttoward(x, y); 0 2 2
5129 # endif
5130 OUTPUT:
5131 RETVAL
5132  
5133 #endif
5134  
5135 #ifdef PSX2008_HAS_POW
5136 NV
5137 pow(NV x, NV y);
5138 CODE:
5139 # if defined(PSX2008_HAS_SQRTQ)
5140 RETVAL = powq(x, y);
5141 # elif defined(PSX2008_HAS_SQRTL)
5142 RETVAL = powl(x, y);
5143 # else
5144 3 ▶ RETVAL = pow(x, y);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = pow(x, y); 0 3 3
5145 # endif
5146 OUTPUT:
5147 RETVAL
5148  
5149 #endif
5150  
5151 #ifdef PSX2008_HAS_REMAINDER
5152 void
5153 remainder(NV x, NV y);
5154 INIT:
5155 NV res;
5156 PPCODE:
5157 {
5158 # if defined(PSX2008_HAS_SQRTQ)
5159 res = remainderq(x, y);
5160 # elif defined(PSX2008_HAS_SQRTL)
5161 res = remainderl(x, y);
5162 # else
5163 1 res = remainder(x, y);
5164 # endif
5165 1 mPUSHs(newSVnv(res));
5166 }
5167  
5168 #endif
5169  
5170 #ifdef PSX2008_HAS_REMQUO
5171 void
5172 remquo(NV x, NV y);
5173 INIT:
5174 int quo;
5175 NV res;
5176 PPCODE:
5177 {
5178 # if defined(PSX2008_HAS_SQRTQ)
5179 res = remquoq(x, y, &quo);
5180 # elif defined(PSX2008_HAS_SQRTL)
5181 res = remquol(x, y, &quo);
5182 # else
5183 0 res = remquo(x, y, &quo);
5184 # endif
5185 0 mPUSHs(newSVnv(res));
5186 0 mPUSHs(newSViv(quo));
5187 }
5188  
5189 #endif
5190  
5191 #ifdef PSX2008_HAS_RINT
5192 NV
5193 rint(NV x);
5194 CODE:
5195 {
5196 # if defined(PSX2008_HAS_SQRTQ)
5197 RETVAL = rintq(x);
5198 # elif defined(PSX2008_HAS_SQRTL)
5199 RETVAL = rintl(x);
5200 # else
5201 2 ▶ RETVAL = rint(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = rint(x); 0 2 2
5202 # endif
5203 }
5204 OUTPUT:
5205 RETVAL
5206  
5207 #endif
5208  
5209 #ifdef PSX2008_HAS_ROUND
5210 NV
5211 round(NV x);
5212 CODE:
5213 # if defined(PSX2008_HAS_SQRTQ)
5214 RETVAL = roundq(x);
5215 # elif defined(PSX2008_HAS_SQRTL)
5216 RETVAL = roundl(x);
5217 # else
5218 2 ▶ RETVAL = round(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = round(x); 0 2 2
5219 # endif
5220 OUTPUT:
5221 RETVAL
5222  
5223 #endif
5224  
5225 #ifdef PSX2008_HAS_SCALBN
5226 NV
5227 scalbn(NV x, IV n);
5228 CODE:
5229 # if defined(PSX2008_HAS_SCALBLNQ)
5230 RETVAL = scalblnq(x, (long)n);
5231 # elif defined(PSX2008_HAS_SCALBNQ)
5232 RETVAL = scalbnq(x, (int)n);
5233 # elif defined(PSX2008_HAS_SCALBLNL)
5234 RETVAL = scalblnl(x, (long)n);
5235 # elif defined(PSX2008_HAS_SCALBNL)
5236 RETVAL = scalbnl(x, (int)n);
5237 # elif defined(PSX2008_HAS_SCALBLN)
5238 0 ▶ RETVAL = scalbln(x, (long)n);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = scalbln(x, (long)n); 0 0 0
5239 # else
5240 RETVAL = scalbn(x, (int)n);
5241 # endif
5242 OUTPUT:
5243 RETVAL
5244  
5245 #endif
5246  
5247 #ifdef PSX2008_HAS_SIGNBIT
5248 NV
5249 signbit(NV x);
5250 CODE:
5251 # if defined(PSX2008_HAS_SQRTQ)
5252 RETVAL = signbitq(x);
5253 # else
5254 0 ▶ RETVAL = signbit(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = signbit(x); 0 0 0
5255 # endif
5256 OUTPUT:
5257 RETVAL
5258  
5259 #endif
5260  
5261 #ifdef PSX2008_HAS_SIN
5262 NV
5263 sin(NV x);
5264 CODE:
5265 # if defined(PSX2008_HAS_SQRTQ)
5266 RETVAL = sinq(x);
5267 # elif defined(PSX2008_HAS_SQRTL)
5268 RETVAL = sinl(x);
5269 # else
5270 4 ▶ RETVAL = sin(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sin(x); 0 4 4
5271 # endif
5272 OUTPUT:
5273 RETVAL
5274  
5275 #endif
5276  
5277 #ifdef PSX2008_HAS_SINH
5278 NV
5279 sinh(NV x);
5280 CODE:
5281 # if defined(PSX2008_HAS_SQRTQ)
5282 RETVAL = sinhq(x);
5283 # elif defined(PSX2008_HAS_SQRTL)
5284 RETVAL = sinhl(x);
5285 # else
5286 4 ▶ RETVAL = sinh(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sinh(x); 0 4 4
5287 # endif
5288 OUTPUT:
5289 RETVAL
5290  
5291 #endif
5292  
5293 #ifdef PSX2008_HAS_SQRT
5294 NV
5295 sqrt(NV x);
5296 CODE:
5297 # if defined(PSX2008_HAS_SQRTQ)
5298 RETVAL = sqrtq(x);
5299 # elif defined(PSX2008_HAS_SQRTL)
5300 RETVAL = sqrtl(x);
5301 # else
5302 2 ▶ RETVAL = sqrt(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sqrt(x); 0 2 2
5303 # endif
5304 OUTPUT:
5305 RETVAL
5306  
5307 #endif
5308  
5309 #ifdef PSX2008_HAS_TAN
5310 NV
5311 tan(NV x);
5312 CODE:
5313 # if defined(PSX2008_HAS_SQRTQ)
5314 RETVAL = tanq(x);
5315 # elif defined(PSX2008_HAS_SQRTL)
5316 RETVAL = tanl(x);
5317 # else
5318 4 ▶ RETVAL = tan(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = tan(x); 0 4 4
5319 # endif
5320 OUTPUT:
5321 RETVAL
5322  
5323 #endif
5324  
5325 #ifdef PSX2008_HAS_TANH
5326 NV
5327 tanh(NV x);
5328 CODE:
5329 # if defined(PSX2008_HAS_SQRTQ)
5330 RETVAL = tanhq(x);
5331 # elif defined(PSX2008_HAS_SQRTL)
5332 RETVAL = tanhl(x);
5333 # else
5334 4 ▶ RETVAL = tanh(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = tanh(x); 0 4 4
5335 # endif
5336 OUTPUT:
5337 RETVAL
5338  
5339 #endif
5340  
5341 #ifdef PSX2008_HAS_TGAMMA
5342 NV
5343 tgamma(NV x);
5344 CODE:
5345 # if defined(PSX2008_HAS_SQRTQ)
5346 RETVAL = tgammaq(x);
5347 # elif defined(PSX2008_HAS_TGAMMAL)
5348 RETVAL = tgammal(x);
5349 # else
5350 2 ▶ RETVAL = tgamma(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = tgamma(x); 0 2 2
5351 # endif
5352 OUTPUT:
5353 RETVAL
5354  
5355 #endif
5356  
5357 #ifdef PSX2008_HAS_TRUNC
5358 NV
5359 trunc(NV x);
5360 CODE:
5361 # if defined(PSX2008_HAS_SQRTQ)
5362 RETVAL = truncq(x);
5363 # elif defined(PSX2008_HAS_SQRTL)
5364 RETVAL = truncl(x);
5365 # else
5366 2 ▶ RETVAL = trunc(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = trunc(x); 0 2 2
5367 # endif
5368 OUTPUT:
5369 RETVAL
5370  
5371 #endif
5372  
5373 #ifdef PSX2008_HAS_Y0
5374 NV
5375 y0(NV x);
5376 CODE:
5377 # if defined(PSX2008_HAS_SQRTQ)
5378 RETVAL = y0q(x);
5379 # elif defined(PSX2008_HAS_Y0L) && !defined(__MINGW32__)
5380 RETVAL = y0l(x);
5381 # else
5382 2 ▶ RETVAL = y0(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = y0(x); 0 2 2
5383 # endif
5384 OUTPUT:
5385 RETVAL
5386  
5387 #endif
5388  
5389 #ifdef PSX2008_HAS_Y1
5390 NV
5391 y1(NV x);
5392 CODE:
5393 # if defined(PSX2008_HAS_SQRTQ)
5394 RETVAL = y1q(x);
5395 # elif defined(PSX2008_HAS_Y1L) && !defined(__MINGW32__)
5396 RETVAL = y1l(x);
5397 # else
5398 2 ▶ RETVAL = y1(x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = y1(x); 0 2 2
5399 # endif
5400 OUTPUT:
5401 RETVAL
5402  
5403 #endif
5404  
5405 #if defined(PSX2008_HAS_YN)
5406 NV
5407 yn(int n, NV x);
5408 CODE:
5409 # if defined(PSX2008_HAS_SQRTQ)
5410 RETVAL = ynq(n, x);
5411 # elif defined(PSX2008_HAS_YNL) && !defined(__MINGW32__)
5412 RETVAL = ynl(n, x);
5413 # else
5414 3 ▶ RETVAL = yn(n, x);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = yn(n, x); 0 3 3
5415 # endif
5416 OUTPUT:
5417 RETVAL
5418  
5419 #endif
5420  
5421 ## Complex arithmetic functions
5422 ###############################
5423  
5424 #ifdef PSX2008_HAS_CABS
5425 NV
5426 cabs(NV re, NV im);
5427 INIT:
5428 PSX2008_COMPLEX_T z;
5429 1 COMPLEX_FROM_RE_IM(z, re, im);
5430 CODE:
5431 # if defined(PSX2008_HAS_CSQRTQ)
5432 RETVAL = cabsq(z);
5433 # elif defined(PSX2008_HAS_CSQRTL)
5434 RETVAL = cabsl(z);
5435 # else
5436 1 ▶ RETVAL = cabs(z);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = cabs(z); 0 1 1
5437 # endif
5438 OUTPUT:
5439 RETVAL
5440  
5441 #endif
5442  
5443 #ifdef PSX2008_HAS_CARG
5444 NV
5445 carg(NV re, NV im);
5446 INIT:
5447 PSX2008_COMPLEX_T z;
5448 1 COMPLEX_FROM_RE_IM(z, re, im);
5449 CODE:
5450 # if defined(PSX2008_HAS_CSQRTQ)
5451 RETVAL = cargq(z);
5452 # elif defined(PSX2008_HAS_CSQRTL)
5453 RETVAL = cargl(z);
5454 # else
5455 1 ▶ RETVAL = carg(z);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = carg(z); 0 1 1
5456 # endif
5457 OUTPUT:
5458 RETVAL
5459  
5460 #endif
5461  
5462 #ifdef PSX2008_HAS_CIMAG
5463 NV
5464 cimag(NV re, NV im);
5465 INIT:
5466 PSX2008_COMPLEX_T z;
5467 1 COMPLEX_FROM_RE_IM(z, re, im);
5468 CODE:
5469 # if defined(PSX2008_HAS_CSQRTQ)
5470 RETVAL = cimagq(z);
5471 # elif defined(PSX2008_HAS_CSQRTL)
5472 RETVAL = cimagl(z);
5473 # else
5474 1 ▶ RETVAL = cimag(z);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = cimag(z); 0 1 1
5475 # endif
5476 OUTPUT:
5477 RETVAL
5478  
5479 #endif
5480  
5481 #ifdef PSX2008_HAS_CPROJ
5482 void
5483 cproj(NV re, NV im);
5484 INIT:
5485 PSX2008_COMPLEX_T result;
5486 PSX2008_COMPLEX_T z;
5487 1 COMPLEX_FROM_RE_IM(z, re, im);
5488 PPCODE:
5489 # if defined(PSX2008_HAS_CSQRTQ)
5490 result = cprojq(z);
5491 # elif defined(PSX2008_HAS_CSQRTL)
5492 result = cprojl(z);
5493 # else
5494 1 result = cproj(z);
5495 # endif
5496 1 RETURN_COMPLEX(result);
5497  
5498 #endif
5499  
5500 #ifdef PSX2008_HAS_CREAL
5501 NV
5502 creal(NV re, NV im);
5503 INIT:
5504 PSX2008_COMPLEX_T z;
5505 1 COMPLEX_FROM_RE_IM(z, re, im);
5506 CODE:
5507 # if defined(PSX2008_HAS_CSQRTQ)
5508 RETVAL = crealq(z);
5509 # elif defined(PSX2008_HAS_CSQRTL)
5510 RETVAL = creall(z);
5511 # else
5512 1 ▶ RETVAL = creal(z);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = creal(z); 0 1 1
5513 # endif
5514 OUTPUT:
5515 RETVAL
5516  
5517 #endif
5518  
5519 #ifdef PSX2008_HAS_CEXP
5520 void
5521 cexp(NV re, NV im);
5522 INIT:
5523 PSX2008_COMPLEX_T result;
5524 PSX2008_COMPLEX_T z;
5525 1 COMPLEX_FROM_RE_IM(z, re, im);
5526 PPCODE:
5527 # if defined(PSX2008_HAS_CSQRTQ)
5528 result = cexpq(z);
5529 # elif defined(PSX2008_HAS_CEXPL)
5530 result = cexpl(z);
5531 # else
5532 1 result = cexp(z);
5533 # endif
5534 1 RETURN_COMPLEX(result);
5535  
5536 #endif
5537  
5538 #ifdef PSX2008_HAS_CLOG
5539 void
5540 clog(NV re, NV im);
5541 INIT:
5542 PSX2008_COMPLEX_T result;
5543 PSX2008_COMPLEX_T z;
5544 1 COMPLEX_FROM_RE_IM(z, re, im);
5545 PPCODE:
5546 # if defined(PSX2008_HAS_CSQRTQ)
5547 result = clogq(z);
5548 # elif defined(PSX2008_HAS_CLOGL)
5549 result = clogl(z);
5550 # else
5551 1 result = clog(z);
5552 # endif
5553 1 RETURN_COMPLEX(result);
5554  
5555 #endif
5556  
5557 #ifdef PSX2008_HAS_CONJ
5558 void
5559 conj(NV re, NV im);
5560 INIT:
5561 PSX2008_COMPLEX_T result;
5562 PSX2008_COMPLEX_T z;
5563 1 COMPLEX_FROM_RE_IM(z, re, im);
5564 PPCODE:
5565 # if defined(PSX2008_HAS_CSQRTQ)
5566 result = conjq(z);
5567 # elif defined(PSX2008_HAS_CSQRTL)
5568 result = conjl(z);
5569 # else
5570 1 result = conj(z);
5571 # endif
5572 1 RETURN_COMPLEX(result);
5573  
5574 #endif
5575  
5576 #ifdef PSX2008_HAS_CPOW
5577 void
5578 cpow(NV re_x, NV im_x, NV re_y, NV im_y);
5579 INIT:
5580 PSX2008_COMPLEX_T result;
5581 PSX2008_COMPLEX_T x, y;
5582 1 COMPLEX_FROM_RE_IM(x, re_x, im_x);
5583 1 COMPLEX_FROM_RE_IM(y, re_y, im_y);
5584 PPCODE:
5585 # if defined(PSX2008_HAS_CSQRTQ)
5586 result = cpowq(x, y);
5587 # elif defined(PSX2008_HAS_CSQRTL)
5588 result = cpowl(x, y);
5589 # else
5590 1 result = cpow(x, y);
5591 # endif
5592 1 RETURN_COMPLEX(result);
5593  
5594 #endif
5595  
5596 #ifdef PSX2008_HAS_CSQRT
5597 void
5598 csqrt(NV re, NV im);
5599 INIT:
5600 PSX2008_COMPLEX_T result;
5601 PSX2008_COMPLEX_T z;
5602 2 COMPLEX_FROM_RE_IM(z, re, im);
5603 PPCODE:
5604 # if defined(PSX2008_HAS_CSQRTQ)
5605 result = csqrtq(z);
5606 # elif defined(PSX2008_HAS_CSQRTL)
5607 result = csqrtl(z);
5608 # else
5609 2 result = csqrt(z);
5610 # endif
5611 2 RETURN_COMPLEX(result);
5612  
5613 #endif
5614  
5615 #ifdef PSX2008_HAS_CACOS
5616 void
5617 cacos(NV re, NV im);
5618 INIT:
5619 PSX2008_COMPLEX_T result;
5620 PSX2008_COMPLEX_T z;
5621 1 COMPLEX_FROM_RE_IM(z, re, im);
5622 PPCODE:
5623 # if defined(PSX2008_HAS_CSQRTQ)
5624 result = cacosq(z);
5625 # elif defined(PSX2008_HAS_CSQRTL)
5626 result = cacosl(z);
5627 # else
5628 1 result = cacos(z);
5629 # endif
5630 1 RETURN_COMPLEX(result);
5631  
5632 #endif
5633  
5634 #ifdef PSX2008_HAS_CACOSH
5635 void
5636 cacosh(NV re, NV im);
5637 INIT:
5638 PSX2008_COMPLEX_T result;
5639 PSX2008_COMPLEX_T z;
5640 1 COMPLEX_FROM_RE_IM(z, re, im);
5641 PPCODE:
5642 # if defined(PSX2008_HAS_CSQRTQ)
5643 result = cacoshq(z);
5644 # elif defined(PSX2008_HAS_CSQRTL)
5645 result = cacoshl(z);
5646 # else
5647 1 result = cacosh(z);
5648 # endif
5649 1 RETURN_COMPLEX(result);
5650  
5651 #endif
5652  
5653 #ifdef PSX2008_HAS_CASIN
5654 void
5655 casin(NV re, NV im);
5656 INIT:
5657 PSX2008_COMPLEX_T result;
5658 PSX2008_COMPLEX_T z;
5659 1 COMPLEX_FROM_RE_IM(z, re, im);
5660 PPCODE:
5661 # if defined(PSX2008_HAS_CSQRTQ)
5662 result = casinq(z);
5663 # elif defined(PSX2008_HAS_CSQRTL)
5664 result = casinl(z);
5665 # else
5666 1 result = casin(z);
5667 # endif
5668 1 RETURN_COMPLEX(result);
5669  
5670 #endif
5671  
5672 #ifdef PSX2008_HAS_CASINH
5673 void
5674 casinh(NV re, NV im);
5675 INIT:
5676 PSX2008_COMPLEX_T result;
5677 PSX2008_COMPLEX_T z;
5678 1 COMPLEX_FROM_RE_IM(z, re, im);
5679 PPCODE:
5680 # if defined(PSX2008_HAS_CSQRTQ)
5681 result = casinhq(z);
5682 # elif defined(PSX2008_HAS_CSQRTL)
5683 result = casinhl(z);
5684 # else
5685 1 result = casinh(z);
5686 # endif
5687 1 RETURN_COMPLEX(result);
5688  
5689 #endif
5690  
5691 #ifdef PSX2008_HAS_CATAN
5692 void
5693 catan(NV re, NV im);
5694 INIT:
5695 PSX2008_COMPLEX_T result;
5696 PSX2008_COMPLEX_T z;
5697 1 COMPLEX_FROM_RE_IM(z, re, im);
5698 PPCODE:
5699 # if defined(PSX2008_HAS_CSQRTQ)
5700 result = catanq(z);
5701 # elif defined(PSX2008_HAS_CSQRTL)
5702 result = catanl(z);
5703 # else
5704 1 result = catan(z);
5705 # endif
5706 1 RETURN_COMPLEX(result);
5707  
5708 #endif
5709  
5710 #ifdef PSX2008_HAS_CATANH
5711 void
5712 catanh(NV re, NV im);
5713 INIT:
5714 PSX2008_COMPLEX_T result;
5715 PSX2008_COMPLEX_T z;
5716 1 COMPLEX_FROM_RE_IM(z, re, im);
5717 PPCODE:
5718 # if defined(PSX2008_HAS_CSQRTQ)
5719 result = catanhq(z);
5720 # elif defined(PSX2008_HAS_CSQRTL)
5721 result = catanhl(z);
5722 # else
5723 1 result = catanh(z);
5724 # endif
5725 1 RETURN_COMPLEX(result);
5726  
5727 #endif
5728  
5729 #ifdef PSX2008_HAS_CCOS
5730 void
5731 ccos(NV re, NV im);
5732 INIT:
5733 PSX2008_COMPLEX_T result;
5734 PSX2008_COMPLEX_T z;
5735 1 COMPLEX_FROM_RE_IM(z, re, im);
5736 PPCODE:
5737 # if defined(PSX2008_HAS_CSQRTQ)
5738 result = ccosq(z);
5739 # elif defined(PSX2008_HAS_CCOSL)
5740 result = ccosl(z);
5741 # else
5742 1 result = ccos(z);
5743 # endif
5744 1 RETURN_COMPLEX(result);
5745  
5746 #endif
5747  
5748 #ifdef PSX2008_HAS_CCOSH
5749 void
5750 ccosh(NV re, NV im);
5751 INIT:
5752 PSX2008_COMPLEX_T result;
5753 PSX2008_COMPLEX_T z;
5754 1 COMPLEX_FROM_RE_IM(z, re, im);
5755 PPCODE:
5756 # if defined(PSX2008_HAS_CSQRTQ)
5757 result = ccoshq(z);
5758 # elif defined(PSX2008_HAS_CCOSHL)
5759 result = ccoshl(z);
5760 # else
5761 1 result = ccosh(z);
5762 # endif
5763 1 RETURN_COMPLEX(result);
5764  
5765 #endif
5766  
5767 #ifdef PSX2008_HAS_CSIN
5768 void
5769 csin(NV re, NV im);
5770 INIT:
5771 PSX2008_COMPLEX_T result;
5772 PSX2008_COMPLEX_T z;
5773 1 COMPLEX_FROM_RE_IM(z, re, im);
5774 PPCODE:
5775 # if defined(PSX2008_HAS_CSQRTQ)
5776 result = csinq(z);
5777 # elif defined(PSX2008_HAS_CSINL)
5778 result = csinl(z);
5779 # else
5780 1 result = csin(z);
5781 # endif
5782 1 RETURN_COMPLEX(result);
5783  
5784 #endif
5785  
5786 #ifdef PSX2008_HAS_CSINH
5787 void
5788 csinh(NV re, NV im);
5789 INIT:
5790 PSX2008_COMPLEX_T result;
5791 PSX2008_COMPLEX_T z;
5792 1 COMPLEX_FROM_RE_IM(z, re, im);
5793 PPCODE:
5794 # if defined(PSX2008_HAS_CSQRTQ)
5795 result = csinhq(z);
5796 # elif defined(PSX2008_HAS_CSINHL)
5797 result = csinhl(z);
5798 # else
5799 1 result = csinh(z);
5800 # endif
5801 1 RETURN_COMPLEX(result);
5802  
5803 #endif
5804  
5805 #ifdef PSX2008_HAS_CTAN
5806 void
5807 ctan(NV re, NV im);
5808 INIT:
5809 PSX2008_COMPLEX_T result;
5810 PSX2008_COMPLEX_T z;
5811 1 COMPLEX_FROM_RE_IM(z, re, im);
5812 PPCODE:
5813 # if defined(PSX2008_HAS_CSQRTQ)
5814 result = ctanq(z);
5815 # elif defined(PSX2008_HAS_CTANL)
5816 result = ctanl(z);
5817 # else
5818 1 result = ctan(z);
5819 # endif
5820 1 RETURN_COMPLEX(result);
5821  
5822 #endif
5823  
5824 #ifdef PSX2008_HAS_CTANH
5825 void
5826 ctanh(NV re, NV im);
5827 INIT:
5828 PSX2008_COMPLEX_T result;
5829 PSX2008_COMPLEX_T z;
5830 1 COMPLEX_FROM_RE_IM(z, re, im);
5831 PPCODE:
5832 # if defined(PSX2008_HAS_CSQRTQ)
5833 result = ctanhq(z);
5834 # elif defined(PSX2008_HAS_CTANHL)
5835 result = ctanhl(z);
5836 # else
5837 1 result = ctanh(z);
5838 # endif
5839 1 RETURN_COMPLEX(result);
5840  
5841 #endif
« blib/lib/POSIX/2008.pm ↑ Summary const-c.inc »