line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#include |
4
|
|
|
|
|
|
|
#include |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#include "EXTERN.h" |
7
|
|
|
|
|
|
|
#include "perl.h" |
8
|
|
|
|
|
|
|
#include "XSUB.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "ppport.h" |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
MODULE = File::ReplaceBytes PACKAGE = File::ReplaceBytes |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
ssize_t |
15
|
|
|
|
|
|
|
pread(PerlIO *fh, SV *buf, ...) |
16
|
|
|
|
|
|
|
PROTOTYPE: $$$;$ |
17
|
|
|
|
|
|
|
PREINIT: |
18
|
8
|
|
|
|
|
|
off_t offset = 0; |
19
|
8
|
|
|
|
|
|
STRLEN len = 0; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
CODE: |
22
|
7
|
50
|
|
|
|
|
if( items > 2 ) { |
23
|
7
|
50
|
|
|
|
|
if (!SvIOK(ST(2)) || SvIV(ST(2)) < 0) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
24
|
1
|
|
|
|
|
|
errno = EINVAL; |
25
|
1
|
|
|
|
|
|
XSRETURN_IV(-1); |
26
|
|
|
|
|
|
|
} |
27
|
6
|
50
|
|
|
|
|
len = SvIV(ST(2)); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
/* emulate pread not complaining if nothing to read */ |
30
|
6
|
100
|
|
|
|
|
if (len == 0) |
31
|
1
|
|
|
|
|
|
XSRETURN_IV(0); |
32
|
5
|
50
|
|
|
|
|
if( items > 3 ) { |
33
|
5
|
50
|
|
|
|
|
if (!SvIOK(ST(3)) || SvIV(ST(3)) < 0) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
34
|
1
|
|
|
|
|
|
errno = EINVAL; |
35
|
1
|
|
|
|
|
|
XSRETURN_IV(-1); |
36
|
|
|
|
|
|
|
} |
37
|
4
|
50
|
|
|
|
|
offset = SvIV(ST(3)); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
4
|
100
|
|
|
|
|
if(!SvOK(buf)) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
41
|
1
|
|
|
|
|
|
sv_setpvs(buf, ""); |
42
|
|
|
|
|
|
|
|
43
|
4
|
100
|
|
|
|
|
RETVAL = pread(PerlIO_fileno(fh), SvGROW(buf, len), len, offset); |
|
|
50
|
|
|
|
|
|
44
|
4
|
50
|
|
|
|
|
if (RETVAL > 0) { |
45
|
4
|
|
|
|
|
|
SvCUR_set(buf, RETVAL); |
46
|
4
|
50
|
|
|
|
|
SvTAINTED_on(buf); |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
SvCUR_set(buf, 0); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
OUTPUT: |
52
|
|
|
|
|
|
|
buf |
53
|
|
|
|
|
|
|
RETVAL |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
ssize_t |
56
|
|
|
|
|
|
|
pwrite(PerlIO *fh, SV *buf, ...) |
57
|
|
|
|
|
|
|
PROTOTYPE: $$;$$ |
58
|
|
|
|
|
|
|
PREINIT: |
59
|
|
|
|
|
|
|
char *bp; |
60
|
6
|
|
|
|
|
|
off_t offset = 0; |
61
|
6
|
|
|
|
|
|
STRLEN len = 0; |
62
|
6
|
|
|
|
|
|
STRLEN userlen = 0; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
CODE: |
65
|
|
|
|
|
|
|
/* pwrite(2) does not complain if nothing to write, so emulate that */ |
66
|
6
|
100
|
|
|
|
|
if(!SvOK(buf) || SvCUR(buf) == 0) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
67
|
4
|
|
|
|
|
|
XSRETURN_IV(0); |
68
|
|
|
|
|
|
|
/* length, offset are optional, but offset demands that length also be |
69
|
|
|
|
|
|
|
* set by the caller */ |
70
|
4
|
50
|
|
|
|
|
if( items > 2 ) { |
71
|
4
|
50
|
|
|
|
|
if (!SvIOK(ST(2)) || SvIV(ST(2)) < 0) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
72
|
1
|
|
|
|
|
|
errno = EINVAL; |
73
|
1
|
|
|
|
|
|
XSRETURN_IV(-1); |
74
|
|
|
|
|
|
|
} |
75
|
3
|
50
|
|
|
|
|
userlen = SvIV(ST(2)); |
76
|
|
|
|
|
|
|
} |
77
|
3
|
50
|
|
|
|
|
if( items > 3 ) { |
78
|
3
|
50
|
|
|
|
|
if (!SvIOK(ST(3)) || SvIV(ST(3)) < 0) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
79
|
1
|
|
|
|
|
|
errno = EINVAL; |
80
|
1
|
|
|
|
|
|
XSRETURN_IV(-1); |
81
|
|
|
|
|
|
|
} |
82
|
2
|
50
|
|
|
|
|
offset = SvIV(ST(3)); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
2
|
100
|
|
|
|
|
bp = SvPV(buf, len); |
86
|
2
|
50
|
|
|
|
|
if (userlen == 0 || userlen > len) |
|
|
0
|
|
|
|
|
|
87
|
2
|
|
|
|
|
|
userlen = len; |
88
|
2
|
|
|
|
|
|
RETVAL = pwrite(PerlIO_fileno(fh), bp, userlen, offset); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
OUTPUT: |
91
|
|
|
|
|
|
|
RETVAL |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
ssize_t |
94
|
|
|
|
|
|
|
replacebytes(SV *filename, SV *buf, ...) |
95
|
|
|
|
|
|
|
PROTOTYPE: $$;$ |
96
|
|
|
|
|
|
|
PREINIT: |
97
|
|
|
|
|
|
|
char *bp; |
98
|
|
|
|
|
|
|
int fd, i; |
99
|
2
|
|
|
|
|
|
off_t offset = 0; |
100
|
|
|
|
|
|
|
STRLEN len; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
CODE: |
103
|
2
|
50
|
|
|
|
|
if(!SvOK(buf) || SvCUR(buf) == 0) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
104
|
1
|
|
|
|
|
|
XSRETURN_IV(0); |
105
|
2
|
100
|
|
|
|
|
if( items > 2 ) { |
106
|
1
|
50
|
|
|
|
|
if (!SvIOK(ST(2)) || SvIV(ST(2)) < 0) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
errno = EINVAL; |
108
|
0
|
|
|
|
|
|
XSRETURN_IV(-1); |
109
|
|
|
|
|
|
|
} |
110
|
1
|
50
|
|
|
|
|
offset = SvIV(ST(2)); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
/* as otherwise a filename of "bar\0foo" results in a "bar" file which |
114
|
|
|
|
|
|
|
* is not the same as what was input */ |
115
|
2
|
50
|
|
|
|
|
bp = SvPV(filename, len); |
116
|
8
|
100
|
|
|
|
|
for (i = 0; i < len; i++) { |
117
|
7
|
100
|
|
|
|
|
if (bp[i] == '\0') { |
118
|
1
|
|
|
|
|
|
errno = EINVAL; |
119
|
1
|
|
|
|
|
|
XSRETURN_IV(-1); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
1
|
50
|
|
|
|
|
if((fd = open(SvPV_nolen(filename), O_CREAT|O_WRONLY, 0666)) == -1) |
|
|
50
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
XSRETURN_IV(-1); |
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
|
|
|
|
bp = SvPV(buf, len); |
127
|
1
|
|
|
|
|
|
RETVAL = pwrite(fd, bp, len, offset); |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
|
close(fd); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
OUTPUT: |
132
|
|
|
|
|
|
|
RETVAL |