File Coverage

lib/File/lchown.xs
Criterion Covered Total %
statement 22 24 91.6
branch 17 22 77.2
condition n/a
subroutine n/a
pod n/a
total 39 46 84.7


line stmt bran cond sub pod time code
1             /* You may distribute under the terms of either the GNU General Public License
2             * or the Artistic License (the same terms as Perl itself)
3             *
4             * (C) Paul Evans, 2007,2008,2025 -- leonerd@leonerd.org.uk
5             */
6              
7             #include "EXTERN.h"
8             #include "perl.h"
9             #include "XSUB.h"
10              
11             #include
12             #include
13              
14 8           static void S_extract_timeval(pTHX_ struct timeval *tvp, SV *sv)
15             {
16 8 100         if(SvNOK(sv)) {
17 2           NV nv = SvNV(sv);
18 2           tvp->tv_sec = (long)nv;
19 2           tvp->tv_usec = 1000000 * (nv - tvp->tv_sec);
20             }
21 6 100         else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV) {
    50          
22             AV *av = (AV *)SvRV(sv);
23 2 50         if(AvFILL(av) < 1)
    50          
24 0           croak("Expected an ARRAY reference of at least 2 elements");
25 2           tvp->tv_sec = SvUV(*av_fetch(av, 0, 0));
26 2           tvp->tv_usec = SvUV(*av_fetch(av, 1, 0));
27             }
28             else {
29 4           tvp->tv_sec = SvUV(sv);
30 4           tvp->tv_usec = 0;
31             }
32 8           }
33              
34             MODULE = File::lchown PACKAGE = File::lchown
35              
36             int
37             lchown(int uid, int gid, ...)
38             PREINIT:
39             int i;
40              
41             CODE:
42             RETVAL = 0;
43              
44 2 100         for(i = 2; i < items; i++) {
45 1           char *path = SvPV_nolen(ST(i));
46 1 50         if(lchown(path, uid, gid) == 0)
47 0           RETVAL++;
48             }
49              
50             OUTPUT:
51             RETVAL
52              
53             int
54             lutimes(SV *atime, SV *mtime, ...)
55             PREINIT:
56             struct timeval tv[2];
57             struct timeval *tvp;
58             int i;
59              
60             CODE:
61             #ifdef HAVE_LUTIMES
62 5 100         if(!SvOK(atime) && !SvOK(mtime))
    50          
63             tvp = NULL;
64             else {
65 4           S_extract_timeval(aTHX_ &tv[0], atime);
66 4           S_extract_timeval(aTHX_ &tv[1], mtime);
67             tvp = tv;
68             }
69              
70             RETVAL = 0;
71              
72 9 100         for(i = 2; i < items; i++) {
73 4           char *path = SvPV_nolen(ST(i));
74 4 100         if(lutimes(path, tvp) == 0)
75 3           RETVAL++;
76             }
77             #else
78             croak("lutimes() not implemented");
79             #endif
80              
81             OUTPUT:
82             RETVAL