line |
stmt |
bran |
cond |
sub |
time |
code |
1
|
|
|
|
|
|
/* doio.c |
2
|
|
|
|
|
|
* |
3
|
|
|
|
|
|
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
4
|
|
|
|
|
|
* 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others |
5
|
|
|
|
|
|
* |
6
|
|
|
|
|
|
* You may distribute under the terms of either the GNU General Public |
7
|
|
|
|
|
|
* License or the Artistic License, as specified in the README file. |
8
|
|
|
|
|
|
* |
9
|
|
|
|
|
|
*/ |
10
|
|
|
|
|
|
|
11
|
|
|
|
|
|
/* |
12
|
|
|
|
|
|
* Far below them they saw the white waters pour into a foaming bowl, and |
13
|
|
|
|
|
|
* then swirl darkly about a deep oval basin in the rocks, until they found |
14
|
|
|
|
|
|
* their way out again through a narrow gate, and flowed away, fuming and |
15
|
|
|
|
|
|
* chattering, into calmer and more level reaches. |
16
|
|
|
|
|
|
* |
17
|
|
|
|
|
|
* [p.684 of _The Lord of the Rings_, IV/vi: "The Forbidden Pool"] |
18
|
|
|
|
|
|
*/ |
19
|
|
|
|
|
|
|
20
|
|
|
|
|
|
/* This file contains functions that do the actual I/O on behalf of ops. |
21
|
|
|
|
|
|
* For example, pp_print() calls the do_print() function in this file for |
22
|
|
|
|
|
|
* each argument needing printing. |
23
|
|
|
|
|
|
*/ |
24
|
|
|
|
|
|
|
25
|
|
|
|
|
|
#include "EXTERN.h" |
26
|
|
|
|
|
|
#define PERL_IN_DOIO_C |
27
|
|
|
|
|
|
#include "perl.h" |
28
|
|
|
|
|
|
|
29
|
|
|
|
|
|
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) |
30
|
|
|
|
|
|
#ifndef HAS_SEM |
31
|
|
|
|
|
|
#include |
32
|
|
|
|
|
|
#endif |
33
|
|
|
|
|
|
#ifdef HAS_MSG |
34
|
|
|
|
|
|
#include |
35
|
|
|
|
|
|
#endif |
36
|
|
|
|
|
|
#ifdef HAS_SHM |
37
|
|
|
|
|
|
#include |
38
|
|
|
|
|
|
# ifndef HAS_SHMAT_PROTOTYPE |
39
|
|
|
|
|
|
extern Shmat_t shmat (int, char *, int); |
40
|
|
|
|
|
|
# endif |
41
|
|
|
|
|
|
#endif |
42
|
|
|
|
|
|
#endif |
43
|
|
|
|
|
|
|
44
|
|
|
|
|
|
#ifdef I_UTIME |
45
|
|
|
|
|
|
# if defined(_MSC_VER) || defined(__MINGW32__) |
46
|
|
|
|
|
|
# include |
47
|
|
|
|
|
|
# else |
48
|
|
|
|
|
|
# include |
49
|
|
|
|
|
|
# endif |
50
|
|
|
|
|
|
#endif |
51
|
|
|
|
|
|
|
52
|
|
|
|
|
|
#ifdef O_EXCL |
53
|
|
|
|
|
|
# define OPEN_EXCL O_EXCL |
54
|
|
|
|
|
|
#else |
55
|
|
|
|
|
|
# define OPEN_EXCL 0 |
56
|
|
|
|
|
|
#endif |
57
|
|
|
|
|
|
|
58
|
|
|
|
|
|
#define PERL_MODE_MAX 8 |
59
|
|
|
|
|
|
#define PERL_FLAGS_MAX 10 |
60
|
|
|
|
|
|
|
61
|
|
|
|
|
|
#include |
62
|
|
|
|
|
|
|
63
|
|
|
|
|
|
bool |
64
|
4866069
|
|
|
|
|
Perl_do_openn(pTHX_ GV *gv, const char *oname, I32 len, int as_raw, |
65
|
|
|
|
|
|
int rawmode, int rawperm, PerlIO *supplied_fp, SV **svp, |
66
|
|
|
|
|
|
I32 num_svs) |
67
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
dVAR; |
69
|
4866069
|
50
|
|
|
|
IO * const io = GvIOn(gv); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
70
|
|
|
|
|
|
PerlIO *saveifp = NULL; |
71
|
|
|
|
|
|
PerlIO *saveofp = NULL; |
72
|
|
|
|
|
|
int savefd = -1; |
73
|
|
|
|
|
|
char savetype = IoTYPE_CLOSED; |
74
|
4866069
|
|
|
|
|
int writing = 0; |
75
|
|
|
|
|
|
PerlIO *fp; |
76
|
|
|
|
|
|
int fd; |
77
|
|
|
|
|
|
int result; |
78
|
|
|
|
|
|
bool was_fdopen = FALSE; |
79
|
|
|
|
|
|
bool in_raw = 0, in_crlf = 0, out_raw = 0, out_crlf = 0; |
80
|
|
|
|
|
|
char *type = NULL; |
81
|
|
|
|
|
|
char mode[PERL_MODE_MAX]; /* file mode ("r\0", "rb\0", "ab\0" etc.) */ |
82
|
|
|
|
|
|
SV *namesv; |
83
|
|
|
|
|
|
|
84
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_OPENN; |
85
|
|
|
|
|
|
|
86
|
|
|
|
|
|
Zero(mode,sizeof(mode),char); |
87
|
4866069
|
|
|
|
|
PL_forkprocess = 1; /* assume true if no fork */ |
88
|
|
|
|
|
|
|
89
|
|
|
|
|
|
/* Collect default raw/crlf info from the op */ |
90
|
4866069
|
50
|
|
|
|
if (PL_op && PL_op->op_type == OP_OPEN) { |
|
|
100
|
|
|
|
|
91
|
|
|
|
|
|
/* set up IO layers */ |
92
|
4858137
|
|
|
|
|
const U8 flags = PL_op->op_private; |
93
|
4858137
|
|
|
|
|
in_raw = (flags & OPpOPEN_IN_RAW); |
94
|
4858137
|
|
|
|
|
in_crlf = (flags & OPpOPEN_IN_CRLF); |
95
|
4858137
|
|
|
|
|
out_raw = (flags & OPpOPEN_OUT_RAW); |
96
|
4858137
|
|
|
|
|
out_crlf = (flags & OPpOPEN_OUT_CRLF); |
97
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
99
|
|
|
|
|
|
/* If currently open - close before we re-open */ |
100
|
4866069
|
100
|
|
|
|
if (IoIFP(io)) { |
101
|
7158
|
|
|
|
|
fd = PerlIO_fileno(IoIFP(io)); |
102
|
7158
|
100
|
|
|
|
if (IoTYPE(io) == IoTYPE_STD) { |
103
|
|
|
|
|
|
/* This is a clone of one of STD* handles */ |
104
|
|
|
|
|
|
result = 0; |
105
|
|
|
|
|
|
} |
106
|
7156
|
100
|
|
|
|
else if (fd >= 0 && fd <= PL_maxsysfd) { |
|
|
100
|
|
|
|
|
107
|
|
|
|
|
|
/* This is one of the original STD* handles */ |
108
|
5190
|
|
|
|
|
saveifp = IoIFP(io); |
109
|
5190
|
|
|
|
|
saveofp = IoOFP(io); |
110
|
5190
|
|
|
|
|
savetype = IoTYPE(io); |
111
|
|
|
|
|
|
savefd = fd; |
112
|
5190
|
|
|
|
|
result = 0; |
113
|
|
|
|
|
|
} |
114
|
1966
|
50
|
|
|
|
else if (IoTYPE(io) == IoTYPE_PIPE) |
115
|
0
|
|
|
|
|
result = PerlProc_pclose(IoIFP(io)); |
116
|
1966
|
100
|
|
|
|
else if (IoIFP(io) != IoOFP(io)) { |
117
|
1092
|
50
|
|
|
|
if (IoOFP(io)) { |
118
|
0
|
|
|
|
|
result = PerlIO_close(IoOFP(io)); |
119
|
0
|
|
|
|
|
PerlIO_close(IoIFP(io)); /* clear stdio, fd already closed */ |
120
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
else |
122
|
1092
|
|
|
|
|
result = PerlIO_close(IoIFP(io)); |
123
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
else |
125
|
874
|
|
|
|
|
result = PerlIO_close(IoIFP(io)); |
126
|
7158
|
100
|
|
|
|
if (result == EOF && fd > PL_maxsysfd) { |
|
|
50
|
|
|
|
|
127
|
|
|
|
|
|
/* Why is this not Perl_warn*() call ? */ |
128
|
0
|
0
|
|
|
|
PerlIO_printf(Perl_error_log, |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
129
|
|
|
|
|
|
"Warning: unable to close filehandle %"HEKf" properly.\n", |
130
|
0
|
0
|
|
|
|
HEKfARG(GvENAME_HEK(gv)) |
131
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
} |
133
|
7158
|
|
|
|
|
IoOFP(io) = IoIFP(io) = NULL; |
134
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
136
|
4866069
|
100
|
|
|
|
if (as_raw) { |
137
|
|
|
|
|
|
/* sysopen style args, i.e. integer mode and permissions */ |
138
|
|
|
|
|
|
STRLEN ix = 0; |
139
|
|
|
|
|
|
const int appendtrunc = |
140
|
|
|
|
|
|
0 |
141
|
|
|
|
|
|
#ifdef O_APPEND /* Not fully portable. */ |
142
|
|
|
|
|
|
|O_APPEND |
143
|
|
|
|
|
|
#endif |
144
|
|
|
|
|
|
#ifdef O_TRUNC /* Not fully portable. */ |
145
|
|
|
|
|
|
|O_TRUNC |
146
|
|
|
|
|
|
#endif |
147
|
|
|
|
|
|
; |
148
|
|
|
|
|
|
const int modifyingmode = O_WRONLY|O_RDWR|O_CREAT|appendtrunc; |
149
|
|
|
|
|
|
int ismodifying; |
150
|
|
|
|
|
|
|
151
|
6546
|
50
|
|
|
|
if (num_svs != 0) { |
152
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: sysopen with multiple args, num_svs=%ld", |
153
|
|
|
|
|
|
(long) num_svs); |
154
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
/* It's not always |
156
|
|
|
|
|
|
|
157
|
|
|
|
|
|
O_RDONLY 0 |
158
|
|
|
|
|
|
O_WRONLY 1 |
159
|
|
|
|
|
|
O_RDWR 2 |
160
|
|
|
|
|
|
|
161
|
|
|
|
|
|
It might be (in OS/390 and Mac OS Classic it is) |
162
|
|
|
|
|
|
|
163
|
|
|
|
|
|
O_WRONLY 1 |
164
|
|
|
|
|
|
O_RDONLY 2 |
165
|
|
|
|
|
|
O_RDWR 3 |
166
|
|
|
|
|
|
|
167
|
|
|
|
|
|
This means that simple & with O_RDWR would look |
168
|
|
|
|
|
|
like O_RDONLY is present. Therefore we have to |
169
|
|
|
|
|
|
be more careful. |
170
|
|
|
|
|
|
*/ |
171
|
6546
|
100
|
|
|
|
if ((ismodifying = (rawmode & modifyingmode))) { |
172
|
6470
|
50
|
|
|
|
if ((ismodifying & O_WRONLY) == O_WRONLY || |
173
|
6470
|
|
|
|
|
(ismodifying & O_RDWR) == O_RDWR || |
174
|
|
|
|
|
|
(ismodifying & (O_CREAT|appendtrunc))) |
175
|
6470
|
50
|
|
|
|
TAINT_PROPER("sysopen"); |
176
|
|
|
|
|
|
} |
177
|
6546
|
|
|
|
|
mode[ix++] = IoTYPE_NUMERIC; /* Marker to openn to use numeric "sysopen" */ |
178
|
|
|
|
|
|
|
179
|
|
|
|
|
|
#if defined(USE_64_BIT_RAWIO) && defined(O_LARGEFILE) |
180
|
|
|
|
|
|
rawmode |= O_LARGEFILE; /* Transparently largefiley. */ |
181
|
|
|
|
|
|
#endif |
182
|
|
|
|
|
|
|
183
|
6546
|
|
|
|
|
IoTYPE(io) = PerlIO_intmode2str(rawmode, &mode[ix], &writing); |
184
|
|
|
|
|
|
|
185
|
6546
|
|
|
|
|
namesv = newSVpvn_flags(oname, len, SVs_TEMP); |
186
|
|
|
|
|
|
num_svs = 1; |
187
|
|
|
|
|
|
svp = &namesv; |
188
|
|
|
|
|
|
type = NULL; |
189
|
6546
|
|
|
|
|
fp = PerlIO_openn(aTHX_ type, mode, -1, rawmode, rawperm, NULL, num_svs, svp); |
190
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
else { |
192
|
|
|
|
|
|
/* Regular (non-sys) open */ |
193
|
|
|
|
|
|
char *name; |
194
|
4859523
|
|
|
|
|
STRLEN olen = len; |
195
|
|
|
|
|
|
char *tend; |
196
|
|
|
|
|
|
int dodup = 0; |
197
|
|
|
|
|
|
|
198
|
4859523
|
|
|
|
|
type = savepvn(oname, len); |
199
|
4859523
|
|
|
|
|
tend = type+len; |
200
|
4859523
|
|
|
|
|
SAVEFREEPV(type); |
201
|
|
|
|
|
|
|
202
|
|
|
|
|
|
/* Lose leading and trailing white space */ |
203
|
7288624
|
100
|
|
|
|
while (isSPACE(*type)) |
204
|
58
|
|
|
|
|
type++; |
205
|
4859555
|
100
|
|
|
|
while (tend > type && isSPACE(tend[-1])) |
|
|
100
|
|
|
|
|
206
|
32
|
|
|
|
|
*--tend = '\0'; |
207
|
|
|
|
|
|
|
208
|
4859523
|
100
|
|
|
|
if (num_svs) { |
209
|
|
|
|
|
|
/* New style explicit name, type is just mode and layer info */ |
210
|
|
|
|
|
|
#ifdef USE_STDIO |
211
|
|
|
|
|
|
if (SvROK(*svp) && !strchr(oname,'&')) { |
212
|
|
|
|
|
|
if (ckWARN(WARN_IO)) |
213
|
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_IO), |
214
|
|
|
|
|
|
"Can't open a reference"); |
215
|
|
|
|
|
|
SETERRNO(EINVAL, LIB_INVARG); |
216
|
|
|
|
|
|
goto say_false; |
217
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
#endif /* USE_STDIO */ |
219
|
2456015
|
50
|
|
|
|
if (!IS_SAFE_PATHNAME(*svp, "open")) |
220
|
|
|
|
|
|
goto say_false; |
221
|
|
|
|
|
|
|
222
|
1227846
|
50
|
|
|
|
name = (SvOK(*svp) || SvGMAGICAL(*svp)) ? |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
223
|
3683844
|
100
|
|
|
|
savesvpv (*svp) : savepvs (""); |
224
|
2456015
|
|
|
|
|
SAVEFREEPV(name); |
225
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
else { |
227
|
|
|
|
|
|
name = type; |
228
|
2403508
|
|
|
|
|
len = tend-type; |
229
|
|
|
|
|
|
} |
230
|
4859523
|
|
|
|
|
IoTYPE(io) = *type; |
231
|
4860030
|
100
|
|
|
|
if ((*type == IoTYPE_RDWR) && /* scary */ |
|
|
50
|
|
|
|
|
232
|
1521
|
100
|
|
|
|
(*(type+1) == IoTYPE_RDONLY || *(type+1) == IoTYPE_WRONLY) && |
233
|
86
|
50
|
|
|
|
((!num_svs || (tend > type+1 && tend[-1] != IoTYPE_PIPE)))) { |
|
|
50
|
|
|
|
|
234
|
1014
|
100
|
|
|
|
TAINT_PROPER("open"); |
235
|
1014
|
|
|
|
|
mode[1] = *type++; |
236
|
1014
|
|
|
|
|
writing = 1; |
237
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
239
|
4859523
|
100
|
|
|
|
if (*type == IoTYPE_PIPE) { |
240
|
54
|
100
|
|
|
|
if (num_svs) { |
241
|
4
|
50
|
|
|
|
if (type[1] != IoTYPE_STD) { |
242
|
|
|
|
|
|
unknown_open_mode: |
243
|
8
|
|
|
|
|
Perl_croak(aTHX_ "Unknown open() mode '%.*s'", (int)olen, oname); |
244
|
|
|
|
|
|
} |
245
|
29
|
|
|
|
|
type++; |
246
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
do { |
248
|
64
|
|
|
|
|
type++; |
249
|
64
|
100
|
|
|
|
} while (isSPACE(*type)); |
250
|
54
|
100
|
|
|
|
if (!num_svs) { |
251
|
|
|
|
|
|
name = type; |
252
|
50
|
|
|
|
|
len = tend-type; |
253
|
|
|
|
|
|
} |
254
|
54
|
100
|
|
|
|
if (*name == '\0') { |
255
|
|
|
|
|
|
/* command is missing 19990114 */ |
256
|
12
|
100
|
|
|
|
if (ckWARN(WARN_PIPE)) |
257
|
4
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_PIPE), "Missing command in piped open"); |
258
|
12
|
|
|
|
|
errno = EPIPE; |
259
|
12
|
|
|
|
|
goto say_false; |
260
|
|
|
|
|
|
} |
261
|
42
|
100
|
|
|
|
if (!(*name == '-' && name[1] == '\0') || num_svs) |
|
|
50
|
|
|
|
|
262
|
28
|
50
|
|
|
|
TAINT_ENV(); |
263
|
42
|
50
|
|
|
|
TAINT_PROPER("piped open"); |
264
|
42
|
100
|
|
|
|
if (!num_svs && name[len-1] == '|') { |
|
|
100
|
|
|
|
|
265
|
4
|
|
|
|
|
name[--len] = '\0' ; |
266
|
4
|
100
|
|
|
|
if (ckWARN(WARN_PIPE)) |
267
|
2
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_PIPE), "Can't open bidirectional pipe"); |
268
|
|
|
|
|
|
} |
269
|
42
|
|
|
|
|
mode[0] = 'w'; |
270
|
42
|
|
|
|
|
writing = 1; |
271
|
42
|
50
|
|
|
|
if (out_raw) |
272
|
0
|
|
|
|
|
mode[1] = 'b'; |
273
|
42
|
50
|
|
|
|
else if (out_crlf) |
274
|
0
|
|
|
|
|
mode[1] = 't'; |
275
|
42
|
50
|
|
|
|
if (num_svs > 1) { |
276
|
0
|
|
|
|
|
fp = PerlProc_popen_list(mode, num_svs, svp); |
277
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
else { |
279
|
42
|
|
|
|
|
fp = PerlProc_popen(name,mode); |
280
|
|
|
|
|
|
} |
281
|
42
|
100
|
|
|
|
if (num_svs) { |
282
|
4
|
50
|
|
|
|
if (*type) { |
283
|
0
|
0
|
|
|
|
if (PerlIO_apply_layers(aTHX_ fp, mode, type) != 0) { |
284
|
|
|
|
|
|
goto say_false; |
285
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
} /* IoTYPE_PIPE */ |
289
|
4859469
|
100
|
|
|
|
else if (*type == IoTYPE_WRONLY) { |
290
|
388684
|
100
|
|
|
|
TAINT_PROPER("open"); |
291
|
388684
|
|
|
|
|
type++; |
292
|
388684
|
100
|
|
|
|
if (*type == IoTYPE_WRONLY) { |
293
|
|
|
|
|
|
/* Two IoTYPE_WRONLYs in a row make for an IoTYPE_APPEND. */ |
294
|
324000
|
|
|
|
|
mode[0] = IoTYPE(io) = IoTYPE_APPEND; |
295
|
324000
|
|
|
|
|
type++; |
296
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
else { |
298
|
64684
|
|
|
|
|
mode[0] = 'w'; |
299
|
|
|
|
|
|
} |
300
|
388684
|
|
|
|
|
writing = 1; |
301
|
|
|
|
|
|
|
302
|
388684
|
50
|
|
|
|
if (out_raw) |
303
|
0
|
|
|
|
|
mode[1] = 'b'; |
304
|
388684
|
50
|
|
|
|
else if (out_crlf) |
305
|
0
|
|
|
|
|
mode[1] = 't'; |
306
|
388684
|
100
|
|
|
|
if (*type == '&') { |
307
|
|
|
|
|
|
duplicity: |
308
|
|
|
|
|
|
dodup = PERLIO_DUP_FD; |
309
|
12890
|
|
|
|
|
type++; |
310
|
12890
|
100
|
|
|
|
if (*type == '=') { |
311
|
|
|
|
|
|
dodup = 0; |
312
|
42
|
|
|
|
|
type++; |
313
|
|
|
|
|
|
} |
314
|
12890
|
100
|
|
|
|
if (!num_svs && !*type && supplied_fp) { |
|
|
100
|
|
|
|
|
315
|
|
|
|
|
|
/* "<+&" etc. is used by typemaps */ |
316
|
|
|
|
|
|
fp = supplied_fp; |
317
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
else { |
319
|
|
|
|
|
|
PerlIO *that_fp = NULL; |
320
|
12532
|
50
|
|
|
|
if (num_svs > 1) { |
321
|
|
|
|
|
|
/* diag_listed_as: More than one argument to '%s' open */ |
322
|
0
|
|
|
|
|
Perl_croak(aTHX_ "More than one argument to '%c&' open",IoTYPE(io)); |
323
|
|
|
|
|
|
} |
324
|
12532
|
50
|
|
|
|
while (isSPACE(*type)) |
325
|
0
|
|
|
|
|
type++; |
326
|
13842
|
100
|
|
|
|
if (num_svs && ( |
|
|
100
|
|
|
|
|
327
|
2620
|
|
|
|
|
SvIOK(*svp) |
328
|
2612
|
100
|
|
|
|
|| (SvPOKp(*svp) && looks_like_number(*svp)) |
|
|
100
|
|
|
|
|
329
|
|
|
|
|
|
)) { |
330
|
14
|
50
|
|
|
|
fd = SvUV(*svp); |
331
|
14
|
|
|
|
|
num_svs = 0; |
332
|
|
|
|
|
|
} |
333
|
12518
|
100
|
|
|
|
else if (isDIGIT(*type)) { |
334
|
|
|
|
|
|
fd = atoi(type); |
335
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
else { |
337
|
|
|
|
|
|
const IO* thatio; |
338
|
11232
|
100
|
|
|
|
if (num_svs) { |
339
|
2606
|
|
|
|
|
thatio = sv_2io(*svp); |
340
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
else { |
342
|
8626
|
|
|
|
|
GV * const thatgv = gv_fetchpvn_flags(type, tend - type, |
343
|
|
|
|
|
|
0, SVt_PVIO); |
344
|
8626
|
100
|
|
|
|
thatio = GvIO(thatgv); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
345
|
|
|
|
|
|
} |
346
|
11224
|
100
|
|
|
|
if (!thatio) { |
347
|
|
|
|
|
|
#ifdef EINVAL |
348
|
2
|
|
|
|
|
SETERRNO(EINVAL,SS_IVCHAN); |
349
|
|
|
|
|
|
#endif |
350
|
2
|
|
|
|
|
goto say_false; |
351
|
|
|
|
|
|
} |
352
|
11222
|
50
|
|
|
|
if ((that_fp = IoIFP(thatio))) { |
353
|
|
|
|
|
|
/* Flush stdio buffer before dup. --mjd |
354
|
|
|
|
|
|
* Unfortunately SEEK_CURing 0 seems to |
355
|
|
|
|
|
|
* be optimized away on most platforms; |
356
|
|
|
|
|
|
* only Solaris and Linux seem to flush |
357
|
|
|
|
|
|
* on that. --jhi */ |
358
|
|
|
|
|
|
#ifdef USE_SFIO |
359
|
|
|
|
|
|
/* sfio fails to clear error on next |
360
|
|
|
|
|
|
sfwrite, contrary to documentation. |
361
|
|
|
|
|
|
-- Nicholas Clark */ |
362
|
|
|
|
|
|
if (PerlIO_seek(that_fp, 0, SEEK_CUR) == -1) |
363
|
|
|
|
|
|
PerlIO_clearerr(that_fp); |
364
|
|
|
|
|
|
#endif |
365
|
|
|
|
|
|
/* On the other hand, do all platforms |
366
|
|
|
|
|
|
* take gracefully to flushing a read-only |
367
|
|
|
|
|
|
* filehandle? Perhaps we should do |
368
|
|
|
|
|
|
* fsetpos(src)+fgetpos(dst)? --nik */ |
369
|
11222
|
|
|
|
|
PerlIO_flush(that_fp); |
370
|
11222
|
|
|
|
|
fd = PerlIO_fileno(that_fp); |
371
|
|
|
|
|
|
/* When dup()ing STDIN, STDOUT or STDERR |
372
|
|
|
|
|
|
* explicitly set appropriate access mode */ |
373
|
11222
|
100
|
|
|
|
if (that_fp == PerlIO_stdout() |
374
|
5560
|
100
|
|
|
|
|| that_fp == PerlIO_stderr()) |
375
|
9308
|
|
|
|
|
IoTYPE(io) = IoTYPE_WRONLY; |
376
|
1914
|
100
|
|
|
|
else if (that_fp == PerlIO_stdin()) |
377
|
156
|
|
|
|
|
IoTYPE(io) = IoTYPE_RDONLY; |
378
|
|
|
|
|
|
/* When dup()ing a socket, say result is |
379
|
|
|
|
|
|
* one as well */ |
380
|
1758
|
50
|
|
|
|
else if (IoTYPE(thatio) == IoTYPE_SOCKET) |
381
|
0
|
|
|
|
|
IoTYPE(io) = IoTYPE_SOCKET; |
382
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
else |
384
|
|
|
|
|
|
fd = -1; |
385
|
|
|
|
|
|
} |
386
|
12522
|
100
|
|
|
|
if (!num_svs) |
387
|
|
|
|
|
|
type = NULL; |
388
|
12522
|
100
|
|
|
|
if (that_fp) { |
389
|
11222
|
|
|
|
|
fp = PerlIO_fdupopen(aTHX_ that_fp, NULL, dodup); |
390
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
else { |
392
|
1300
|
100
|
|
|
|
if (dodup) |
393
|
1270
|
|
|
|
|
fd = PerlLIO_dup(fd); |
394
|
|
|
|
|
|
else |
395
|
|
|
|
|
|
was_fdopen = TRUE; |
396
|
1300
|
50
|
|
|
|
if (!(fp = PerlIO_openn(aTHX_ type,mode,fd,0,0,NULL,num_svs,svp))) { |
397
|
0
|
0
|
|
|
|
if (dodup && fd >= 0) |
398
|
0
|
|
|
|
|
PerlLIO_close(fd); |
399
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
} /* & */ |
403
|
|
|
|
|
|
else { |
404
|
385644
|
100
|
|
|
|
while (isSPACE(*type)) |
405
|
9286
|
|
|
|
|
type++; |
406
|
376358
|
100
|
|
|
|
if (*type == IoTYPE_STD && (!type[1] || isSPACE(type[1]) || type[1] == ':')) { |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
407
|
6
|
|
|
|
|
type++; |
408
|
6
|
|
|
|
|
fp = PerlIO_stdout(); |
409
|
6
|
|
|
|
|
IoTYPE(io) = IoTYPE_STD; |
410
|
6
|
50
|
|
|
|
if (num_svs > 1) { |
411
|
|
|
|
|
|
/* diag_listed_as: More than one argument to '%s' open */ |
412
|
0
|
|
|
|
|
Perl_croak(aTHX_ "More than one argument to '>%c' open",IoTYPE_STD); |
413
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
else { |
416
|
376352
|
100
|
|
|
|
if (!num_svs) { |
417
|
347700
|
|
|
|
|
namesv = newSVpvn_flags(type, tend - type, SVs_TEMP); |
418
|
|
|
|
|
|
num_svs = 1; |
419
|
|
|
|
|
|
svp = &namesv; |
420
|
|
|
|
|
|
type = NULL; |
421
|
|
|
|
|
|
} |
422
|
376352
|
|
|
|
|
fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp); |
423
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
} /* !& */ |
425
|
389238
|
100
|
|
|
|
if (!fp && type && *type && *type != ':' && !isIDFIRST(*type)) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
426
|
|
|
|
|
|
goto unknown_open_mode; |
427
|
|
|
|
|
|
} /* IoTYPE_WRONLY */ |
428
|
4470785
|
100
|
|
|
|
else if (*type == IoTYPE_RDONLY) { |
429
|
|
|
|
|
|
do { |
430
|
2472957
|
|
|
|
|
type++; |
431
|
2472957
|
100
|
|
|
|
} while (isSPACE(*type)); |
432
|
2453675
|
|
|
|
|
mode[0] = 'r'; |
433
|
2453675
|
50
|
|
|
|
if (in_raw) |
434
|
0
|
|
|
|
|
mode[1] = 'b'; |
435
|
2453675
|
50
|
|
|
|
else if (in_crlf) |
436
|
0
|
|
|
|
|
mode[1] = 't'; |
437
|
2453675
|
100
|
|
|
|
if (*type == '&') { |
438
|
|
|
|
|
|
goto duplicity; |
439
|
|
|
|
|
|
} |
440
|
2453111
|
50
|
|
|
|
if (*type == IoTYPE_STD && (!type[1] || isSPACE(type[1]) || type[1] == ':')) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
441
|
0
|
|
|
|
|
type++; |
442
|
0
|
|
|
|
|
fp = PerlIO_stdin(); |
443
|
0
|
|
|
|
|
IoTYPE(io) = IoTYPE_STD; |
444
|
0
|
0
|
|
|
|
if (num_svs > 1) { |
445
|
|
|
|
|
|
/* diag_listed_as: More than one argument to '%s' open */ |
446
|
0
|
|
|
|
|
Perl_croak(aTHX_ "More than one argument to '<%c' open",IoTYPE_STD); |
447
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
else { |
450
|
2453111
|
100
|
|
|
|
if (!num_svs) { |
451
|
29336
|
|
|
|
|
namesv = newSVpvn_flags(type, tend - type, SVs_TEMP); |
452
|
|
|
|
|
|
num_svs = 1; |
453
|
|
|
|
|
|
svp = &namesv; |
454
|
|
|
|
|
|
type = NULL; |
455
|
|
|
|
|
|
} |
456
|
2453111
|
|
|
|
|
fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp); |
457
|
|
|
|
|
|
} |
458
|
2453107
|
100
|
|
|
|
if (!fp && type && *type && *type != ':' && !isIDFIRST(*type)) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
459
|
|
|
|
|
|
goto unknown_open_mode; |
460
|
|
|
|
|
|
} /* IoTYPE_RDONLY */ |
461
|
2017592
|
100
|
|
|
|
else if ((num_svs && /* '-|...' or '...|' */ |
|
|
100
|
|
|
|
|
462
|
1009696
|
50
|
|
|
|
type[0] == IoTYPE_STD && type[1] == IoTYPE_PIPE) || |
|
|
100
|
|
|
|
|
463
|
2016146
|
100
|
|
|
|
(!num_svs && tend > type+1 && tend[-1] == IoTYPE_PIPE)) { |
|
|
100
|
|
|
|
|
464
|
7612
|
100
|
|
|
|
if (num_svs) { |
465
|
958
|
|
|
|
|
type += 2; /* skip over '-|' */ |
466
|
|
|
|
|
|
} |
467
|
|
|
|
|
|
else { |
468
|
6654
|
|
|
|
|
*--tend = '\0'; |
469
|
19405
|
50
|
|
|
|
while (tend > type && isSPACE(tend[-1])) |
|
|
100
|
|
|
|
|
470
|
9424
|
|
|
|
|
*--tend = '\0'; |
471
|
3327
|
50
|
|
|
|
for (; isSPACE(*type); type++) |
472
|
|
|
|
|
|
; |
473
|
|
|
|
|
|
name = type; |
474
|
|
|
|
|
|
len = tend-type; |
475
|
|
|
|
|
|
} |
476
|
7612
|
50
|
|
|
|
if (*name == '\0') { |
477
|
|
|
|
|
|
/* command is missing 19990114 */ |
478
|
0
|
0
|
|
|
|
if (ckWARN(WARN_PIPE)) |
479
|
0
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_PIPE), "Missing command in piped open"); |
480
|
0
|
|
|
|
|
errno = EPIPE; |
481
|
0
|
|
|
|
|
goto say_false; |
482
|
|
|
|
|
|
} |
483
|
7612
|
100
|
|
|
|
if (!(*name == '-' && name[1] == '\0') || num_svs) |
|
|
50
|
|
|
|
|
484
|
6232
|
50
|
|
|
|
TAINT_ENV(); |
485
|
7612
|
50
|
|
|
|
TAINT_PROPER("piped open"); |
486
|
7612
|
|
|
|
|
mode[0] = 'r'; |
487
|
|
|
|
|
|
|
488
|
7612
|
50
|
|
|
|
if (in_raw) |
489
|
0
|
|
|
|
|
mode[1] = 'b'; |
490
|
7612
|
50
|
|
|
|
else if (in_crlf) |
491
|
0
|
|
|
|
|
mode[1] = 't'; |
492
|
|
|
|
|
|
|
493
|
7612
|
100
|
|
|
|
if (num_svs > 1) { |
494
|
6
|
|
|
|
|
fp = PerlProc_popen_list(mode,num_svs,svp); |
495
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
else { |
497
|
7606
|
|
|
|
|
fp = PerlProc_popen(name,mode); |
498
|
|
|
|
|
|
} |
499
|
7612
|
|
|
|
|
IoTYPE(io) = IoTYPE_PIPE; |
500
|
7612
|
100
|
|
|
|
if (num_svs) { |
501
|
958
|
50
|
|
|
|
while (isSPACE(*type)) |
502
|
0
|
|
|
|
|
type++; |
503
|
958
|
50
|
|
|
|
if (*type) { |
504
|
0
|
0
|
|
|
|
if (PerlIO_apply_layers(aTHX_ fp, mode, type) != 0) { |
505
|
|
|
|
|
|
goto say_false; |
506
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
else { /* layer(Args) */ |
511
|
2009498
|
100
|
|
|
|
if (num_svs) |
512
|
|
|
|
|
|
goto unknown_open_mode; |
513
|
|
|
|
|
|
name = type; |
514
|
2009492
|
|
|
|
|
IoTYPE(io) = IoTYPE_RDONLY; |
515
|
2009492
|
50
|
|
|
|
for (; isSPACE(*name); name++) |
516
|
|
|
|
|
|
; |
517
|
2009492
|
|
|
|
|
mode[0] = 'r'; |
518
|
|
|
|
|
|
|
519
|
2009492
|
50
|
|
|
|
if (in_raw) |
520
|
0
|
|
|
|
|
mode[1] = 'b'; |
521
|
2009492
|
50
|
|
|
|
else if (in_crlf) |
522
|
0
|
|
|
|
|
mode[1] = 't'; |
523
|
|
|
|
|
|
|
524
|
2009492
|
100
|
|
|
|
if (*name == '-' && name[1] == '\0') { |
|
|
50
|
|
|
|
|
525
|
162
|
|
|
|
|
fp = PerlIO_stdin(); |
526
|
162
|
|
|
|
|
IoTYPE(io) = IoTYPE_STD; |
527
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
else { |
529
|
2009330
|
50
|
|
|
|
if (!num_svs) { |
530
|
2009330
|
|
|
|
|
namesv = newSVpvn_flags(type, tend - type, SVs_TEMP); |
531
|
|
|
|
|
|
num_svs = 1; |
532
|
|
|
|
|
|
svp = &namesv; |
533
|
|
|
|
|
|
type = NULL; |
534
|
|
|
|
|
|
} |
535
|
2009330
|
|
|
|
|
fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp); |
536
|
|
|
|
|
|
} |
537
|
|
|
|
|
|
} |
538
|
|
|
|
|
|
} |
539
|
4866035
|
100
|
|
|
|
if (!fp) { |
540
|
1688082
|
100
|
|
|
|
if (IoTYPE(io) == IoTYPE_RDONLY && ckWARN(WARN_NEWLINE) |
|
|
100
|
|
|
|
|
541
|
1687748
|
100
|
|
|
|
&& strchr(oname, '\n') |
542
|
|
|
|
|
|
|
543
|
|
|
|
|
|
) |
544
|
6
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "open"); |
545
|
|
|
|
|
|
goto say_false; |
546
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
548
|
3177953
|
100
|
|
|
|
if (ckWARN(WARN_IO)) { |
549
|
3074842
|
|
|
|
|
if ((IoTYPE(io) == IoTYPE_RDONLY) && |
550
|
2943694
|
100
|
|
|
|
(fp == PerlIO_stdout() || fp == PerlIO_stderr())) { |
551
|
54
|
100
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_IO), |
552
|
|
|
|
|
|
"Filehandle STD%s reopened as %"HEKf |
553
|
|
|
|
|
|
" only for input", |
554
|
54
|
|
|
|
|
((fp == PerlIO_stdout()) ? "OUT" : "ERR"), |
555
|
54
|
50
|
|
|
|
HEKfARG(GvENAME_HEK(gv))); |
556
|
|
|
|
|
|
} |
557
|
1602935
|
100
|
|
|
|
else if ((IoTYPE(io) == IoTYPE_WRONLY) && fp == PerlIO_stdin()) { |
|
|
100
|
|
|
|
|
558
|
6
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_IO), |
559
|
|
|
|
|
|
"Filehandle STDIN reopened as %"HEKf" only for output", |
560
|
6
|
50
|
|
|
|
HEKfARG(GvENAME_HEK(gv)) |
561
|
|
|
|
|
|
); |
562
|
|
|
|
|
|
} |
563
|
|
|
|
|
|
} |
564
|
|
|
|
|
|
|
565
|
3177953
|
|
|
|
|
fd = PerlIO_fileno(fp); |
566
|
|
|
|
|
|
/* If there is no fd (e.g. PerlIO::scalar) assume it isn't a |
567
|
|
|
|
|
|
* socket - this covers PerlIO::scalar - otherwise unless we "know" the |
568
|
|
|
|
|
|
* type probe for socket-ness. |
569
|
|
|
|
|
|
*/ |
570
|
3177953
|
100
|
|
|
|
if (IoTYPE(io) && IoTYPE(io) != IoTYPE_PIPE && IoTYPE(io) != IoTYPE_STD && fd >= 0) { |
|
|
100
|
|
|
|
|
571
|
3165753
|
100
|
|
|
|
if (PerlLIO_fstat(fd,&PL_statbuf) < 0) { |
572
|
|
|
|
|
|
/* If PerlIO claims to have fd we had better be able to fstat() it. */ |
573
|
4
|
|
|
|
|
(void) PerlIO_close(fp); |
574
|
4
|
|
|
|
|
goto say_false; |
575
|
|
|
|
|
|
} |
576
|
|
|
|
|
|
#ifndef PERL_MICRO |
577
|
3165749
|
100
|
|
|
|
if (S_ISSOCK(PL_statbuf.st_mode)) |
578
|
4
|
|
|
|
|
IoTYPE(io) = IoTYPE_SOCKET; /* in case a socket was passed in to us */ |
579
|
|
|
|
|
|
#ifdef HAS_SOCKET |
580
|
3165745
|
50
|
|
|
|
else if ( |
581
|
|
|
|
|
|
#ifdef S_IFMT |
582
|
3165745
|
|
|
|
|
!(PL_statbuf.st_mode & S_IFMT) |
583
|
|
|
|
|
|
#else |
584
|
|
|
|
|
|
!PL_statbuf.st_mode |
585
|
|
|
|
|
|
#endif |
586
|
0
|
0
|
|
|
|
&& IoTYPE(io) != IoTYPE_WRONLY /* Dups of STD* filehandles already have */ |
587
|
0
|
0
|
|
|
|
&& IoTYPE(io) != IoTYPE_RDONLY /* type so they aren't marked as sockets */ |
588
|
|
|
|
|
|
) { /* on OS's that return 0 on fstat()ed pipe */ |
589
|
|
|
|
|
|
char tmpbuf[256]; |
590
|
0
|
|
|
|
|
Sock_size_t buflen = sizeof tmpbuf; |
591
|
0
|
0
|
|
|
|
if (PerlSock_getsockname(fd, (struct sockaddr *)tmpbuf, &buflen) >= 0 |
592
|
0
|
0
|
|
|
|
|| errno != ENOTSOCK) |
593
|
0
|
|
|
|
|
IoTYPE(io) = IoTYPE_SOCKET; /* some OS's return 0 on fstat()ed socket */ |
594
|
|
|
|
|
|
/* but some return 0 for streams too, sigh */ |
595
|
|
|
|
|
|
} |
596
|
|
|
|
|
|
#endif /* HAS_SOCKET */ |
597
|
|
|
|
|
|
#endif /* !PERL_MICRO */ |
598
|
|
|
|
|
|
} |
599
|
|
|
|
|
|
|
600
|
|
|
|
|
|
/* Eeek - FIXME !!! |
601
|
|
|
|
|
|
* If this is a standard handle we discard all the layer stuff |
602
|
|
|
|
|
|
* and just dup the fd into whatever was on the handle before ! |
603
|
|
|
|
|
|
*/ |
604
|
|
|
|
|
|
|
605
|
3177949
|
100
|
|
|
|
if (saveifp) { /* must use old fp? */ |
606
|
|
|
|
|
|
/* If fd is less that PL_maxsysfd i.e. STDIN..STDERR |
607
|
|
|
|
|
|
then dup the new fileno down |
608
|
|
|
|
|
|
*/ |
609
|
5188
|
100
|
|
|
|
if (saveofp) { |
610
|
4876
|
|
|
|
|
PerlIO_flush(saveofp); /* emulate PerlIO_close() */ |
611
|
4876
|
100
|
|
|
|
if (saveofp != saveifp) { /* was a socket? */ |
612
|
290
|
|
|
|
|
PerlIO_close(saveofp); |
613
|
|
|
|
|
|
} |
614
|
|
|
|
|
|
} |
615
|
5188
|
50
|
|
|
|
if (savefd != fd) { |
616
|
|
|
|
|
|
/* Still a small can-of-worms here if (say) PerlIO::scalar |
617
|
|
|
|
|
|
is assigned to (say) STDOUT - for now let dup2() fail |
618
|
|
|
|
|
|
and provide the error |
619
|
|
|
|
|
|
*/ |
620
|
5188
|
100
|
|
|
|
if (PerlLIO_dup2(fd, savefd) < 0) { |
621
|
4
|
|
|
|
|
(void)PerlIO_close(fp); |
622
|
4
|
|
|
|
|
goto say_false; |
623
|
|
|
|
|
|
} |
624
|
|
|
|
|
|
#ifdef VMS |
625
|
|
|
|
|
|
if (savefd != PerlIO_fileno(PerlIO_stdin())) { |
626
|
|
|
|
|
|
char newname[FILENAME_MAX+1]; |
627
|
|
|
|
|
|
if (PerlIO_getname(fp, newname)) { |
628
|
|
|
|
|
|
if (fd == PerlIO_fileno(PerlIO_stdout())) |
629
|
|
|
|
|
|
vmssetuserlnm("SYS$OUTPUT", newname); |
630
|
|
|
|
|
|
if (fd == PerlIO_fileno(PerlIO_stderr())) |
631
|
|
|
|
|
|
vmssetuserlnm("SYS$ERROR", newname); |
632
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
#endif |
635
|
|
|
|
|
|
|
636
|
|
|
|
|
|
#if !defined(WIN32) |
637
|
|
|
|
|
|
/* PL_fdpid isn't used on Windows, so avoid this useless work. |
638
|
|
|
|
|
|
* XXX Probably the same for a lot of other places. */ |
639
|
10368
|
|
|
|
|
{ |
640
|
|
|
|
|
|
Pid_t pid; |
641
|
|
|
|
|
|
SV *sv; |
642
|
|
|
|
|
|
|
643
|
5184
|
|
|
|
|
sv = *av_fetch(PL_fdpid,fd,TRUE); |
644
|
5238
|
|
|
|
|
SvUPGRADE(sv, SVt_IV); |
645
|
5184
|
|
|
|
|
pid = SvIVX(sv); |
646
|
5184
|
|
|
|
|
SvIV_set(sv, 0); |
647
|
5184
|
|
|
|
|
sv = *av_fetch(PL_fdpid,savefd,TRUE); |
648
|
5276
|
|
|
|
|
SvUPGRADE(sv, SVt_IV); |
649
|
5184
|
|
|
|
|
SvIV_set(sv, pid); |
650
|
|
|
|
|
|
} |
651
|
|
|
|
|
|
#endif |
652
|
|
|
|
|
|
|
653
|
5184
|
50
|
|
|
|
if (was_fdopen) { |
654
|
|
|
|
|
|
/* need to close fp without closing underlying fd */ |
655
|
0
|
|
|
|
|
int ofd = PerlIO_fileno(fp); |
656
|
0
|
|
|
|
|
int dupfd = PerlLIO_dup(ofd); |
657
|
|
|
|
|
|
#if defined(HAS_FCNTL) && defined(F_SETFD) |
658
|
|
|
|
|
|
/* Assume if we have F_SETFD we have F_GETFD */ |
659
|
0
|
|
|
|
|
int coe = fcntl(ofd,F_GETFD); |
660
|
|
|
|
|
|
#endif |
661
|
0
|
|
|
|
|
PerlIO_close(fp); |
662
|
0
|
|
|
|
|
PerlLIO_dup2(dupfd,ofd); |
663
|
|
|
|
|
|
#if defined(HAS_FCNTL) && defined(F_SETFD) |
664
|
|
|
|
|
|
/* The dup trick has lost close-on-exec on ofd */ |
665
|
0
|
|
|
|
|
fcntl(ofd,F_SETFD, coe); |
666
|
|
|
|
|
|
#endif |
667
|
0
|
|
|
|
|
PerlLIO_close(dupfd); |
668
|
|
|
|
|
|
} |
669
|
|
|
|
|
|
else |
670
|
5184
|
|
|
|
|
PerlIO_close(fp); |
671
|
|
|
|
|
|
} |
672
|
|
|
|
|
|
fp = saveifp; |
673
|
5184
|
|
|
|
|
PerlIO_clearerr(fp); |
674
|
5184
|
|
|
|
|
fd = PerlIO_fileno(fp); |
675
|
|
|
|
|
|
} |
676
|
|
|
|
|
|
#if defined(HAS_FCNTL) && defined(F_SETFD) |
677
|
3177945
|
100
|
|
|
|
if (fd >= 0) { |
678
|
3173561
|
|
|
|
|
dSAVE_ERRNO; |
679
|
3173561
|
|
|
|
|
fcntl(fd,F_SETFD,fd > PL_maxsysfd); /* can change errno */ |
680
|
3173561
|
|
|
|
|
RESTORE_ERRNO; |
681
|
|
|
|
|
|
} |
682
|
|
|
|
|
|
#endif |
683
|
3177945
|
|
|
|
|
IoIFP(io) = fp; |
684
|
|
|
|
|
|
|
685
|
3177945
|
|
|
|
|
IoFLAGS(io) &= ~IOf_NOLINE; |
686
|
3177945
|
100
|
|
|
|
if (writing) { |
687
|
395510
|
100
|
|
|
|
if (IoTYPE(io) == IoTYPE_SOCKET |
688
|
395506
|
100
|
|
|
|
|| (IoTYPE(io) == IoTYPE_WRONLY && fd >= 0 && S_ISCHR(PL_statbuf.st_mode)) ) { |
|
|
100
|
|
|
|
|
689
|
|
|
|
|
|
char *s = mode; |
690
|
312
|
100
|
|
|
|
if (*s == IoTYPE_IMPLICIT || *s == IoTYPE_NUMERIC) |
691
|
|
|
|
|
|
s++; |
692
|
312
|
|
|
|
|
*s = 'w'; |
693
|
312
|
50
|
|
|
|
if (!(IoOFP(io) = PerlIO_openn(aTHX_ type,s,fd,0,0,NULL,0,svp))) { |
694
|
0
|
|
|
|
|
PerlIO_close(fp); |
695
|
0
|
|
|
|
|
IoIFP(io) = NULL; |
696
|
0
|
|
|
|
|
goto say_false; |
697
|
|
|
|
|
|
} |
698
|
|
|
|
|
|
} |
699
|
|
|
|
|
|
else |
700
|
395198
|
|
|
|
|
IoOFP(io) = fp; |
701
|
|
|
|
|
|
} |
702
|
|
|
|
|
|
return TRUE; |
703
|
|
|
|
|
|
|
704
|
|
|
|
|
|
say_false: |
705
|
1688104
|
|
|
|
|
IoIFP(io) = saveifp; |
706
|
1688104
|
|
|
|
|
IoOFP(io) = saveofp; |
707
|
1688104
|
|
|
|
|
IoTYPE(io) = savetype; |
708
|
3277795
|
|
|
|
|
return FALSE; |
709
|
|
|
|
|
|
} |
710
|
|
|
|
|
|
|
711
|
|
|
|
|
|
PerlIO * |
712
|
682
|
|
|
|
|
Perl_nextargv(pTHX_ GV *gv) |
713
|
|
|
|
|
|
{ |
714
|
|
|
|
|
|
dVAR; |
715
|
|
|
|
|
|
SV *sv; |
716
|
|
|
|
|
|
#ifndef FLEXFILENAMES |
717
|
|
|
|
|
|
int filedev; |
718
|
|
|
|
|
|
int fileino; |
719
|
|
|
|
|
|
#endif |
720
|
|
|
|
|
|
Uid_t fileuid; |
721
|
|
|
|
|
|
Gid_t filegid; |
722
|
682
|
|
|
|
|
IO * const io = GvIOp(gv); |
723
|
|
|
|
|
|
|
724
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEXTARGV; |
725
|
|
|
|
|
|
|
726
|
682
|
100
|
|
|
|
if (!PL_argvoutgv) |
727
|
212
|
|
|
|
|
PL_argvoutgv = gv_fetchpvs("ARGVOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
728
|
682
|
50
|
|
|
|
if (io && (IoFLAGS(io) & IOf_ARGV) && (IoFLAGS(io) & IOf_START)) { |
|
|
100
|
|
|
|
|
729
|
88
|
|
|
|
|
IoFLAGS(io) &= ~IOf_START; |
730
|
88
|
100
|
|
|
|
if (PL_inplace) { |
731
|
|
|
|
|
|
assert(PL_defoutgv); |
732
|
24
|
|
|
|
|
Perl_av_create_and_push(aTHX_ &PL_argvout_stack, |
733
|
24
|
|
|
|
|
SvREFCNT_inc_simple_NN(PL_defoutgv)); |
734
|
|
|
|
|
|
} |
735
|
|
|
|
|
|
} |
736
|
682
|
50
|
|
|
|
if (PL_filemode & (S_ISUID|S_ISGID)) { |
737
|
0
|
0
|
|
|
|
PerlIO_flush(IoIFP(GvIOn(PL_argvoutgv))); /* chmod must follow last write */ |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
738
|
|
|
|
|
|
#ifdef HAS_FCHMOD |
739
|
0
|
0
|
|
|
|
if (PL_lastfd != -1) |
740
|
0
|
|
|
|
|
(void)fchmod(PL_lastfd,PL_filemode); |
741
|
|
|
|
|
|
#else |
742
|
|
|
|
|
|
(void)PerlLIO_chmod(PL_oldname,PL_filemode); |
743
|
|
|
|
|
|
#endif |
744
|
|
|
|
|
|
} |
745
|
682
|
|
|
|
|
PL_lastfd = -1; |
746
|
682
|
|
|
|
|
PL_filemode = 0; |
747
|
682
|
50
|
|
|
|
if (!GvAV(gv)) |
748
|
|
|
|
|
|
return NULL; |
749
|
688
|
100
|
|
|
|
while (av_len(GvAV(gv)) >= 0) { |
750
|
|
|
|
|
|
STRLEN oldlen; |
751
|
480
|
|
|
|
|
sv = av_shift(GvAV(gv)); |
752
|
480
|
|
|
|
|
SAVEFREESV(sv); |
753
|
480
|
50
|
|
|
|
SvTAINTED_off(GvSVn(gv)); /* previous tainting irrelevant */ |
|
|
0
|
|
|
|
|
754
|
480
|
100
|
|
|
|
sv_setsv(GvSVn(gv),sv); |
755
|
480
|
50
|
|
|
|
SvSETMAGIC(GvSV(gv)); |
756
|
480
|
50
|
|
|
|
PL_oldname = SvPVx(GvSV(gv), oldlen); |
757
|
480
|
50
|
|
|
|
if (do_open(gv,PL_oldname,oldlen,PL_inplace!=0,O_RDONLY,0,NULL)) { |
758
|
480
|
100
|
|
|
|
if (PL_inplace) { |
759
|
48
|
50
|
|
|
|
TAINT_PROPER("inplace open"); |
760
|
48
|
50
|
|
|
|
if (oldlen == 1 && *PL_oldname == '-') { |
|
|
0
|
|
|
|
|
761
|
0
|
|
|
|
|
setdefout(gv_fetchpvs("STDOUT", GV_ADD|GV_NOTQUAL, |
762
|
|
|
|
|
|
SVt_PVIO)); |
763
|
0
|
|
|
|
|
return IoIFP(GvIOp(gv)); |
764
|
|
|
|
|
|
} |
765
|
|
|
|
|
|
#ifndef FLEXFILENAMES |
766
|
|
|
|
|
|
filedev = PL_statbuf.st_dev; |
767
|
|
|
|
|
|
fileino = PL_statbuf.st_ino; |
768
|
|
|
|
|
|
#endif |
769
|
48
|
|
|
|
|
PL_filemode = PL_statbuf.st_mode; |
770
|
48
|
|
|
|
|
fileuid = PL_statbuf.st_uid; |
771
|
48
|
|
|
|
|
filegid = PL_statbuf.st_gid; |
772
|
48
|
100
|
|
|
|
if (!S_ISREG(PL_filemode)) { |
773
|
6
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE), |
774
|
|
|
|
|
|
"Can't do inplace edit: %s is not a regular file", |
775
|
|
|
|
|
|
PL_oldname ); |
776
|
6
|
|
|
|
|
do_close(gv,FALSE); |
777
|
6
|
|
|
|
|
continue; |
778
|
|
|
|
|
|
} |
779
|
42
|
100
|
|
|
|
if (*PL_inplace && strNE(PL_inplace, "*")) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
780
|
30
|
|
|
|
|
const char *star = strchr(PL_inplace, '*'); |
781
|
30
|
100
|
|
|
|
if (star) { |
782
|
6
|
|
|
|
|
const char *begin = PL_inplace; |
783
|
6
|
|
|
|
|
sv_setpvs(sv, ""); |
784
|
|
|
|
|
|
do { |
785
|
6
|
|
|
|
|
sv_catpvn(sv, begin, star - begin); |
786
|
6
|
|
|
|
|
sv_catpvn(sv, PL_oldname, oldlen); |
787
|
6
|
|
|
|
|
begin = ++star; |
788
|
6
|
50
|
|
|
|
} while ((star = strchr(begin, '*'))); |
789
|
6
|
50
|
|
|
|
if (*begin) |
790
|
0
|
|
|
|
|
sv_catpv(sv,begin); |
791
|
|
|
|
|
|
} |
792
|
|
|
|
|
|
else { |
793
|
24
|
|
|
|
|
sv_catpv(sv,PL_inplace); |
794
|
|
|
|
|
|
} |
795
|
|
|
|
|
|
#ifndef FLEXFILENAMES |
796
|
|
|
|
|
|
if ((PerlLIO_stat(SvPVX_const(sv),&PL_statbuf) >= 0 |
797
|
|
|
|
|
|
&& PL_statbuf.st_dev == filedev |
798
|
|
|
|
|
|
&& PL_statbuf.st_ino == fileino) |
799
|
|
|
|
|
|
#ifdef DJGPP |
800
|
|
|
|
|
|
|| ((_djstat_fail_bits & _STFAIL_TRUENAME)!=0) |
801
|
|
|
|
|
|
#endif |
802
|
|
|
|
|
|
) |
803
|
|
|
|
|
|
{ |
804
|
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE), |
805
|
|
|
|
|
|
"Can't do inplace edit: %"SVf" would not be unique", |
806
|
|
|
|
|
|
SVfARG(sv)); |
807
|
|
|
|
|
|
do_close(gv,FALSE); |
808
|
|
|
|
|
|
continue; |
809
|
|
|
|
|
|
} |
810
|
|
|
|
|
|
#endif |
811
|
|
|
|
|
|
#ifdef HAS_RENAME |
812
|
|
|
|
|
|
#if !defined(DOSISH) && !defined(__CYGWIN__) |
813
|
30
|
50
|
|
|
|
if (PerlLIO_rename(PL_oldname,SvPVX_const(sv)) < 0) { |
814
|
0
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE), |
815
|
|
|
|
|
|
"Can't rename %s to %"SVf": %s, skipping file", |
816
|
0
|
|
|
|
|
PL_oldname, SVfARG(sv), Strerror(errno)); |
817
|
0
|
|
|
|
|
do_close(gv,FALSE); |
818
|
0
|
|
|
|
|
continue; |
819
|
|
|
|
|
|
} |
820
|
|
|
|
|
|
#else |
821
|
|
|
|
|
|
do_close(gv,FALSE); |
822
|
|
|
|
|
|
(void)PerlLIO_unlink(SvPVX_const(sv)); |
823
|
|
|
|
|
|
(void)PerlLIO_rename(PL_oldname,SvPVX_const(sv)); |
824
|
|
|
|
|
|
do_open(gv,(char*)SvPVX_const(sv),SvCUR(sv),TRUE,O_RDONLY,0,NULL); |
825
|
|
|
|
|
|
#endif /* DOSISH */ |
826
|
|
|
|
|
|
#else |
827
|
|
|
|
|
|
(void)UNLINK(SvPVX_const(sv)); |
828
|
|
|
|
|
|
if (link(PL_oldname,SvPVX_const(sv)) < 0) { |
829
|
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE), |
830
|
|
|
|
|
|
"Can't rename %s to %"SVf": %s, skipping file", |
831
|
|
|
|
|
|
PL_oldname, SVfARG(sv), Strerror(errno) ); |
832
|
|
|
|
|
|
do_close(gv,FALSE); |
833
|
|
|
|
|
|
continue; |
834
|
|
|
|
|
|
} |
835
|
|
|
|
|
|
(void)UNLINK(PL_oldname); |
836
|
|
|
|
|
|
#endif |
837
|
|
|
|
|
|
} |
838
|
|
|
|
|
|
else { |
839
|
|
|
|
|
|
#if !defined(DOSISH) && !defined(AMIGAOS) |
840
|
|
|
|
|
|
# ifndef VMS /* Don't delete; use automatic file versioning */ |
841
|
12
|
50
|
|
|
|
if (UNLINK(PL_oldname) < 0) { |
842
|
0
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE), |
843
|
|
|
|
|
|
"Can't remove %s: %s, skipping file", |
844
|
0
|
|
|
|
|
PL_oldname, Strerror(errno) ); |
845
|
0
|
|
|
|
|
do_close(gv,FALSE); |
846
|
0
|
|
|
|
|
continue; |
847
|
|
|
|
|
|
} |
848
|
|
|
|
|
|
# endif |
849
|
|
|
|
|
|
#else |
850
|
|
|
|
|
|
Perl_croak(aTHX_ "Can't do inplace edit without backup"); |
851
|
|
|
|
|
|
#endif |
852
|
|
|
|
|
|
} |
853
|
|
|
|
|
|
|
854
|
42
|
|
|
|
|
sv_setpvn(sv,PL_oldname,oldlen); |
855
|
42
|
|
|
|
|
SETERRNO(0,0); /* in case sprintf set errno */ |
856
|
42
|
50
|
|
|
|
if (!Perl_do_openn(aTHX_ PL_argvoutgv, (char*)SvPVX_const(sv), |
857
|
42
|
|
|
|
|
SvCUR(sv), TRUE, |
858
|
|
|
|
|
|
#ifdef VMS |
859
|
|
|
|
|
|
O_WRONLY|O_CREAT|O_TRUNC,0, |
860
|
|
|
|
|
|
#else |
861
|
|
|
|
|
|
O_WRONLY|O_CREAT|OPEN_EXCL,0600, |
862
|
|
|
|
|
|
#endif |
863
|
|
|
|
|
|
NULL, NULL, 0)) { |
864
|
0
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE), "Can't do inplace edit on %s: %s", |
865
|
0
|
|
|
|
|
PL_oldname, Strerror(errno) ); |
866
|
0
|
|
|
|
|
do_close(gv,FALSE); |
867
|
0
|
|
|
|
|
continue; |
868
|
|
|
|
|
|
} |
869
|
42
|
|
|
|
|
setdefout(PL_argvoutgv); |
870
|
42
|
|
|
|
|
PL_lastfd = PerlIO_fileno(IoIFP(GvIOp(PL_argvoutgv))); |
871
|
42
|
|
|
|
|
(void)PerlLIO_fstat(PL_lastfd,&PL_statbuf); |
872
|
|
|
|
|
|
#ifdef HAS_FCHMOD |
873
|
42
|
|
|
|
|
(void)fchmod(PL_lastfd,PL_filemode); |
874
|
|
|
|
|
|
#else |
875
|
|
|
|
|
|
(void)PerlLIO_chmod(PL_oldname,PL_filemode); |
876
|
|
|
|
|
|
#endif |
877
|
42
|
50
|
|
|
|
if (fileuid != PL_statbuf.st_uid || filegid != PL_statbuf.st_gid) { |
|
|
50
|
|
|
|
|
878
|
|
|
|
|
|
#ifdef HAS_FCHOWN |
879
|
0
|
|
|
|
|
(void)fchown(PL_lastfd,fileuid,filegid); |
880
|
|
|
|
|
|
#else |
881
|
|
|
|
|
|
#ifdef HAS_CHOWN |
882
|
|
|
|
|
|
(void)PerlLIO_chown(PL_oldname,fileuid,filegid); |
883
|
|
|
|
|
|
#endif |
884
|
|
|
|
|
|
#endif |
885
|
|
|
|
|
|
} |
886
|
|
|
|
|
|
} |
887
|
474
|
|
|
|
|
return IoIFP(GvIOp(gv)); |
888
|
|
|
|
|
|
} |
889
|
|
|
|
|
|
else { |
890
|
0
|
0
|
|
|
|
if (ckWARN_d(WARN_INPLACE)) { |
891
|
0
|
|
|
|
|
const int eno = errno; |
892
|
0
|
0
|
|
|
|
if (PerlLIO_stat(PL_oldname, &PL_statbuf) >= 0 |
893
|
0
|
0
|
|
|
|
&& !S_ISREG(PL_statbuf.st_mode)) |
894
|
|
|
|
|
|
{ |
895
|
0
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_INPLACE), |
896
|
|
|
|
|
|
"Can't do inplace edit: %s is not a regular file", |
897
|
|
|
|
|
|
PL_oldname); |
898
|
|
|
|
|
|
} |
899
|
|
|
|
|
|
else |
900
|
3
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_INPLACE), "Can't open %s: %s", |
901
|
|
|
|
|
|
PL_oldname, Strerror(eno)); |
902
|
|
|
|
|
|
} |
903
|
|
|
|
|
|
} |
904
|
|
|
|
|
|
} |
905
|
208
|
50
|
|
|
|
if (io && (IoFLAGS(io) & IOf_ARGV)) |
|
|
50
|
|
|
|
|
906
|
208
|
|
|
|
|
IoFLAGS(io) |= IOf_START; |
907
|
208
|
100
|
|
|
|
if (PL_inplace) { |
908
|
22
|
|
|
|
|
(void)do_close(PL_argvoutgv,FALSE); |
909
|
22
|
50
|
|
|
|
if (io && (IoFLAGS(io) & IOf_ARGV) |
|
|
50
|
|
|
|
|
910
|
22
|
50
|
|
|
|
&& PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0) |
|
|
50
|
|
|
|
|
911
|
|
|
|
|
|
{ |
912
|
22
|
|
|
|
|
GV * const oldout = MUTABLE_GV(av_pop(PL_argvout_stack)); |
913
|
22
|
|
|
|
|
setdefout(oldout); |
914
|
|
|
|
|
|
SvREFCNT_dec_NN(oldout); |
915
|
|
|
|
|
|
return NULL; |
916
|
|
|
|
|
|
} |
917
|
341
|
|
|
|
|
setdefout(gv_fetchpvs("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO)); |
918
|
|
|
|
|
|
} |
919
|
|
|
|
|
|
return NULL; |
920
|
|
|
|
|
|
} |
921
|
|
|
|
|
|
|
922
|
|
|
|
|
|
/* explicit renamed to avoid C++ conflict -- kja */ |
923
|
|
|
|
|
|
bool |
924
|
2438308
|
|
|
|
|
Perl_do_close(pTHX_ GV *gv, bool not_implicit) |
925
|
|
|
|
|
|
{ |
926
|
|
|
|
|
|
dVAR; |
927
|
|
|
|
|
|
bool retval; |
928
|
|
|
|
|
|
IO *io; |
929
|
|
|
|
|
|
|
930
|
2438308
|
50
|
|
|
|
if (!gv) |
931
|
0
|
|
|
|
|
gv = PL_argvgv; |
932
|
2438308
|
50
|
|
|
|
if (!gv || !isGV_with_GP(gv)) { |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
933
|
16
|
50
|
|
|
|
if (not_implicit) |
934
|
16
|
|
|
|
|
SETERRNO(EBADF,SS_IVCHAN); |
935
|
|
|
|
|
|
return FALSE; |
936
|
|
|
|
|
|
} |
937
|
2438292
|
50
|
|
|
|
io = GvIO(gv); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
938
|
2438292
|
100
|
|
|
|
if (!io) { /* never opened */ |
939
|
12
|
50
|
|
|
|
if (not_implicit) { |
940
|
12
|
|
|
|
|
report_evil_fh(gv); |
941
|
10
|
|
|
|
|
SETERRNO(EBADF,SS_IVCHAN); |
942
|
|
|
|
|
|
} |
943
|
|
|
|
|
|
return FALSE; |
944
|
|
|
|
|
|
} |
945
|
2438280
|
|
|
|
|
retval = io_close(io, not_implicit); |
946
|
2438276
|
100
|
|
|
|
if (not_implicit) { |
947
|
2437582
|
|
|
|
|
IoLINES(io) = 0; |
948
|
2437582
|
|
|
|
|
IoPAGE(io) = 0; |
949
|
2437582
|
|
|
|
|
IoLINES_LEFT(io) = IoPAGE_LEN(io); |
950
|
|
|
|
|
|
} |
951
|
2438276
|
|
|
|
|
IoTYPE(io) = IoTYPE_CLOSED; |
952
|
2438289
|
|
|
|
|
return retval; |
953
|
|
|
|
|
|
} |
954
|
|
|
|
|
|
|
955
|
|
|
|
|
|
bool |
956
|
3178831
|
|
|
|
|
Perl_io_close(pTHX_ IO *io, bool not_implicit) |
957
|
|
|
|
|
|
{ |
958
|
|
|
|
|
|
dVAR; |
959
|
|
|
|
|
|
bool retval = FALSE; |
960
|
|
|
|
|
|
|
961
|
|
|
|
|
|
PERL_ARGS_ASSERT_IO_CLOSE; |
962
|
|
|
|
|
|
|
963
|
3178831
|
100
|
|
|
|
if (IoIFP(io)) { |
964
|
3178471
|
100
|
|
|
|
if (IoTYPE(io) == IoTYPE_PIPE) { |
965
|
7592
|
|
|
|
|
const int status = PerlProc_pclose(IoIFP(io)); |
966
|
7592
|
100
|
|
|
|
if (not_implicit) { |
967
|
5826
|
100
|
|
|
|
STATUS_NATIVE_CHILD_SET(status); |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
968
|
5826
|
|
|
|
|
retval = (STATUS_UNIX == 0); |
969
|
|
|
|
|
|
} |
970
|
|
|
|
|
|
else { |
971
|
1766
|
|
|
|
|
retval = (status != -1); |
972
|
|
|
|
|
|
} |
973
|
|
|
|
|
|
} |
974
|
3170879
|
100
|
|
|
|
else if (IoTYPE(io) == IoTYPE_STD) |
975
|
|
|
|
|
|
retval = TRUE; |
976
|
|
|
|
|
|
else { |
977
|
3171001
|
100
|
|
|
|
if (IoOFP(io) && IoOFP(io) != IoIFP(io)) { /* a socket */ |
|
|
100
|
|
|
|
|
978
|
268
|
|
|
|
|
const bool prev_err = PerlIO_error(IoOFP(io)); |
979
|
268
|
50
|
|
|
|
retval = (PerlIO_close(IoOFP(io)) != EOF && !prev_err); |
|
|
50
|
|
|
|
|
980
|
268
|
|
|
|
|
PerlIO_close(IoIFP(io)); /* clear stdio, fd already closed */ |
981
|
|
|
|
|
|
} |
982
|
|
|
|
|
|
else { |
983
|
3170465
|
|
|
|
|
const bool prev_err = PerlIO_error(IoIFP(io)); |
984
|
3170465
|
100
|
|
|
|
retval = (PerlIO_close(IoIFP(io)) != EOF && !prev_err); |
|
|
100
|
|
|
|
|
985
|
|
|
|
|
|
} |
986
|
|
|
|
|
|
} |
987
|
3178465
|
|
|
|
|
IoOFP(io) = IoIFP(io) = NULL; |
988
|
|
|
|
|
|
} |
989
|
360
|
100
|
|
|
|
else if (not_implicit) { |
990
|
348
|
|
|
|
|
SETERRNO(EBADF,SS_IVCHAN); |
991
|
|
|
|
|
|
} |
992
|
|
|
|
|
|
|
993
|
3178825
|
|
|
|
|
return retval; |
994
|
|
|
|
|
|
} |
995
|
|
|
|
|
|
|
996
|
|
|
|
|
|
bool |
997
|
35126
|
|
|
|
|
Perl_do_eof(pTHX_ GV *gv) |
998
|
|
|
|
|
|
{ |
999
|
|
|
|
|
|
dVAR; |
1000
|
35126
|
50
|
|
|
|
IO * const io = GvIO(gv); |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
1001
|
|
|
|
|
|
|
1002
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_EOF; |
1003
|
|
|
|
|
|
|
1004
|
35126
|
100
|
|
|
|
if (!io) |
1005
|
|
|
|
|
|
return TRUE; |
1006
|
35024
|
100
|
|
|
|
else if (IoTYPE(io) == IoTYPE_WRONLY) |
1007
|
4
|
|
|
|
|
report_wrongway_fh(gv, '>'); |
1008
|
|
|
|
|
|
|
1009
|
52582
|
100
|
|
|
|
while (IoIFP(io)) { |
1010
|
35004
|
50
|
|
|
|
if (PerlIO_has_cntptr(IoIFP(io))) { /* (the code works without this) */ |
1011
|
35004
|
100
|
|
|
|
if (PerlIO_get_cnt(IoIFP(io)) > 0) /* cheat a little, since */ |
1012
|
|
|
|
|
|
return FALSE; /* this is the most usual case */ |
1013
|
|
|
|
|
|
} |
1014
|
|
|
|
|
|
|
1015
|
|
|
|
|
|
{ |
1016
|
|
|
|
|
|
/* getc and ungetc can stomp on errno */ |
1017
|
204
|
|
|
|
|
dSAVE_ERRNO; |
1018
|
204
|
|
|
|
|
const int ch = PerlIO_getc(IoIFP(io)); |
1019
|
204
|
100
|
|
|
|
if (ch != EOF) { |
1020
|
94
|
|
|
|
|
(void)PerlIO_ungetc(IoIFP(io),ch); |
1021
|
94
|
|
|
|
|
RESTORE_ERRNO; |
1022
|
94
|
|
|
|
|
return FALSE; |
1023
|
|
|
|
|
|
} |
1024
|
110
|
|
|
|
|
RESTORE_ERRNO; |
1025
|
|
|
|
|
|
} |
1026
|
|
|
|
|
|
|
1027
|
110
|
50
|
|
|
|
if (PerlIO_has_cntptr(IoIFP(io)) && PerlIO_canset_cnt(IoIFP(io))) { |
|
|
50
|
|
|
|
|
1028
|
110
|
50
|
|
|
|
if (PerlIO_get_cnt(IoIFP(io)) < -1) |
1029
|
0
|
|
|
|
|
PerlIO_set_cnt(IoIFP(io),-1); |
1030
|
|
|
|
|
|
} |
1031
|
110
|
100
|
|
|
|
if (PL_op->op_flags & OPf_SPECIAL) { /* not necessarily a real EOF yet? */ |
1032
|
17530
|
100
|
|
|
|
if (gv != PL_argvgv || !nextargv(gv)) /* get another fp handy */ |
|
|
100
|
|
|
|
|
1033
|
|
|
|
|
|
return TRUE; |
1034
|
|
|
|
|
|
} |
1035
|
|
|
|
|
|
else |
1036
|
|
|
|
|
|
return TRUE; /* normal fp, definitely end of file */ |
1037
|
|
|
|
|
|
} |
1038
|
|
|
|
|
|
return TRUE; |
1039
|
|
|
|
|
|
} |
1040
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
Off_t |
1042
|
10260
|
|
|
|
|
Perl_do_tell(pTHX_ GV *gv) |
1043
|
|
|
|
|
|
{ |
1044
|
|
|
|
|
|
dVAR; |
1045
|
10260
|
50
|
|
|
|
IO *const io = GvIO(gv); |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
1046
|
|
|
|
|
|
PerlIO *fp; |
1047
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_TELL; |
1049
|
|
|
|
|
|
|
1050
|
10260
|
100
|
|
|
|
if (io && (fp = IoIFP(io))) { |
|
|
100
|
|
|
|
|
1051
|
|
|
|
|
|
#ifdef ULTRIX_STDIO_BOTCH |
1052
|
|
|
|
|
|
if (PerlIO_eof(fp)) |
1053
|
|
|
|
|
|
(void)PerlIO_seek(fp, 0L, 2); /* ultrix 1.2 workaround */ |
1054
|
|
|
|
|
|
#endif |
1055
|
10242
|
|
|
|
|
return PerlIO_tell(fp); |
1056
|
|
|
|
|
|
} |
1057
|
18
|
|
|
|
|
report_evil_fh(gv); |
1058
|
18
|
|
|
|
|
SETERRNO(EBADF,RMS_IFI); |
1059
|
5139
|
|
|
|
|
return (Off_t)-1; |
1060
|
|
|
|
|
|
} |
1061
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
bool |
1063
|
60830
|
|
|
|
|
Perl_do_seek(pTHX_ GV *gv, Off_t pos, int whence) |
1064
|
|
|
|
|
|
{ |
1065
|
|
|
|
|
|
dVAR; |
1066
|
60830
|
50
|
|
|
|
IO *const io = GvIO(gv); |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
1067
|
|
|
|
|
|
PerlIO *fp; |
1068
|
|
|
|
|
|
|
1069
|
60830
|
100
|
|
|
|
if (io && (fp = IoIFP(io))) { |
|
|
100
|
|
|
|
|
1070
|
|
|
|
|
|
#ifdef ULTRIX_STDIO_BOTCH |
1071
|
|
|
|
|
|
if (PerlIO_eof(fp)) |
1072
|
|
|
|
|
|
(void)PerlIO_seek(fp, 0L, 2); /* ultrix 1.2 workaround */ |
1073
|
|
|
|
|
|
#endif |
1074
|
60818
|
|
|
|
|
return PerlIO_seek(fp, pos, whence) >= 0; |
1075
|
|
|
|
|
|
} |
1076
|
12
|
|
|
|
|
report_evil_fh(gv); |
1077
|
12
|
|
|
|
|
SETERRNO(EBADF,RMS_IFI); |
1078
|
30421
|
|
|
|
|
return FALSE; |
1079
|
|
|
|
|
|
} |
1080
|
|
|
|
|
|
|
1081
|
|
|
|
|
|
Off_t |
1082
|
224
|
|
|
|
|
Perl_do_sysseek(pTHX_ GV *gv, Off_t pos, int whence) |
1083
|
|
|
|
|
|
{ |
1084
|
|
|
|
|
|
dVAR; |
1085
|
224
|
50
|
|
|
|
IO *const io = GvIO(gv); |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
1086
|
|
|
|
|
|
PerlIO *fp; |
1087
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_SYSSEEK; |
1089
|
|
|
|
|
|
|
1090
|
224
|
100
|
|
|
|
if (io && (fp = IoIFP(io))) |
|
|
100
|
|
|
|
|
1091
|
214
|
|
|
|
|
return PerlLIO_lseek(PerlIO_fileno(fp), pos, whence); |
1092
|
10
|
|
|
|
|
report_evil_fh(gv); |
1093
|
10
|
|
|
|
|
SETERRNO(EBADF,RMS_IFI); |
1094
|
117
|
|
|
|
|
return (Off_t)-1; |
1095
|
|
|
|
|
|
} |
1096
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
int |
1098
|
3113011
|
|
|
|
|
Perl_mode_from_discipline(pTHX_ const char *s, STRLEN len) |
1099
|
|
|
|
|
|
{ |
1100
|
|
|
|
|
|
int mode = O_BINARY; |
1101
|
3113011
|
100
|
|
|
|
if (s) { |
1102
|
29072
|
100
|
|
|
|
while (*s) { |
1103
|
17636
|
100
|
|
|
|
if (*s == ':') { |
1104
|
15920
|
|
|
|
|
switch (s[1]) { |
1105
|
|
|
|
|
|
case 'r': |
1106
|
6136
|
50
|
|
|
|
if (s[2] == 'a' && s[3] == 'w' |
|
|
50
|
|
|
|
|
1107
|
6136
|
100
|
|
|
|
&& (!s[4] || s[4] == ':' || isSPACE(s[4]))) |
|
|
50
|
|
|
|
|
1108
|
|
|
|
|
|
{ |
1109
|
|
|
|
|
|
mode = O_BINARY; |
1110
|
6136
|
|
|
|
|
s += 4; |
1111
|
6136
|
|
|
|
|
len -= 4; |
1112
|
6136
|
|
|
|
|
break; |
1113
|
|
|
|
|
|
} |
1114
|
|
|
|
|
|
/* FALL THROUGH */ |
1115
|
|
|
|
|
|
case 'c': |
1116
|
1898
|
50
|
|
|
|
if (s[2] == 'r' && s[3] == 'l' && s[4] == 'f' |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1117
|
1898
|
50
|
|
|
|
&& (!s[5] || s[5] == ':' || isSPACE(s[5]))) |
|
|
0
|
|
|
|
|
1118
|
|
|
|
|
|
{ |
1119
|
|
|
|
|
|
mode = O_TEXT; |
1120
|
1898
|
|
|
|
|
s += 5; |
1121
|
1898
|
|
|
|
|
len -= 5; |
1122
|
1898
|
|
|
|
|
break; |
1123
|
|
|
|
|
|
} |
1124
|
|
|
|
|
|
/* FALL THROUGH */ |
1125
|
|
|
|
|
|
default: |
1126
|
|
|
|
|
|
goto fail_discipline; |
1127
|
|
|
|
|
|
} |
1128
|
|
|
|
|
|
} |
1129
|
1716
|
100
|
|
|
|
else if (isSPACE(*s)) { |
1130
|
80
|
|
|
|
|
++s; |
1131
|
80
|
|
|
|
|
--len; |
1132
|
|
|
|
|
|
} |
1133
|
|
|
|
|
|
else { |
1134
|
|
|
|
|
|
const char *end; |
1135
|
|
|
|
|
|
fail_discipline: |
1136
|
9522
|
|
|
|
|
end = strchr(s+1, ':'); |
1137
|
9522
|
100
|
|
|
|
if (!end) |
1138
|
9492
|
|
|
|
|
end = s+len; |
1139
|
|
|
|
|
|
#ifndef PERLIO_LAYERS |
1140
|
|
|
|
|
|
Perl_croak(aTHX_ "IO layers (like '%.*s') unavailable", end-s, s); |
1141
|
|
|
|
|
|
#else |
1142
|
13579
|
|
|
|
|
len -= end-s; |
1143
|
|
|
|
|
|
s = end; |
1144
|
|
|
|
|
|
#endif |
1145
|
|
|
|
|
|
} |
1146
|
|
|
|
|
|
} |
1147
|
|
|
|
|
|
} |
1148
|
3113011
|
|
|
|
|
return mode; |
1149
|
|
|
|
|
|
} |
1150
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
#if !defined(HAS_TRUNCATE) && !defined(HAS_CHSIZE) |
1152
|
|
|
|
|
|
I32 |
1153
|
|
|
|
|
|
my_chsize(int fd, Off_t length) |
1154
|
|
|
|
|
|
{ |
1155
|
|
|
|
|
|
#ifdef F_FREESP |
1156
|
|
|
|
|
|
/* code courtesy of William Kucharski */ |
1157
|
|
|
|
|
|
#define HAS_CHSIZE |
1158
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
Stat_t filebuf; |
1160
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
if (PerlLIO_fstat(fd, &filebuf) < 0) |
1162
|
|
|
|
|
|
return -1; |
1163
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
if (filebuf.st_size < length) { |
1165
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
/* extend file length */ |
1167
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
if ((PerlLIO_lseek(fd, (length - 1), 0)) < 0) |
1169
|
|
|
|
|
|
return -1; |
1170
|
|
|
|
|
|
|
1171
|
|
|
|
|
|
/* write a "0" byte */ |
1172
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
if ((PerlLIO_write(fd, "", 1)) != 1) |
1174
|
|
|
|
|
|
return -1; |
1175
|
|
|
|
|
|
} |
1176
|
|
|
|
|
|
else { |
1177
|
|
|
|
|
|
/* truncate length */ |
1178
|
|
|
|
|
|
struct flock fl; |
1179
|
|
|
|
|
|
fl.l_whence = 0; |
1180
|
|
|
|
|
|
fl.l_len = 0; |
1181
|
|
|
|
|
|
fl.l_start = length; |
1182
|
|
|
|
|
|
fl.l_type = F_WRLCK; /* write lock on file space */ |
1183
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
/* |
1185
|
|
|
|
|
|
* This relies on the UNDOCUMENTED F_FREESP argument to |
1186
|
|
|
|
|
|
* fcntl(2), which truncates the file so that it ends at the |
1187
|
|
|
|
|
|
* position indicated by fl.l_start. |
1188
|
|
|
|
|
|
* |
1189
|
|
|
|
|
|
* Will minor miracles never cease? |
1190
|
|
|
|
|
|
*/ |
1191
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
if (fcntl(fd, F_FREESP, &fl) < 0) |
1193
|
|
|
|
|
|
return -1; |
1194
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
} |
1196
|
|
|
|
|
|
return 0; |
1197
|
|
|
|
|
|
#else |
1198
|
|
|
|
|
|
Perl_croak_nocontext("truncate not implemented"); |
1199
|
|
|
|
|
|
#endif /* F_FREESP */ |
1200
|
|
|
|
|
|
return -1; |
1201
|
|
|
|
|
|
} |
1202
|
|
|
|
|
|
#endif /* !HAS_TRUNCATE && !HAS_CHSIZE */ |
1203
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
bool |
1205
|
5504814
|
|
|
|
|
Perl_do_print(pTHX_ SV *sv, PerlIO *fp) |
1206
|
|
|
|
|
|
{ |
1207
|
|
|
|
|
|
dVAR; |
1208
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_PRINT; |
1210
|
|
|
|
|
|
|
1211
|
|
|
|
|
|
/* assuming fp is checked earlier */ |
1212
|
5504814
|
50
|
|
|
|
if (!sv) |
1213
|
|
|
|
|
|
return TRUE; |
1214
|
5504814
|
100
|
|
|
|
if (SvTYPE(sv) == SVt_IV && SvIOK(sv)) { |
1215
|
|
|
|
|
|
assert(!SvGMAGICAL(sv)); |
1216
|
107410
|
50
|
|
|
|
if (SvIsUV(sv)) |
1217
|
0
|
|
|
|
|
PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv)); |
1218
|
|
|
|
|
|
else |
1219
|
107410
|
|
|
|
|
PerlIO_printf(fp, "%"IVdf, (IV)SvIVX(sv)); |
1220
|
107410
|
|
|
|
|
return !PerlIO_error(fp); |
1221
|
|
|
|
|
|
} |
1222
|
|
|
|
|
|
else { |
1223
|
|
|
|
|
|
STRLEN len; |
1224
|
|
|
|
|
|
/* Do this first to trigger any overloading. */ |
1225
|
5397404
|
100
|
|
|
|
const char *tmps = SvPV_const(sv, len); |
1226
|
|
|
|
|
|
U8 *tmpbuf = NULL; |
1227
|
|
|
|
|
|
bool happy = TRUE; |
1228
|
|
|
|
|
|
|
1229
|
5397400
|
100
|
|
|
|
if (PerlIO_isutf8(fp)) { /* If the stream is utf8 ... */ |
1230
|
174938
|
100
|
|
|
|
if (!SvUTF8(sv)) { /* Convert to utf8 if necessary */ |
1231
|
|
|
|
|
|
/* We don't modify the original scalar. */ |
1232
|
149776
|
|
|
|
|
tmpbuf = bytes_to_utf8((const U8*) tmps, &len); |
1233
|
|
|
|
|
|
tmps = (char *) tmpbuf; |
1234
|
|
|
|
|
|
} |
1235
|
25162
|
100
|
|
|
|
else if (ckWARN4_d(WARN_UTF8, WARN_SURROGATE, WARN_NON_UNICODE, WARN_NONCHAR)) { |
1236
|
21060
|
|
|
|
|
(void) check_utf8_print((const U8*) tmps, len); |
1237
|
|
|
|
|
|
} |
1238
|
|
|
|
|
|
} /* else stream isn't utf8 */ |
1239
|
5222462
|
100
|
|
|
|
else if (DO_UTF8(sv)) { /* But if is utf8 internally, attempt to |
|
|
50
|
|
|
|
|
1240
|
|
|
|
|
|
convert to bytes */ |
1241
|
1582
|
|
|
|
|
STRLEN tmplen = len; |
1242
|
1582
|
|
|
|
|
bool utf8 = TRUE; |
1243
|
1582
|
|
|
|
|
U8 * const result = bytes_from_utf8((const U8*) tmps, &tmplen, &utf8); |
1244
|
1582
|
100
|
|
|
|
if (!utf8) { |
1245
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
/* Here, succeeded in downgrading from utf8. Set up to below |
1247
|
|
|
|
|
|
* output the converted value */ |
1248
|
|
|
|
|
|
tmpbuf = result; |
1249
|
|
|
|
|
|
tmps = (char *) tmpbuf; |
1250
|
1550
|
|
|
|
|
len = tmplen; |
1251
|
|
|
|
|
|
} |
1252
|
|
|
|
|
|
else { /* Non-utf8 output stream, but string only representable in |
1253
|
|
|
|
|
|
utf8 */ |
1254
|
|
|
|
|
|
assert((char *)result == tmps); |
1255
|
64
|
50
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_UTF8), |
1256
|
|
|
|
|
|
"Wide character in %s", |
1257
|
48
|
50
|
|
|
|
PL_op ? OP_DESC(PL_op) : "print" |
|
|
0
|
|
|
|
|
1258
|
|
|
|
|
|
); |
1259
|
|
|
|
|
|
/* Could also check that isn't one of the things to avoid |
1260
|
|
|
|
|
|
* in utf8 by using check_utf8_print(), but not doing so, |
1261
|
|
|
|
|
|
* since the stream isn't a UTF8 stream */ |
1262
|
|
|
|
|
|
} |
1263
|
|
|
|
|
|
} |
1264
|
|
|
|
|
|
/* To detect whether the process is about to overstep its |
1265
|
|
|
|
|
|
* filesize limit we would need getrlimit(). We could then |
1266
|
|
|
|
|
|
* also transparently raise the limit with setrlimit() -- |
1267
|
|
|
|
|
|
* but only until the system hard limit/the filesystem limit, |
1268
|
|
|
|
|
|
* at which we would get EPERM. Note that when using buffered |
1269
|
|
|
|
|
|
* io the write failure can be delayed until the flush/close. --jhi */ |
1270
|
5397396
|
100
|
|
|
|
if (len && (PerlIO_write(fp,tmps,len) == 0)) |
|
|
100
|
|
|
|
|
1271
|
|
|
|
|
|
happy = FALSE; |
1272
|
5397394
|
|
|
|
|
Safefree(tmpbuf); |
1273
|
5451099
|
100
|
|
|
|
return happy ? !PerlIO_error(fp) : FALSE; |
1274
|
|
|
|
|
|
} |
1275
|
|
|
|
|
|
} |
1276
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
I32 |
1278
|
1158680
|
|
|
|
|
Perl_my_stat_flags(pTHX_ const U32 flags) |
1279
|
|
|
|
|
|
{ |
1280
|
|
|
|
|
|
dVAR; |
1281
|
1158680
|
|
|
|
|
dSP; |
1282
|
|
|
|
|
|
IO *io; |
1283
|
|
|
|
|
|
GV* gv; |
1284
|
|
|
|
|
|
|
1285
|
1158680
|
100
|
|
|
|
if (PL_op->op_flags & OPf_REF) { |
1286
|
106428
|
|
|
|
|
gv = cGVOP_gv; |
1287
|
|
|
|
|
|
do_fstat: |
1288
|
109926
|
100
|
|
|
|
if (gv == PL_defgv) |
1289
|
104570
|
|
|
|
|
return PL_laststatval; |
1290
|
5356
|
50
|
|
|
|
io = GvIO(gv); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1291
|
|
|
|
|
|
do_fstat_have_io: |
1292
|
5410
|
|
|
|
|
PL_laststype = OP_STAT; |
1293
|
5410
|
100
|
|
|
|
PL_statgv = gv ? gv : (GV *)io; |
1294
|
5410
|
|
|
|
|
sv_setpvs(PL_statname, ""); |
1295
|
5410
|
100
|
|
|
|
if(io) { |
1296
|
5406
|
100
|
|
|
|
if (IoIFP(io)) { |
1297
|
10696
|
|
|
|
|
return (PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache)); |
1298
|
58
|
100
|
|
|
|
} else if (IoDIRP(io)) { |
1299
|
8
|
|
|
|
|
return (PL_laststatval = PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache)); |
1300
|
|
|
|
|
|
} |
1301
|
|
|
|
|
|
} |
1302
|
58
|
|
|
|
|
PL_laststatval = -1; |
1303
|
58
|
|
|
|
|
report_evil_fh(gv); |
1304
|
54
|
|
|
|
|
return -1; |
1305
|
|
|
|
|
|
} |
1306
|
1052252
|
100
|
|
|
|
else if ((PL_op->op_private & (OPpFT_STACKED|OPpFT_AFTER_t)) |
1307
|
|
|
|
|
|
== OPpFT_STACKED) |
1308
|
68
|
|
|
|
|
return PL_laststatval; |
1309
|
|
|
|
|
|
else { |
1310
|
1052184
|
|
|
|
|
SV* const sv = TOPs; |
1311
|
|
|
|
|
|
const char *s; |
1312
|
|
|
|
|
|
STRLEN len; |
1313
|
1052184
|
50
|
|
|
|
if ((gv = MAYBE_DEREF_GV_flags(sv,flags))) { |
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
1314
|
|
|
|
|
|
goto do_fstat; |
1315
|
|
|
|
|
|
} |
1316
|
1048686
|
100
|
|
|
|
else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) { |
|
|
100
|
|
|
|
|
1317
|
54
|
|
|
|
|
io = MUTABLE_IO(SvRV(sv)); |
1318
|
|
|
|
|
|
gv = NULL; |
1319
|
54
|
|
|
|
|
goto do_fstat_have_io; |
1320
|
|
|
|
|
|
} |
1321
|
|
|
|
|
|
|
1322
|
1048632
|
100
|
|
|
|
s = SvPV_flags_const(sv, len, flags); |
1323
|
1048632
|
|
|
|
|
PL_statgv = NULL; |
1324
|
1048632
|
|
|
|
|
sv_setpvn(PL_statname, s, len); |
1325
|
1048632
|
|
|
|
|
s = SvPVX_const(PL_statname); /* s now NUL-terminated */ |
1326
|
1048632
|
|
|
|
|
PL_laststype = OP_STAT; |
1327
|
1048632
|
|
|
|
|
PL_laststatval = PerlLIO_stat(s, &PL_statcache); |
1328
|
1048632
|
100
|
|
|
|
if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(s, '\n')) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
1329
|
0
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "stat"); |
1330
|
1103654
|
|
|
|
|
return PL_laststatval; |
1331
|
|
|
|
|
|
} |
1332
|
|
|
|
|
|
} |
1333
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
I32 |
1336
|
388790
|
|
|
|
|
Perl_my_lstat_flags(pTHX_ const U32 flags) |
1337
|
|
|
|
|
|
{ |
1338
|
|
|
|
|
|
dVAR; |
1339
|
|
|
|
|
|
static const char* const no_prev_lstat = "The stat preceding -l _ wasn't an lstat"; |
1340
|
388790
|
|
|
|
|
dSP; |
1341
|
|
|
|
|
|
const char *file; |
1342
|
388790
|
|
|
|
|
SV* const sv = TOPs; |
1343
|
|
|
|
|
|
bool isio = FALSE; |
1344
|
388790
|
100
|
|
|
|
if (PL_op->op_flags & OPf_REF) { |
1345
|
336
|
100
|
|
|
|
if (cGVOP_gv == PL_defgv) { |
1346
|
324
|
100
|
|
|
|
if (PL_laststype != OP_LSTAT) |
1347
|
6
|
|
|
|
|
Perl_croak(aTHX_ "%s", no_prev_lstat); |
1348
|
318
|
|
|
|
|
return PL_laststatval; |
1349
|
|
|
|
|
|
} |
1350
|
12
|
|
|
|
|
PL_laststatval = -1; |
1351
|
12
|
100
|
|
|
|
if (ckWARN(WARN_IO)) { |
1352
|
|
|
|
|
|
/* diag_listed_as: Use of -l on filehandle%s */ |
1353
|
6
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_IO), |
1354
|
|
|
|
|
|
"Use of -l on filehandle %"HEKf, |
1355
|
6
|
50
|
|
|
|
HEKfARG(GvENAME_HEK(cGVOP_gv))); |
1356
|
|
|
|
|
|
} |
1357
|
|
|
|
|
|
return -1; |
1358
|
|
|
|
|
|
} |
1359
|
388454
|
100
|
|
|
|
if ((PL_op->op_private & (OPpFT_STACKED|OPpFT_AFTER_t)) |
1360
|
|
|
|
|
|
== OPpFT_STACKED) { |
1361
|
8
|
100
|
|
|
|
if (PL_laststype != OP_LSTAT) |
1362
|
6
|
|
|
|
|
Perl_croak(aTHX_ "%s", no_prev_lstat); |
1363
|
2
|
|
|
|
|
return PL_laststatval; |
1364
|
|
|
|
|
|
} |
1365
|
|
|
|
|
|
|
1366
|
388446
|
|
|
|
|
PL_laststype = OP_LSTAT; |
1367
|
388446
|
|
|
|
|
PL_statgv = NULL; |
1368
|
388446
|
100
|
|
|
|
if ( ( (SvROK(sv) && ( isGV_with_GP(SvRV(sv)) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
1369
|
8
|
100
|
|
|
|
|| (isio = SvTYPE(SvRV(sv)) == SVt_PVIO) ) |
1370
|
|
|
|
|
|
) |
1371
|
388432
|
100
|
|
|
|
|| isGV_with_GP(sv) |
|
|
50
|
|
|
|
|
1372
|
|
|
|
|
|
) |
1373
|
18
|
100
|
|
|
|
&& ckWARN(WARN_IO)) { |
1374
|
10
|
100
|
|
|
|
if (isio) |
1375
|
|
|
|
|
|
/* diag_listed_as: Use of -l on filehandle%s */ |
1376
|
2
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_IO), |
1377
|
|
|
|
|
|
"Use of -l on filehandle"); |
1378
|
|
|
|
|
|
else |
1379
|
|
|
|
|
|
/* diag_listed_as: Use of -l on filehandle%s */ |
1380
|
8
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_IO), |
1381
|
|
|
|
|
|
"Use of -l on filehandle %"HEKf, |
1382
|
8
|
100
|
|
|
|
GvENAME_HEK((const GV *) |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
0
|
|
|
|
|
1383
|
|
|
|
|
|
(SvROK(sv) ? SvRV(sv) : sv))); |
1384
|
|
|
|
|
|
} |
1385
|
388446
|
100
|
|
|
|
file = SvPV_flags_const_nolen(sv, flags); |
1386
|
388446
|
|
|
|
|
sv_setpv(PL_statname,file); |
1387
|
388446
|
|
|
|
|
PL_laststatval = PerlLIO_lstat(file,&PL_statcache); |
1388
|
388446
|
100
|
|
|
|
if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(file, '\n')) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
1389
|
0
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "lstat"); |
1390
|
388611
|
|
|
|
|
return PL_laststatval; |
1391
|
|
|
|
|
|
} |
1392
|
|
|
|
|
|
|
1393
|
|
|
|
|
|
static void |
1394
|
10
|
|
|
|
|
S_exec_failed(pTHX_ const char *cmd, int fd, int do_report) |
1395
|
|
|
|
|
|
{ |
1396
|
10
|
|
|
|
|
const int e = errno; |
1397
|
|
|
|
|
|
PERL_ARGS_ASSERT_EXEC_FAILED; |
1398
|
10
|
100
|
|
|
|
if (ckWARN(WARN_EXEC)) |
1399
|
4
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't exec \"%s\": %s", |
1400
|
|
|
|
|
|
cmd, Strerror(e)); |
1401
|
10
|
50
|
|
|
|
if (do_report) { |
1402
|
0
|
|
|
|
|
PerlLIO_write(fd, (void*)&e, sizeof(int)); |
1403
|
0
|
|
|
|
|
PerlLIO_close(fd); |
1404
|
|
|
|
|
|
} |
1405
|
10
|
|
|
|
|
} |
1406
|
|
|
|
|
|
|
1407
|
|
|
|
|
|
bool |
1408
|
10
|
|
|
|
|
Perl_do_aexec5(pTHX_ SV *really, SV **mark, SV **sp, |
1409
|
|
|
|
|
|
int fd, int do_report) |
1410
|
|
|
|
|
|
{ |
1411
|
|
|
|
|
|
dVAR; |
1412
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_AEXEC5; |
1413
|
|
|
|
|
|
#if defined(__SYMBIAN32__) || defined(__LIBCATAMOUNT__) |
1414
|
|
|
|
|
|
Perl_croak(aTHX_ "exec? I'm not *that* kind of operating system"); |
1415
|
|
|
|
|
|
#else |
1416
|
10
|
50
|
|
|
|
if (sp > mark) { |
1417
|
|
|
|
|
|
const char **a; |
1418
|
|
|
|
|
|
const char *tmps = NULL; |
1419
|
10
|
50
|
|
|
|
Newx(PL_Argv, sp - mark + 1, const char*); |
1420
|
10
|
|
|
|
|
a = PL_Argv; |
1421
|
|
|
|
|
|
|
1422
|
35
|
100
|
|
|
|
while (++mark <= sp) { |
1423
|
20
|
50
|
|
|
|
if (*mark) |
1424
|
20
|
100
|
|
|
|
*a++ = SvPV_nolen_const(*mark); |
1425
|
|
|
|
|
|
else |
1426
|
10
|
|
|
|
|
*a++ = ""; |
1427
|
|
|
|
|
|
} |
1428
|
10
|
|
|
|
|
*a = NULL; |
1429
|
10
|
50
|
|
|
|
if (really) |
1430
|
0
|
0
|
|
|
|
tmps = SvPV_nolen_const(really); |
1431
|
10
|
50
|
|
|
|
if ((!really && *PL_Argv[0] != '/') || |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
1432
|
0
|
0
|
|
|
|
(really && *tmps != '/')) /* will execvp use PATH? */ |
1433
|
10
|
50
|
|
|
|
TAINT_ENV(); /* testing IFS here is overkill, probably */ |
1434
|
10
|
|
|
|
|
PERL_FPU_PRE_EXEC |
1435
|
10
|
50
|
|
|
|
if (really && *tmps) |
|
|
0
|
|
|
|
|
1436
|
0
|
|
|
|
|
PerlProc_execvp(tmps,EXEC_ARGV_CAST(PL_Argv)); |
1437
|
|
|
|
|
|
else |
1438
|
10
|
|
|
|
|
PerlProc_execvp(PL_Argv[0],EXEC_ARGV_CAST(PL_Argv)); |
1439
|
10
|
|
|
|
|
PERL_FPU_POST_EXEC |
1440
|
10
|
50
|
|
|
|
S_exec_failed(aTHX_ (really ? tmps : PL_Argv[0]), fd, do_report); |
1441
|
|
|
|
|
|
} |
1442
|
10
|
|
|
|
|
do_execfree(); |
1443
|
|
|
|
|
|
#endif |
1444
|
10
|
|
|
|
|
return FALSE; |
1445
|
|
|
|
|
|
} |
1446
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
void |
1448
|
24114
|
|
|
|
|
Perl_do_execfree(pTHX) |
1449
|
|
|
|
|
|
{ |
1450
|
|
|
|
|
|
dVAR; |
1451
|
24114
|
|
|
|
|
Safefree(PL_Argv); |
1452
|
24114
|
|
|
|
|
PL_Argv = NULL; |
1453
|
24114
|
|
|
|
|
Safefree(PL_Cmd); |
1454
|
24114
|
|
|
|
|
PL_Cmd = NULL; |
1455
|
24114
|
|
|
|
|
} |
1456
|
|
|
|
|
|
|
1457
|
|
|
|
|
|
#ifdef PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION |
1458
|
|
|
|
|
|
|
1459
|
|
|
|
|
|
bool |
1460
|
0
|
|
|
|
|
Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) |
1461
|
|
|
|
|
|
{ |
1462
|
|
|
|
|
|
dVAR; |
1463
|
|
|
|
|
|
const char **a; |
1464
|
|
|
|
|
|
char *s; |
1465
|
|
|
|
|
|
char *buf; |
1466
|
|
|
|
|
|
char *cmd; |
1467
|
|
|
|
|
|
/* Make a copy so we can change it */ |
1468
|
0
|
|
|
|
|
const Size_t cmdlen = strlen(incmd) + 1; |
1469
|
|
|
|
|
|
|
1470
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_EXEC3; |
1471
|
|
|
|
|
|
|
1472
|
0
|
|
|
|
|
Newx(buf, cmdlen, char); |
1473
|
|
|
|
|
|
cmd = buf; |
1474
|
0
|
|
|
|
|
memcpy(cmd, incmd, cmdlen); |
1475
|
|
|
|
|
|
|
1476
|
0
|
0
|
|
|
|
while (*cmd && isSPACE(*cmd)) |
|
|
0
|
|
|
|
|
1477
|
0
|
|
|
|
|
cmd++; |
1478
|
|
|
|
|
|
|
1479
|
|
|
|
|
|
/* save an extra exec if possible */ |
1480
|
|
|
|
|
|
|
1481
|
|
|
|
|
|
#ifdef CSH |
1482
|
|
|
|
|
|
{ |
1483
|
|
|
|
|
|
char flags[PERL_FLAGS_MAX]; |
1484
|
|
|
|
|
|
if (strnEQ(cmd,PL_cshname,PL_cshlen) && |
1485
|
|
|
|
|
|
strnEQ(cmd+PL_cshlen," -c",3)) { |
1486
|
|
|
|
|
|
my_strlcpy(flags, "-c", PERL_FLAGS_MAX); |
1487
|
|
|
|
|
|
s = cmd+PL_cshlen+3; |
1488
|
|
|
|
|
|
if (*s == 'f') { |
1489
|
|
|
|
|
|
s++; |
1490
|
|
|
|
|
|
my_strlcat(flags, "f", PERL_FLAGS_MAX - 2); |
1491
|
|
|
|
|
|
} |
1492
|
|
|
|
|
|
if (*s == ' ') |
1493
|
|
|
|
|
|
s++; |
1494
|
|
|
|
|
|
if (*s++ == '\'') { |
1495
|
|
|
|
|
|
char * const ncmd = s; |
1496
|
|
|
|
|
|
|
1497
|
|
|
|
|
|
while (*s) |
1498
|
|
|
|
|
|
s++; |
1499
|
|
|
|
|
|
if (s[-1] == '\n') |
1500
|
|
|
|
|
|
*--s = '\0'; |
1501
|
|
|
|
|
|
if (s[-1] == '\'') { |
1502
|
|
|
|
|
|
*--s = '\0'; |
1503
|
|
|
|
|
|
PERL_FPU_PRE_EXEC |
1504
|
|
|
|
|
|
PerlProc_execl(PL_cshname, "csh", flags, ncmd, (char*)NULL); |
1505
|
|
|
|
|
|
PERL_FPU_POST_EXEC |
1506
|
|
|
|
|
|
*s = '\''; |
1507
|
|
|
|
|
|
S_exec_failed(aTHX_ PL_cshname, fd, do_report); |
1508
|
|
|
|
|
|
Safefree(buf); |
1509
|
|
|
|
|
|
return FALSE; |
1510
|
|
|
|
|
|
} |
1511
|
|
|
|
|
|
} |
1512
|
|
|
|
|
|
} |
1513
|
|
|
|
|
|
} |
1514
|
|
|
|
|
|
#endif /* CSH */ |
1515
|
|
|
|
|
|
|
1516
|
|
|
|
|
|
/* see if there are shell metacharacters in it */ |
1517
|
|
|
|
|
|
|
1518
|
0
|
0
|
|
|
|
if (*cmd == '.' && isSPACE(cmd[1])) |
|
|
0
|
|
|
|
|
1519
|
|
|
|
|
|
goto doshell; |
1520
|
|
|
|
|
|
|
1521
|
0
|
0
|
|
|
|
if (strnEQ(cmd,"exec",4) && isSPACE(cmd[4])) |
|
|
0
|
|
|
|
|
1522
|
|
|
|
|
|
goto doshell; |
1523
|
|
|
|
|
|
|
1524
|
|
|
|
|
|
s = cmd; |
1525
|
0
|
0
|
|
|
|
while (isWORDCHAR(*s)) |
1526
|
0
|
|
|
|
|
s++; /* catch VAR=val gizmo */ |
1527
|
0
|
0
|
|
|
|
if (*s == '=') |
1528
|
|
|
|
|
|
goto doshell; |
1529
|
|
|
|
|
|
|
1530
|
0
|
0
|
|
|
|
for (s = cmd; *s; s++) { |
1531
|
0
|
0
|
|
|
|
if (*s != ' ' && !isALPHA(*s) && |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
1532
|
0
|
|
|
|
|
strchr("$&*(){}[]'\";\\|?<>~`\n",*s)) { |
1533
|
0
|
0
|
|
|
|
if (*s == '\n' && !s[1]) { |
|
|
0
|
|
|
|
|
1534
|
0
|
|
|
|
|
*s = '\0'; |
1535
|
0
|
|
|
|
|
break; |
1536
|
|
|
|
|
|
} |
1537
|
|
|
|
|
|
/* handle the 2>&1 construct at the end */ |
1538
|
0
|
0
|
|
|
|
if (*s == '>' && s[1] == '&' && s[2] == '1' |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
1539
|
0
|
0
|
|
|
|
&& s > cmd + 1 && s[-1] == '2' && isSPACE(s[-2]) |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
1540
|
0
|
0
|
|
|
|
&& (!s[3] || isSPACE(s[3]))) |
|
|
0
|
|
|
|
|
1541
|
|
|
|
|
|
{ |
1542
|
0
|
|
|
|
|
const char *t = s + 3; |
1543
|
|
|
|
|
|
|
1544
|
0
|
0
|
|
|
|
while (*t && isSPACE(*t)) |
|
|
0
|
|
|
|
|
1545
|
0
|
|
|
|
|
++t; |
1546
|
0
|
0
|
|
|
|
if (!*t && (PerlLIO_dup2(1,2) != -1)) { |
|
|
0
|
|
|
|
|
1547
|
0
|
|
|
|
|
s[-2] = '\0'; |
1548
|
0
|
|
|
|
|
break; |
1549
|
|
|
|
|
|
} |
1550
|
|
|
|
|
|
} |
1551
|
|
|
|
|
|
doshell: |
1552
|
0
|
|
|
|
|
PERL_FPU_PRE_EXEC |
1553
|
0
|
|
|
|
|
PerlProc_execl(PL_sh_path, "sh", "-c", cmd, (char *)NULL); |
1554
|
0
|
|
|
|
|
PERL_FPU_POST_EXEC |
1555
|
0
|
|
|
|
|
S_exec_failed(aTHX_ PL_sh_path, fd, do_report); |
1556
|
0
|
|
|
|
|
Safefree(buf); |
1557
|
0
|
|
|
|
|
return FALSE; |
1558
|
|
|
|
|
|
} |
1559
|
|
|
|
|
|
} |
1560
|
|
|
|
|
|
|
1561
|
0
|
0
|
|
|
|
Newx(PL_Argv, (s - cmd) / 2 + 2, const char*); |
1562
|
0
|
|
|
|
|
PL_Cmd = savepvn(cmd, s-cmd); |
1563
|
0
|
|
|
|
|
a = PL_Argv; |
1564
|
0
|
0
|
|
|
|
for (s = PL_Cmd; *s;) { |
1565
|
0
|
0
|
|
|
|
while (isSPACE(*s)) |
1566
|
0
|
|
|
|
|
s++; |
1567
|
0
|
0
|
|
|
|
if (*s) |
1568
|
0
|
|
|
|
|
*(a++) = s; |
1569
|
0
|
0
|
|
|
|
while (*s && !isSPACE(*s)) |
|
|
0
|
|
|
|
|
1570
|
0
|
|
|
|
|
s++; |
1571
|
0
|
0
|
|
|
|
if (*s) |
1572
|
0
|
|
|
|
|
*s++ = '\0'; |
1573
|
|
|
|
|
|
} |
1574
|
0
|
|
|
|
|
*a = NULL; |
1575
|
0
|
0
|
|
|
|
if (PL_Argv[0]) { |
1576
|
0
|
|
|
|
|
PERL_FPU_PRE_EXEC |
1577
|
0
|
|
|
|
|
PerlProc_execvp(PL_Argv[0],EXEC_ARGV_CAST(PL_Argv)); |
1578
|
0
|
|
|
|
|
PERL_FPU_POST_EXEC |
1579
|
0
|
0
|
|
|
|
if (errno == ENOEXEC) { /* for system V NIH syndrome */ |
1580
|
0
|
|
|
|
|
do_execfree(); |
1581
|
0
|
|
|
|
|
goto doshell; |
1582
|
|
|
|
|
|
} |
1583
|
0
|
|
|
|
|
S_exec_failed(aTHX_ PL_Argv[0], fd, do_report); |
1584
|
|
|
|
|
|
} |
1585
|
0
|
|
|
|
|
do_execfree(); |
1586
|
0
|
|
|
|
|
Safefree(buf); |
1587
|
0
|
|
|
|
|
return FALSE; |
1588
|
|
|
|
|
|
} |
1589
|
|
|
|
|
|
|
1590
|
|
|
|
|
|
#endif /* OS2 || WIN32 */ |
1591
|
|
|
|
|
|
|
1592
|
|
|
|
|
|
#ifdef VMS |
1593
|
|
|
|
|
|
#include /* for sys$delprc */ |
1594
|
|
|
|
|
|
#endif |
1595
|
|
|
|
|
|
|
1596
|
|
|
|
|
|
I32 |
1597
|
186792
|
|
|
|
|
Perl_apply(pTHX_ I32 type, SV **mark, SV **sp) |
1598
|
|
|
|
|
|
{ |
1599
|
|
|
|
|
|
dVAR; |
1600
|
|
|
|
|
|
I32 val; |
1601
|
|
|
|
|
|
I32 tot = 0; |
1602
|
186792
|
|
|
|
|
const char *const what = PL_op_name[type]; |
1603
|
|
|
|
|
|
const char *s; |
1604
|
|
|
|
|
|
STRLEN len; |
1605
|
|
|
|
|
|
SV ** const oldmark = mark; |
1606
|
|
|
|
|
|
bool killgp = FALSE; |
1607
|
|
|
|
|
|
|
1608
|
|
|
|
|
|
PERL_ARGS_ASSERT_APPLY; |
1609
|
|
|
|
|
|
|
1610
|
|
|
|
|
|
PERL_UNUSED_VAR(what); /* may not be used depending on compile options */ |
1611
|
|
|
|
|
|
|
1612
|
|
|
|
|
|
/* Doing this ahead of the switch statement preserves the old behaviour, |
1613
|
|
|
|
|
|
where attempting to use kill as a taint test test would fail on |
1614
|
|
|
|
|
|
platforms where kill was not defined. */ |
1615
|
|
|
|
|
|
#ifndef HAS_KILL |
1616
|
|
|
|
|
|
if (type == OP_KILL) |
1617
|
|
|
|
|
|
Perl_die(aTHX_ PL_no_func, what); |
1618
|
|
|
|
|
|
#endif |
1619
|
|
|
|
|
|
#ifndef HAS_CHOWN |
1620
|
|
|
|
|
|
if (type == OP_CHOWN) |
1621
|
|
|
|
|
|
Perl_die(aTHX_ PL_no_func, what); |
1622
|
|
|
|
|
|
#endif |
1623
|
|
|
|
|
|
|
1624
|
|
|
|
|
|
|
1625
|
|
|
|
|
|
#define APPLY_TAINT_PROPER() \ |
1626
|
|
|
|
|
|
STMT_START { \ |
1627
|
|
|
|
|
|
if (TAINT_get) { TAINT_PROPER(what); } \ |
1628
|
|
|
|
|
|
} STMT_END |
1629
|
|
|
|
|
|
|
1630
|
|
|
|
|
|
/* This is a first heuristic; it doesn't catch tainting magic. */ |
1631
|
186792
|
50
|
|
|
|
if (TAINTING_get) { |
1632
|
0
|
0
|
|
|
|
while (++mark <= sp) { |
1633
|
0
|
0
|
|
|
|
if (SvTAINTED(*mark)) { |
|
|
0
|
|
|
|
|
1634
|
0
|
|
|
|
|
TAINT; |
1635
|
0
|
|
|
|
|
break; |
1636
|
|
|
|
|
|
} |
1637
|
|
|
|
|
|
} |
1638
|
|
|
|
|
|
mark = oldmark; |
1639
|
|
|
|
|
|
} |
1640
|
186792
|
|
|
|
|
switch (type) { |
1641
|
|
|
|
|
|
case OP_CHMOD: |
1642
|
44422
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1643
|
44422
|
100
|
|
|
|
if (++mark <= sp) { |
1644
|
44284
|
100
|
|
|
|
val = SvIV(*mark); |
1645
|
44284
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1646
|
44284
|
|
|
|
|
tot = sp - mark; |
1647
|
112172
|
100
|
|
|
|
while (++mark <= sp) { |
1648
|
|
|
|
|
|
GV* gv; |
1649
|
45746
|
100
|
|
|
|
if ((gv = MAYBE_DEREF_GV(*mark))) { |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1650
|
2
|
50
|
|
|
|
if (GvIO(gv) && IoIFP(GvIOp(gv))) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1651
|
|
|
|
|
|
#ifdef HAS_FCHMOD |
1652
|
2
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1653
|
2
|
50
|
|
|
|
if (fchmod(PerlIO_fileno(IoIFP(GvIOn(gv))), val)) |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1654
|
0
|
|
|
|
|
tot--; |
1655
|
|
|
|
|
|
#else |
1656
|
|
|
|
|
|
Perl_die(aTHX_ PL_no_func, "fchmod"); |
1657
|
|
|
|
|
|
#endif |
1658
|
|
|
|
|
|
} |
1659
|
|
|
|
|
|
else { |
1660
|
0
|
|
|
|
|
tot--; |
1661
|
|
|
|
|
|
} |
1662
|
|
|
|
|
|
} |
1663
|
|
|
|
|
|
else { |
1664
|
45744
|
100
|
|
|
|
const char *name = SvPV_nomg_const_nolen(*mark); |
1665
|
45744
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1666
|
91478
|
|
|
|
|
if (!IS_SAFE_PATHNAME(*mark, "chmod") || |
1667
|
45734
|
|
|
|
|
PerlLIO_chmod(name, val)) { |
1668
|
36854
|
|
|
|
|
tot--; |
1669
|
|
|
|
|
|
} |
1670
|
|
|
|
|
|
} |
1671
|
|
|
|
|
|
} |
1672
|
|
|
|
|
|
} |
1673
|
|
|
|
|
|
break; |
1674
|
|
|
|
|
|
#ifdef HAS_CHOWN |
1675
|
|
|
|
|
|
case OP_CHOWN: |
1676
|
164
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1677
|
164
|
100
|
|
|
|
if (sp - mark > 2) { |
1678
|
|
|
|
|
|
I32 val2; |
1679
|
20
|
100
|
|
|
|
val = SvIVx(*++mark); |
1680
|
20
|
50
|
|
|
|
val2 = SvIVx(*++mark); |
1681
|
20
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1682
|
20
|
|
|
|
|
tot = sp - mark; |
1683
|
54
|
100
|
|
|
|
while (++mark <= sp) { |
1684
|
|
|
|
|
|
GV* gv; |
1685
|
24
|
100
|
|
|
|
if ((gv = MAYBE_DEREF_GV(*mark))) { |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1686
|
2
|
50
|
|
|
|
if (GvIO(gv) && IoIFP(GvIOp(gv))) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1687
|
|
|
|
|
|
#ifdef HAS_FCHOWN |
1688
|
2
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1689
|
2
|
50
|
|
|
|
if (fchown(PerlIO_fileno(IoIFP(GvIOn(gv))), val, val2)) |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1690
|
0
|
|
|
|
|
tot--; |
1691
|
|
|
|
|
|
#else |
1692
|
|
|
|
|
|
Perl_die(aTHX_ PL_no_func, "fchown"); |
1693
|
|
|
|
|
|
#endif |
1694
|
|
|
|
|
|
} |
1695
|
|
|
|
|
|
else { |
1696
|
0
|
|
|
|
|
tot--; |
1697
|
|
|
|
|
|
} |
1698
|
|
|
|
|
|
} |
1699
|
|
|
|
|
|
else { |
1700
|
22
|
100
|
|
|
|
const char *name = SvPV_nomg_const_nolen(*mark); |
1701
|
22
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1702
|
40
|
|
|
|
|
if (!IS_SAFE_PATHNAME(*mark, "chown") || |
1703
|
18
|
|
|
|
|
PerlLIO_chown(name, val, val2)) { |
1704
|
21
|
|
|
|
|
tot--; |
1705
|
|
|
|
|
|
} |
1706
|
|
|
|
|
|
} |
1707
|
|
|
|
|
|
} |
1708
|
|
|
|
|
|
} |
1709
|
|
|
|
|
|
break; |
1710
|
|
|
|
|
|
#endif |
1711
|
|
|
|
|
|
/* |
1712
|
|
|
|
|
|
XXX Should we make lchown() directly available from perl? |
1713
|
|
|
|
|
|
For now, we'll let Configure test for HAS_LCHOWN, but do |
1714
|
|
|
|
|
|
nothing in the core. |
1715
|
|
|
|
|
|
--AD 5/1998 |
1716
|
|
|
|
|
|
*/ |
1717
|
|
|
|
|
|
#ifdef HAS_KILL |
1718
|
|
|
|
|
|
case OP_KILL: |
1719
|
60348
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1720
|
60348
|
50
|
|
|
|
if (mark == sp) |
1721
|
|
|
|
|
|
break; |
1722
|
60348
|
100
|
|
|
|
s = SvPVx_const(*++mark, len); |
1723
|
60348
|
100
|
|
|
|
if (*s == '-' && isALPHA(s[1])) |
|
|
50
|
|
|
|
|
1724
|
|
|
|
|
|
{ |
1725
|
0
|
|
|
|
|
s++; |
1726
|
0
|
|
|
|
|
len--; |
1727
|
|
|
|
|
|
killgp = TRUE; |
1728
|
|
|
|
|
|
} |
1729
|
60348
|
100
|
|
|
|
if (isALPHA(*s)) { |
1730
|
92
|
100
|
|
|
|
if (*s == 'S' && s[1] == 'I' && s[2] == 'G') { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1731
|
12
|
|
|
|
|
s += 3; |
1732
|
12
|
|
|
|
|
len -= 3; |
1733
|
|
|
|
|
|
} |
1734
|
92
|
50
|
|
|
|
if ((val = whichsig_pvn(s, len)) < 0) |
1735
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Unrecognized signal name \"%"SVf"\"", SVfARG(*mark)); |
1736
|
|
|
|
|
|
} |
1737
|
|
|
|
|
|
else |
1738
|
|
|
|
|
|
{ |
1739
|
60256
|
100
|
|
|
|
val = SvIV(*mark); |
1740
|
60256
|
100
|
|
|
|
if (val < 0) |
1741
|
|
|
|
|
|
{ |
1742
|
|
|
|
|
|
killgp = TRUE; |
1743
|
18
|
|
|
|
|
val = -val; |
1744
|
|
|
|
|
|
} |
1745
|
|
|
|
|
|
} |
1746
|
60348
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1747
|
60348
|
|
|
|
|
tot = sp - mark; |
1748
|
|
|
|
|
|
#ifdef VMS |
1749
|
|
|
|
|
|
/* kill() doesn't do process groups (job trees?) under VMS */ |
1750
|
|
|
|
|
|
if (val == SIGKILL) { |
1751
|
|
|
|
|
|
/* Use native sys$delprc() to insure that target process is |
1752
|
|
|
|
|
|
* deleted; supervisor-mode images don't pay attention to |
1753
|
|
|
|
|
|
* CRTL's emulation of Unix-style signals and kill() |
1754
|
|
|
|
|
|
*/ |
1755
|
|
|
|
|
|
while (++mark <= sp) { |
1756
|
|
|
|
|
|
I32 proc; |
1757
|
|
|
|
|
|
unsigned long int __vmssts; |
1758
|
|
|
|
|
|
SvGETMAGIC(*mark); |
1759
|
|
|
|
|
|
if (!(SvIOK(*mark) || SvNOK(*mark) || looks_like_number(*mark))) |
1760
|
|
|
|
|
|
Perl_croak(aTHX_ "Can't kill a non-numeric process ID"); |
1761
|
|
|
|
|
|
proc = SvIV_nomg(*mark); |
1762
|
|
|
|
|
|
APPLY_TAINT_PROPER(); |
1763
|
|
|
|
|
|
if (!((__vmssts = sys$delprc(&proc,0)) & 1)) { |
1764
|
|
|
|
|
|
tot--; |
1765
|
|
|
|
|
|
switch (__vmssts) { |
1766
|
|
|
|
|
|
case SS$_NONEXPR: |
1767
|
|
|
|
|
|
case SS$_NOSUCHNODE: |
1768
|
|
|
|
|
|
SETERRNO(ESRCH,__vmssts); |
1769
|
|
|
|
|
|
break; |
1770
|
|
|
|
|
|
case SS$_NOPRIV: |
1771
|
|
|
|
|
|
SETERRNO(EPERM,__vmssts); |
1772
|
|
|
|
|
|
break; |
1773
|
|
|
|
|
|
default: |
1774
|
|
|
|
|
|
SETERRNO(EVMSERR,__vmssts); |
1775
|
|
|
|
|
|
} |
1776
|
|
|
|
|
|
} |
1777
|
|
|
|
|
|
} |
1778
|
|
|
|
|
|
PERL_ASYNC_CHECK(); |
1779
|
|
|
|
|
|
break; |
1780
|
|
|
|
|
|
} |
1781
|
|
|
|
|
|
#endif |
1782
|
180792
|
100
|
|
|
|
while (++mark <= sp) { |
|
|
100
|
|
|
|
|
1783
|
|
|
|
|
|
Pid_t proc; |
1784
|
30142
|
|
|
|
|
SvGETMAGIC(*mark); |
1785
|
60184
|
100
|
|
|
|
if (!(SvNIOK(*mark) || looks_like_number(*mark))) |
|
|
100
|
|
|
|
|
1786
|
6
|
|
|
|
|
Perl_croak(aTHX_ "Can't kill a non-numeric process ID"); |
1787
|
60178
|
100
|
|
|
|
proc = SvIV_nomg(*mark); |
1788
|
60178
|
100
|
|
|
|
if (killgp) |
1789
|
|
|
|
|
|
{ |
1790
|
18
|
|
|
|
|
proc = -proc; |
1791
|
|
|
|
|
|
} |
1792
|
60178
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1793
|
60178
|
100
|
|
|
|
if (PerlProc_kill(proc, val)) |
1794
|
60085
|
|
|
|
|
tot--; |
1795
|
|
|
|
|
|
} |
1796
|
60342
|
100
|
|
|
|
PERL_ASYNC_CHECK(); |
1797
|
|
|
|
|
|
break; |
1798
|
|
|
|
|
|
#endif |
1799
|
|
|
|
|
|
case OP_UNLINK: |
1800
|
78678
|
100
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
50
|
|
|
|
|
1801
|
78678
|
|
|
|
|
tot = sp - mark; |
1802
|
198017
|
100
|
|
|
|
while (++mark <= sp) { |
1803
|
80000
|
100
|
|
|
|
s = SvPV_nolen_const(*mark); |
1804
|
80000
|
100
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
50
|
|
|
|
|
1805
|
80000
|
100
|
|
|
|
if (!IS_SAFE_PATHNAME(*mark, "unlink")) { |
1806
|
14
|
|
|
|
|
tot--; |
1807
|
|
|
|
|
|
} |
1808
|
79986
|
50
|
|
|
|
else if (PerlProc_geteuid() || PL_unsafe) { |
|
|
0
|
|
|
|
|
1809
|
79986
|
100
|
|
|
|
if (UNLINK(s)) |
1810
|
55752
|
|
|
|
|
tot--; |
1811
|
|
|
|
|
|
} |
1812
|
|
|
|
|
|
else { /* don't let root wipe out directories without -U */ |
1813
|
0
|
0
|
|
|
|
if (PerlLIO_lstat(s,&PL_statbuf) < 0 || S_ISDIR(PL_statbuf.st_mode)) |
|
|
0
|
|
|
|
|
1814
|
0
|
|
|
|
|
tot--; |
1815
|
|
|
|
|
|
else { |
1816
|
0
|
0
|
|
|
|
if (UNLINK(s)) |
1817
|
40000
|
|
|
|
|
tot--; |
1818
|
|
|
|
|
|
} |
1819
|
|
|
|
|
|
} |
1820
|
|
|
|
|
|
} |
1821
|
|
|
|
|
|
break; |
1822
|
|
|
|
|
|
#if defined(HAS_UTIME) || defined(HAS_FUTIMES) |
1823
|
|
|
|
|
|
case OP_UTIME: |
1824
|
3180
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1825
|
3180
|
100
|
|
|
|
if (sp - mark > 2) { |
1826
|
|
|
|
|
|
#if defined(HAS_FUTIMES) |
1827
|
|
|
|
|
|
struct timeval utbuf[2]; |
1828
|
|
|
|
|
|
void *utbufp = utbuf; |
1829
|
|
|
|
|
|
#elif defined(I_UTIME) || defined(VMS) |
1830
|
|
|
|
|
|
struct utimbuf utbuf; |
1831
|
|
|
|
|
|
struct utimbuf *utbufp = &utbuf; |
1832
|
|
|
|
|
|
#else |
1833
|
|
|
|
|
|
struct { |
1834
|
|
|
|
|
|
Time_t actime; |
1835
|
|
|
|
|
|
Time_t modtime; |
1836
|
|
|
|
|
|
} utbuf; |
1837
|
|
|
|
|
|
void *utbufp = &utbuf; |
1838
|
|
|
|
|
|
#endif |
1839
|
|
|
|
|
|
|
1840
|
3172
|
|
|
|
|
SV* const accessed = *++mark; |
1841
|
3172
|
|
|
|
|
SV* const modified = *++mark; |
1842
|
|
|
|
|
|
|
1843
|
|
|
|
|
|
/* Be like C, and if both times are undefined, let the C |
1844
|
|
|
|
|
|
* library figure out what to do. This usually means |
1845
|
|
|
|
|
|
* "current time". */ |
1846
|
|
|
|
|
|
|
1847
|
3172
|
100
|
|
|
|
if ( accessed == &PL_sv_undef && modified == &PL_sv_undef ) |
|
|
50
|
|
|
|
|
1848
|
|
|
|
|
|
utbufp = NULL; |
1849
|
|
|
|
|
|
else { |
1850
|
|
|
|
|
|
Zero(&utbuf, sizeof utbuf, char); |
1851
|
|
|
|
|
|
#ifdef HAS_FUTIMES |
1852
|
3158
|
100
|
|
|
|
utbuf[0].tv_sec = (long)SvIV(accessed); /* time accessed */ |
1853
|
3158
|
|
|
|
|
utbuf[0].tv_usec = 0; |
1854
|
3158
|
50
|
|
|
|
utbuf[1].tv_sec = (long)SvIV(modified); /* time modified */ |
1855
|
3158
|
|
|
|
|
utbuf[1].tv_usec = 0; |
1856
|
|
|
|
|
|
#elif defined(BIG_TIME) |
1857
|
|
|
|
|
|
utbuf.actime = (Time_t)SvNV(accessed); /* time accessed */ |
1858
|
|
|
|
|
|
utbuf.modtime = (Time_t)SvNV(modified); /* time modified */ |
1859
|
|
|
|
|
|
#else |
1860
|
|
|
|
|
|
utbuf.actime = (Time_t)SvIV(accessed); /* time accessed */ |
1861
|
|
|
|
|
|
utbuf.modtime = (Time_t)SvIV(modified); /* time modified */ |
1862
|
|
|
|
|
|
#endif |
1863
|
|
|
|
|
|
} |
1864
|
3172
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1865
|
3172
|
|
|
|
|
tot = sp - mark; |
1866
|
7938
|
100
|
|
|
|
while (++mark <= sp) { |
1867
|
|
|
|
|
|
GV* gv; |
1868
|
3180
|
50
|
|
|
|
if ((gv = MAYBE_DEREF_GV(*mark))) { |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1869
|
2
|
50
|
|
|
|
if (GvIO(gv) && IoIFP(GvIOp(gv))) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1870
|
|
|
|
|
|
#ifdef HAS_FUTIMES |
1871
|
2
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1872
|
2
|
50
|
|
|
|
if (futimes(PerlIO_fileno(IoIFP(GvIOn(gv))), |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1873
|
|
|
|
|
|
(struct timeval *) utbufp)) |
1874
|
0
|
|
|
|
|
tot--; |
1875
|
|
|
|
|
|
#else |
1876
|
|
|
|
|
|
Perl_die(aTHX_ PL_no_func, "futimes"); |
1877
|
|
|
|
|
|
#endif |
1878
|
|
|
|
|
|
} |
1879
|
|
|
|
|
|
else { |
1880
|
0
|
|
|
|
|
tot--; |
1881
|
|
|
|
|
|
} |
1882
|
|
|
|
|
|
} |
1883
|
|
|
|
|
|
else { |
1884
|
3178
|
100
|
|
|
|
const char * const name = SvPV_nomg_const_nolen(*mark); |
1885
|
3178
|
50
|
|
|
|
APPLY_TAINT_PROPER(); |
|
|
0
|
|
|
|
|
1886
|
3178
|
100
|
|
|
|
if (!IS_SAFE_PATHNAME(*mark, "utime")) { |
1887
|
12
|
|
|
|
|
tot--; |
1888
|
|
|
|
|
|
} |
1889
|
|
|
|
|
|
else |
1890
|
|
|
|
|
|
#ifdef HAS_FUTIMES |
1891
|
3166
|
100
|
|
|
|
if (utimes(name, (struct timeval *)utbufp)) |
1892
|
|
|
|
|
|
#else |
1893
|
|
|
|
|
|
if (PerlLIO_utime(name, utbufp)) |
1894
|
|
|
|
|
|
#endif |
1895
|
1606
|
|
|
|
|
tot--; |
1896
|
|
|
|
|
|
} |
1897
|
|
|
|
|
|
|
1898
|
|
|
|
|
|
} |
1899
|
|
|
|
|
|
} |
1900
|
|
|
|
|
|
else |
1901
|
|
|
|
|
|
tot = 0; |
1902
|
|
|
|
|
|
break; |
1903
|
|
|
|
|
|
#endif |
1904
|
|
|
|
|
|
} |
1905
|
186784
|
|
|
|
|
return tot; |
1906
|
|
|
|
|
|
|
1907
|
|
|
|
|
|
#undef APPLY_TAINT_PROPER |
1908
|
|
|
|
|
|
} |
1909
|
|
|
|
|
|
|
1910
|
|
|
|
|
|
/* Do the permissions allow some operation? Assumes statcache already set. */ |
1911
|
|
|
|
|
|
#ifndef VMS /* VMS' cando is in vms.c */ |
1912
|
|
|
|
|
|
bool |
1913
|
37224
|
|
|
|
|
Perl_cando(pTHX_ Mode_t mode, bool effective, const Stat_t *statbufp) |
1914
|
|
|
|
|
|
/* effective is a flag, true for EUID, or for checking if the effective gid |
1915
|
|
|
|
|
|
* is in the list of groups returned from getgroups(). |
1916
|
|
|
|
|
|
*/ |
1917
|
|
|
|
|
|
{ |
1918
|
|
|
|
|
|
dVAR; |
1919
|
|
|
|
|
|
|
1920
|
|
|
|
|
|
PERL_ARGS_ASSERT_CANDO; |
1921
|
|
|
|
|
|
|
1922
|
|
|
|
|
|
#ifdef DOSISH |
1923
|
|
|
|
|
|
/* [Comments and code from Len Reed] |
1924
|
|
|
|
|
|
* MS-DOS "user" is similar to UNIX's "superuser," but can't write |
1925
|
|
|
|
|
|
* to write-protected files. The execute permission bit is set |
1926
|
|
|
|
|
|
* by the Microsoft C library stat() function for the following: |
1927
|
|
|
|
|
|
* .exe files |
1928
|
|
|
|
|
|
* .com files |
1929
|
|
|
|
|
|
* .bat files |
1930
|
|
|
|
|
|
* directories |
1931
|
|
|
|
|
|
* All files and directories are readable. |
1932
|
|
|
|
|
|
* Directories and special files, e.g. "CON", cannot be |
1933
|
|
|
|
|
|
* write-protected. |
1934
|
|
|
|
|
|
* [Comment by Tom Dinger -- a directory can have the write-protect |
1935
|
|
|
|
|
|
* bit set in the file system, but DOS permits changes to |
1936
|
|
|
|
|
|
* the directory anyway. In addition, all bets are off |
1937
|
|
|
|
|
|
* here for networked software, such as Novell and |
1938
|
|
|
|
|
|
* Sun's PC-NFS.] |
1939
|
|
|
|
|
|
*/ |
1940
|
|
|
|
|
|
|
1941
|
|
|
|
|
|
/* Atari stat() does pretty much the same thing. we set x_bit_set_in_stat |
1942
|
|
|
|
|
|
* too so it will actually look into the files for magic numbers |
1943
|
|
|
|
|
|
*/ |
1944
|
|
|
|
|
|
return (mode & statbufp->st_mode) ? TRUE : FALSE; |
1945
|
|
|
|
|
|
|
1946
|
|
|
|
|
|
#else /* ! DOSISH */ |
1947
|
|
|
|
|
|
# ifdef __CYGWIN__ |
1948
|
|
|
|
|
|
if (ingroup(544,effective)) { /* member of Administrators */ |
1949
|
|
|
|
|
|
# else |
1950
|
37224
|
100
|
|
|
|
if ((effective ? PerlProc_geteuid() : PerlProc_getuid()) == 0) { /* root is special */ |
|
|
50
|
|
|
|
|
1951
|
|
|
|
|
|
# endif |
1952
|
0
|
0
|
|
|
|
if (mode == S_IXUSR) { |
1953
|
0
|
0
|
|
|
|
if (statbufp->st_mode & 0111 || S_ISDIR(statbufp->st_mode)) |
|
|
0
|
|
|
|
|
1954
|
|
|
|
|
|
return TRUE; |
1955
|
|
|
|
|
|
} |
1956
|
|
|
|
|
|
else |
1957
|
|
|
|
|
|
return TRUE; /* root reads and writes anything */ |
1958
|
0
|
|
|
|
|
return FALSE; |
1959
|
|
|
|
|
|
} |
1960
|
37224
|
100
|
|
|
|
if (statbufp->st_uid == (effective ? PerlProc_geteuid() : PerlProc_getuid()) ) { |
|
|
100
|
|
|
|
|
1961
|
26764
|
100
|
|
|
|
if (statbufp->st_mode & mode) |
1962
|
|
|
|
|
|
return TRUE; /* ok as "user" */ |
1963
|
|
|
|
|
|
} |
1964
|
10460
|
50
|
|
|
|
else if (ingroup(statbufp->st_gid,effective)) { |
1965
|
0
|
0
|
|
|
|
if (statbufp->st_mode & mode >> 3) |
1966
|
|
|
|
|
|
return TRUE; /* ok as "group" */ |
1967
|
|
|
|
|
|
} |
1968
|
10460
|
50
|
|
|
|
else if (statbufp->st_mode & mode >> 6) |
1969
|
|
|
|
|
|
return TRUE; /* ok as "other" */ |
1970
|
25328
|
|
|
|
|
return FALSE; |
1971
|
|
|
|
|
|
#endif /* ! DOSISH */ |
1972
|
|
|
|
|
|
} |
1973
|
|
|
|
|
|
#endif /* ! VMS */ |
1974
|
|
|
|
|
|
|
1975
|
|
|
|
|
|
static bool |
1976
|
10460
|
|
|
|
|
S_ingroup(pTHX_ Gid_t testgid, bool effective) |
1977
|
|
|
|
|
|
{ |
1978
|
|
|
|
|
|
dVAR; |
1979
|
10460
|
50
|
|
|
|
if (testgid == (effective ? PerlProc_getegid() : PerlProc_getgid())) |
|
|
50
|
|
|
|
|
1980
|
|
|
|
|
|
return TRUE; |
1981
|
|
|
|
|
|
#ifdef HAS_GETGROUPS |
1982
|
|
|
|
|
|
{ |
1983
|
|
|
|
|
|
Groups_t *gary = NULL; |
1984
|
|
|
|
|
|
I32 anum; |
1985
|
|
|
|
|
|
bool rc = FALSE; |
1986
|
|
|
|
|
|
|
1987
|
|
|
|
|
|
anum = getgroups(0, gary); |
1988
|
10460
|
50
|
|
|
|
Newx(gary, anum, Groups_t); |
1989
|
|
|
|
|
|
anum = getgroups(anum, gary); |
1990
|
36430
|
100
|
|
|
|
while (--anum >= 0) |
1991
|
20920
|
50
|
|
|
|
if (gary[anum] == testgid) { |
1992
|
|
|
|
|
|
rc = TRUE; |
1993
|
|
|
|
|
|
break; |
1994
|
|
|
|
|
|
} |
1995
|
|
|
|
|
|
|
1996
|
10460
|
|
|
|
|
Safefree(gary); |
1997
|
10460
|
|
|
|
|
return rc; |
1998
|
|
|
|
|
|
} |
1999
|
|
|
|
|
|
#else |
2000
|
|
|
|
|
|
return FALSE; |
2001
|
|
|
|
|
|
#endif |
2002
|
|
|
|
|
|
} |
2003
|
|
|
|
|
|
|
2004
|
|
|
|
|
|
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) |
2005
|
|
|
|
|
|
|
2006
|
|
|
|
|
|
I32 |
2007
|
14
|
|
|
|
|
Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp) |
2008
|
|
|
|
|
|
{ |
2009
|
|
|
|
|
|
dVAR; |
2010
|
14
|
50
|
|
|
|
const key_t key = (key_t)SvNVx(*++mark); |
2011
|
14
|
100
|
|
|
|
SV *nsv = optype == OP_MSGGET ? NULL : *++mark; |
2012
|
14
|
50
|
|
|
|
const I32 flags = SvIVx(*++mark); |
2013
|
|
|
|
|
|
|
2014
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_IPCGET; |
2015
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2016
|
|
|
|
|
|
|
2017
|
14
|
|
|
|
|
SETERRNO(0,0); |
2018
|
14
|
|
|
|
|
switch (optype) |
2019
|
|
|
|
|
|
{ |
2020
|
|
|
|
|
|
#ifdef HAS_MSG |
2021
|
|
|
|
|
|
case OP_MSGGET: |
2022
|
4
|
|
|
|
|
return msgget(key, flags); |
2023
|
|
|
|
|
|
#endif |
2024
|
|
|
|
|
|
#ifdef HAS_SEM |
2025
|
|
|
|
|
|
case OP_SEMGET: |
2026
|
4
|
50
|
|
|
|
return semget(key, (int) SvIV(nsv), flags); |
2027
|
|
|
|
|
|
#endif |
2028
|
|
|
|
|
|
#ifdef HAS_SHM |
2029
|
|
|
|
|
|
case OP_SHMGET: |
2030
|
10
|
50
|
|
|
|
return shmget(key, (size_t) SvUV(nsv), flags); |
2031
|
|
|
|
|
|
#endif |
2032
|
|
|
|
|
|
#if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM) |
2033
|
|
|
|
|
|
default: |
2034
|
|
|
|
|
|
/* diag_listed_as: msg%s not implemented */ |
2035
|
|
|
|
|
|
Perl_croak(aTHX_ "%s not implemented", PL_op_desc[optype]); |
2036
|
|
|
|
|
|
#endif |
2037
|
|
|
|
|
|
} |
2038
|
|
|
|
|
|
return -1; /* should never happen */ |
2039
|
|
|
|
|
|
} |
2040
|
|
|
|
|
|
|
2041
|
|
|
|
|
|
I32 |
2042
|
50
|
|
|
|
|
Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp) |
2043
|
|
|
|
|
|
{ |
2044
|
|
|
|
|
|
dVAR; |
2045
|
|
|
|
|
|
char *a; |
2046
|
|
|
|
|
|
I32 ret = -1; |
2047
|
50
|
50
|
|
|
|
const I32 id = SvIVx(*++mark); |
2048
|
|
|
|
|
|
#ifdef Semctl |
2049
|
50
|
100
|
|
|
|
const I32 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0; |
|
|
50
|
|
|
|
|
2050
|
|
|
|
|
|
#endif |
2051
|
50
|
50
|
|
|
|
const I32 cmd = SvIVx(*++mark); |
2052
|
50
|
|
|
|
|
SV * const astr = *++mark; |
2053
|
|
|
|
|
|
STRLEN infosize = 0; |
2054
|
50
|
|
|
|
|
I32 getinfo = (cmd == IPC_STAT); |
2055
|
|
|
|
|
|
|
2056
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_IPCCTL; |
2057
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2058
|
|
|
|
|
|
|
2059
|
50
|
|
|
|
|
switch (optype) |
2060
|
|
|
|
|
|
{ |
2061
|
|
|
|
|
|
#ifdef HAS_MSG |
2062
|
|
|
|
|
|
case OP_MSGCTL: |
2063
|
10
|
100
|
|
|
|
if (cmd == IPC_STAT || cmd == IPC_SET) |
2064
|
|
|
|
|
|
infosize = sizeof(struct msqid_ds); |
2065
|
|
|
|
|
|
break; |
2066
|
|
|
|
|
|
#endif |
2067
|
|
|
|
|
|
#ifdef HAS_SHM |
2068
|
|
|
|
|
|
case OP_SHMCTL: |
2069
|
10
|
100
|
|
|
|
if (cmd == IPC_STAT || cmd == IPC_SET) |
2070
|
|
|
|
|
|
infosize = sizeof(struct shmid_ds); |
2071
|
|
|
|
|
|
break; |
2072
|
|
|
|
|
|
#endif |
2073
|
|
|
|
|
|
#ifdef HAS_SEM |
2074
|
|
|
|
|
|
case OP_SEMCTL: |
2075
|
|
|
|
|
|
#ifdef Semctl |
2076
|
30
|
100
|
|
|
|
if (cmd == IPC_STAT || cmd == IPC_SET) |
2077
|
|
|
|
|
|
infosize = sizeof(struct semid_ds); |
2078
|
26
|
100
|
|
|
|
else if (cmd == GETALL || cmd == SETALL) |
2079
|
|
|
|
|
|
{ |
2080
|
|
|
|
|
|
struct semid_ds semds; |
2081
|
|
|
|
|
|
union semun semun; |
2082
|
|
|
|
|
|
#ifdef EXTRA_F_IN_SEMUN_BUF |
2083
|
|
|
|
|
|
semun.buff = &semds; |
2084
|
|
|
|
|
|
#else |
2085
|
16
|
|
|
|
|
semun.buf = &semds; |
2086
|
|
|
|
|
|
#endif |
2087
|
16
|
|
|
|
|
getinfo = (cmd == GETALL); |
2088
|
16
|
50
|
|
|
|
if (Semctl(id, 0, IPC_STAT, semun) == -1) |
2089
|
|
|
|
|
|
return -1; |
2090
|
16
|
|
|
|
|
infosize = semds.sem_nsems * sizeof(short); |
2091
|
|
|
|
|
|
/* "short" is technically wrong but much more portable |
2092
|
|
|
|
|
|
than guessing about u_?short(_t)? */ |
2093
|
|
|
|
|
|
} |
2094
|
|
|
|
|
|
#else |
2095
|
|
|
|
|
|
/* diag_listed_as: sem%s not implemented */ |
2096
|
|
|
|
|
|
Perl_croak(aTHX_ "%s not implemented", PL_op_desc[optype]); |
2097
|
|
|
|
|
|
#endif |
2098
|
|
|
|
|
|
break; |
2099
|
|
|
|
|
|
#endif |
2100
|
|
|
|
|
|
#if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM) |
2101
|
|
|
|
|
|
default: |
2102
|
|
|
|
|
|
/* diag_listed_as: shm%s not implemented */ |
2103
|
|
|
|
|
|
Perl_croak(aTHX_ "%s not implemented", PL_op_desc[optype]); |
2104
|
|
|
|
|
|
#endif |
2105
|
|
|
|
|
|
} |
2106
|
|
|
|
|
|
|
2107
|
50
|
100
|
|
|
|
if (infosize) |
2108
|
|
|
|
|
|
{ |
2109
|
30
|
100
|
|
|
|
if (getinfo) |
2110
|
|
|
|
|
|
{ |
2111
|
22
|
100
|
|
|
|
SvPV_force_nolen(astr); |
2112
|
22
|
50
|
|
|
|
a = SvGROW(astr, infosize+1); |
|
|
100
|
|
|
|
|
2113
|
|
|
|
|
|
} |
2114
|
|
|
|
|
|
else |
2115
|
|
|
|
|
|
{ |
2116
|
|
|
|
|
|
STRLEN len; |
2117
|
8
|
50
|
|
|
|
a = SvPV(astr, len); |
2118
|
8
|
50
|
|
|
|
if (len != infosize) |
2119
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Bad arg length for %s, is %lu, should be %ld", |
2120
|
|
|
|
|
|
PL_op_desc[optype], |
2121
|
|
|
|
|
|
(unsigned long)len, |
2122
|
|
|
|
|
|
(long)infosize); |
2123
|
|
|
|
|
|
} |
2124
|
|
|
|
|
|
} |
2125
|
|
|
|
|
|
else |
2126
|
|
|
|
|
|
{ |
2127
|
20
|
50
|
|
|
|
const IV i = SvIV(astr); |
2128
|
20
|
|
|
|
|
a = INT2PTR(char *,i); /* ouch */ |
2129
|
|
|
|
|
|
} |
2130
|
50
|
|
|
|
|
SETERRNO(0,0); |
2131
|
50
|
|
|
|
|
switch (optype) |
2132
|
|
|
|
|
|
{ |
2133
|
|
|
|
|
|
#ifdef HAS_MSG |
2134
|
|
|
|
|
|
case OP_MSGCTL: |
2135
|
10
|
|
|
|
|
ret = msgctl(id, cmd, (struct msqid_ds *)a); |
2136
|
10
|
|
|
|
|
break; |
2137
|
|
|
|
|
|
#endif |
2138
|
|
|
|
|
|
#ifdef HAS_SEM |
2139
|
|
|
|
|
|
case OP_SEMCTL: { |
2140
|
|
|
|
|
|
#ifdef Semctl |
2141
|
|
|
|
|
|
union semun unsemds; |
2142
|
|
|
|
|
|
|
2143
|
|
|
|
|
|
#ifdef EXTRA_F_IN_SEMUN_BUF |
2144
|
|
|
|
|
|
unsemds.buff = (struct semid_ds *)a; |
2145
|
|
|
|
|
|
#else |
2146
|
30
|
|
|
|
|
unsemds.buf = (struct semid_ds *)a; |
2147
|
|
|
|
|
|
#endif |
2148
|
30
|
|
|
|
|
ret = Semctl(id, n, cmd, unsemds); |
2149
|
|
|
|
|
|
#else |
2150
|
|
|
|
|
|
/* diag_listed_as: sem%s not implemented */ |
2151
|
|
|
|
|
|
Perl_croak(aTHX_ "%s not implemented", PL_op_desc[optype]); |
2152
|
|
|
|
|
|
#endif |
2153
|
|
|
|
|
|
} |
2154
|
30
|
|
|
|
|
break; |
2155
|
|
|
|
|
|
#endif |
2156
|
|
|
|
|
|
#ifdef HAS_SHM |
2157
|
|
|
|
|
|
case OP_SHMCTL: |
2158
|
10
|
|
|
|
|
ret = shmctl(id, cmd, (struct shmid_ds *)a); |
2159
|
10
|
|
|
|
|
break; |
2160
|
|
|
|
|
|
#endif |
2161
|
|
|
|
|
|
} |
2162
|
50
|
100
|
|
|
|
if (getinfo && ret >= 0) { |
2163
|
22
|
|
|
|
|
SvCUR_set(astr, infosize); |
2164
|
22
|
|
|
|
|
*SvEND(astr) = '\0'; |
2165
|
36
|
50
|
|
|
|
SvSETMAGIC(astr); |
2166
|
|
|
|
|
|
} |
2167
|
|
|
|
|
|
return ret; |
2168
|
|
|
|
|
|
} |
2169
|
|
|
|
|
|
|
2170
|
|
|
|
|
|
I32 |
2171
|
4
|
|
|
|
|
Perl_do_msgsnd(pTHX_ SV **mark, SV **sp) |
2172
|
|
|
|
|
|
{ |
2173
|
|
|
|
|
|
dVAR; |
2174
|
|
|
|
|
|
#ifdef HAS_MSG |
2175
|
|
|
|
|
|
STRLEN len; |
2176
|
4
|
50
|
|
|
|
const I32 id = SvIVx(*++mark); |
2177
|
4
|
|
|
|
|
SV * const mstr = *++mark; |
2178
|
4
|
50
|
|
|
|
const I32 flags = SvIVx(*++mark); |
2179
|
4
|
50
|
|
|
|
const char * const mbuf = SvPV_const(mstr, len); |
2180
|
4
|
|
|
|
|
const I32 msize = len - sizeof(long); |
2181
|
|
|
|
|
|
|
2182
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_MSGSND; |
2183
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2184
|
|
|
|
|
|
|
2185
|
4
|
50
|
|
|
|
if (msize < 0) |
2186
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Arg too short for msgsnd"); |
2187
|
4
|
|
|
|
|
SETERRNO(0,0); |
2188
|
4
|
|
|
|
|
return msgsnd(id, (struct msgbuf *)mbuf, msize, flags); |
2189
|
|
|
|
|
|
#else |
2190
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2191
|
|
|
|
|
|
PERL_UNUSED_ARG(mark); |
2192
|
|
|
|
|
|
/* diag_listed_as: msg%s not implemented */ |
2193
|
|
|
|
|
|
Perl_croak(aTHX_ "msgsnd not implemented"); |
2194
|
|
|
|
|
|
return -1; |
2195
|
|
|
|
|
|
#endif |
2196
|
|
|
|
|
|
} |
2197
|
|
|
|
|
|
|
2198
|
|
|
|
|
|
I32 |
2199
|
4
|
|
|
|
|
Perl_do_msgrcv(pTHX_ SV **mark, SV **sp) |
2200
|
|
|
|
|
|
{ |
2201
|
|
|
|
|
|
#ifdef HAS_MSG |
2202
|
|
|
|
|
|
dVAR; |
2203
|
|
|
|
|
|
char *mbuf; |
2204
|
|
|
|
|
|
long mtype; |
2205
|
|
|
|
|
|
I32 msize, flags, ret; |
2206
|
4
|
50
|
|
|
|
const I32 id = SvIVx(*++mark); |
2207
|
4
|
|
|
|
|
SV * const mstr = *++mark; |
2208
|
|
|
|
|
|
|
2209
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_MSGRCV; |
2210
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2211
|
|
|
|
|
|
|
2212
|
|
|
|
|
|
/* suppress warning when reading into undef var --jhi */ |
2213
|
4
|
50
|
|
|
|
if (! SvOK(mstr)) |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
2214
|
0
|
|
|
|
|
sv_setpvs(mstr, ""); |
2215
|
4
|
50
|
|
|
|
msize = SvIVx(*++mark); |
2216
|
4
|
50
|
|
|
|
mtype = (long)SvIVx(*++mark); |
2217
|
4
|
50
|
|
|
|
flags = SvIVx(*++mark); |
2218
|
4
|
50
|
|
|
|
SvPV_force_nolen(mstr); |
2219
|
4
|
50
|
|
|
|
mbuf = SvGROW(mstr, sizeof(long)+msize+1); |
|
|
50
|
|
|
|
|
2220
|
|
|
|
|
|
|
2221
|
4
|
|
|
|
|
SETERRNO(0,0); |
2222
|
4
|
|
|
|
|
ret = msgrcv(id, (struct msgbuf *)mbuf, msize, mtype, flags); |
2223
|
4
|
50
|
|
|
|
if (ret >= 0) { |
2224
|
4
|
|
|
|
|
SvCUR_set(mstr, sizeof(long)+ret); |
2225
|
4
|
|
|
|
|
*SvEND(mstr) = '\0'; |
2226
|
|
|
|
|
|
#ifndef INCOMPLETE_TAINTS |
2227
|
|
|
|
|
|
/* who knows who has been playing with this message? */ |
2228
|
4
|
50
|
|
|
|
SvTAINTED_on(mstr); |
2229
|
|
|
|
|
|
#endif |
2230
|
|
|
|
|
|
} |
2231
|
4
|
|
|
|
|
return ret; |
2232
|
|
|
|
|
|
#else |
2233
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2234
|
|
|
|
|
|
PERL_UNUSED_ARG(mark); |
2235
|
|
|
|
|
|
/* diag_listed_as: msg%s not implemented */ |
2236
|
|
|
|
|
|
Perl_croak(aTHX_ "msgrcv not implemented"); |
2237
|
|
|
|
|
|
return -1; |
2238
|
|
|
|
|
|
#endif |
2239
|
|
|
|
|
|
} |
2240
|
|
|
|
|
|
|
2241
|
|
|
|
|
|
I32 |
2242
|
2
|
|
|
|
|
Perl_do_semop(pTHX_ SV **mark, SV **sp) |
2243
|
|
|
|
|
|
{ |
2244
|
|
|
|
|
|
#ifdef HAS_SEM |
2245
|
|
|
|
|
|
dVAR; |
2246
|
|
|
|
|
|
STRLEN opsize; |
2247
|
2
|
50
|
|
|
|
const I32 id = SvIVx(*++mark); |
2248
|
2
|
|
|
|
|
SV * const opstr = *++mark; |
2249
|
2
|
50
|
|
|
|
const char * const opbuf = SvPV_const(opstr, opsize); |
2250
|
|
|
|
|
|
|
2251
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_SEMOP; |
2252
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2253
|
|
|
|
|
|
|
2254
|
2
|
50
|
|
|
|
if (opsize < 3 * SHORTSIZE |
2255
|
2
|
50
|
|
|
|
|| (opsize % (3 * SHORTSIZE))) { |
2256
|
0
|
|
|
|
|
SETERRNO(EINVAL,LIB_INVARG); |
2257
|
0
|
|
|
|
|
return -1; |
2258
|
|
|
|
|
|
} |
2259
|
2
|
|
|
|
|
SETERRNO(0,0); |
2260
|
|
|
|
|
|
/* We can't assume that sizeof(struct sembuf) == 3 * sizeof(short). */ |
2261
|
|
|
|
|
|
{ |
2262
|
2
|
|
|
|
|
const int nsops = opsize / (3 * sizeof (short)); |
2263
|
|
|
|
|
|
int i = nsops; |
2264
|
|
|
|
|
|
short * const ops = (short *) opbuf; |
2265
|
|
|
|
|
|
short *o = ops; |
2266
|
|
|
|
|
|
struct sembuf *temps, *t; |
2267
|
|
|
|
|
|
I32 result; |
2268
|
|
|
|
|
|
|
2269
|
2
|
50
|
|
|
|
Newx (temps, nsops, struct sembuf); |
2270
|
|
|
|
|
|
t = temps; |
2271
|
5
|
100
|
|
|
|
while (i--) { |
2272
|
2
|
|
|
|
|
t->sem_num = *o++; |
2273
|
2
|
|
|
|
|
t->sem_op = *o++; |
2274
|
2
|
|
|
|
|
t->sem_flg = *o++; |
2275
|
2
|
|
|
|
|
t++; |
2276
|
|
|
|
|
|
} |
2277
|
2
|
|
|
|
|
result = semop(id, temps, nsops); |
2278
|
|
|
|
|
|
t = temps; |
2279
|
|
|
|
|
|
o = ops; |
2280
|
|
|
|
|
|
i = nsops; |
2281
|
5
|
100
|
|
|
|
while (i--) { |
2282
|
2
|
|
|
|
|
*o++ = t->sem_num; |
2283
|
2
|
|
|
|
|
*o++ = t->sem_op; |
2284
|
2
|
|
|
|
|
*o++ = t->sem_flg; |
2285
|
2
|
|
|
|
|
t++; |
2286
|
|
|
|
|
|
} |
2287
|
2
|
|
|
|
|
Safefree(temps); |
2288
|
2
|
|
|
|
|
return result; |
2289
|
|
|
|
|
|
} |
2290
|
|
|
|
|
|
#else |
2291
|
|
|
|
|
|
/* diag_listed_as: sem%s not implemented */ |
2292
|
|
|
|
|
|
Perl_croak(aTHX_ "semop not implemented"); |
2293
|
|
|
|
|
|
#endif |
2294
|
|
|
|
|
|
} |
2295
|
|
|
|
|
|
|
2296
|
|
|
|
|
|
I32 |
2297
|
30
|
|
|
|
|
Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) |
2298
|
|
|
|
|
|
{ |
2299
|
|
|
|
|
|
#ifdef HAS_SHM |
2300
|
|
|
|
|
|
dVAR; |
2301
|
|
|
|
|
|
char *shm; |
2302
|
|
|
|
|
|
struct shmid_ds shmds; |
2303
|
30
|
50
|
|
|
|
const I32 id = SvIVx(*++mark); |
2304
|
30
|
|
|
|
|
SV * const mstr = *++mark; |
2305
|
30
|
50
|
|
|
|
const I32 mpos = SvIVx(*++mark); |
2306
|
30
|
50
|
|
|
|
const I32 msize = SvIVx(*++mark); |
2307
|
|
|
|
|
|
|
2308
|
|
|
|
|
|
PERL_ARGS_ASSERT_DO_SHMIO; |
2309
|
|
|
|
|
|
PERL_UNUSED_ARG(sp); |
2310
|
|
|
|
|
|
|
2311
|
30
|
|
|
|
|
SETERRNO(0,0); |
2312
|
30
|
50
|
|
|
|
if (shmctl(id, IPC_STAT, &shmds) == -1) |
2313
|
|
|
|
|
|
return -1; |
2314
|
30
|
50
|
|
|
|
if (mpos < 0 || msize < 0 |
2315
|
30
|
50
|
|
|
|
|| (size_t)mpos + msize > (size_t)shmds.shm_segsz) { |
2316
|
0
|
|
|
|
|
SETERRNO(EFAULT,SS_ACCVIO); /* can't do as caller requested */ |
2317
|
0
|
|
|
|
|
return -1; |
2318
|
|
|
|
|
|
} |
2319
|
30
|
100
|
|
|
|
shm = (char *)shmat(id, NULL, (optype == OP_SHMREAD) ? SHM_RDONLY : 0); |
2320
|
30
|
50
|
|
|
|
if (shm == (char *)-1) /* I hate System V IPC, I really do */ |
2321
|
|
|
|
|
|
return -1; |
2322
|
45
|
100
|
|
|
|
if (optype == OP_SHMREAD) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
2323
|
|
|
|
|
|
char *mbuf; |
2324
|
|
|
|
|
|
/* suppress warning when reading into undef var (tchrist 3/Mar/00) */ |
2325
|
9
|
|
|
|
|
SvGETMAGIC(mstr); |
2326
|
11
|
|
|
|
|
SvUPGRADE(mstr, SVt_PV); |
2327
|
14
|
100
|
|
|
|
if (! SvOK(mstr)) |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
2328
|
4
|
|
|
|
|
sv_setpvs(mstr, ""); |
2329
|
14
|
|
|
|
|
SvPOK_only(mstr); |
2330
|
14
|
100
|
|
|
|
mbuf = SvGROW(mstr, (STRLEN)msize+1); |
|
|
100
|
|
|
|
|
2331
|
|
|
|
|
|
|
2332
|
14
|
|
|
|
|
Copy(shm + mpos, mbuf, msize, char); |
2333
|
14
|
|
|
|
|
SvCUR_set(mstr, msize); |
2334
|
14
|
|
|
|
|
*SvEND(mstr) = '\0'; |
2335
|
14
|
100
|
|
|
|
SvSETMAGIC(mstr); |
2336
|
|
|
|
|
|
#ifndef INCOMPLETE_TAINTS |
2337
|
|
|
|
|
|
/* who knows who has been playing with this shared memory? */ |
2338
|
14
|
50
|
|
|
|
SvTAINTED_on(mstr); |
2339
|
|
|
|
|
|
#endif |
2340
|
|
|
|
|
|
} |
2341
|
|
|
|
|
|
else { |
2342
|
|
|
|
|
|
STRLEN len; |
2343
|
|
|
|
|
|
|
2344
|
16
|
100
|
|
|
|
const char *mbuf = SvPV_const(mstr, len); |
2345
|
16
|
50
|
|
|
|
const I32 n = ((I32)len > msize) ? msize : (I32)len; |
2346
|
16
|
|
|
|
|
Copy(mbuf, shm + mpos, n, char); |
2347
|
16
|
50
|
|
|
|
if (n < msize) |
2348
|
0
|
|
|
|
|
memzero(shm + mpos + n, msize - n); |
2349
|
|
|
|
|
|
} |
2350
|
30
|
|
|
|
|
return shmdt(shm); |
2351
|
|
|
|
|
|
#else |
2352
|
|
|
|
|
|
/* diag_listed_as: shm%s not implemented */ |
2353
|
|
|
|
|
|
Perl_croak(aTHX_ "shm I/O not implemented"); |
2354
|
|
|
|
|
|
return -1; |
2355
|
|
|
|
|
|
#endif |
2356
|
|
|
|
|
|
} |
2357
|
|
|
|
|
|
|
2358
|
|
|
|
|
|
#endif /* SYSV IPC */ |
2359
|
|
|
|
|
|
|
2360
|
|
|
|
|
|
/* |
2361
|
|
|
|
|
|
=head1 IO Functions |
2362
|
|
|
|
|
|
|
2363
|
|
|
|
|
|
=for apidoc start_glob |
2364
|
|
|
|
|
|
|
2365
|
|
|
|
|
|
Function called by C to spawn a glob (or do the glob inside |
2366
|
|
|
|
|
|
perl on VMS). This code used to be inline, but now perl uses C |
2367
|
|
|
|
|
|
this glob starter is only used by miniperl during the build process. |
2368
|
|
|
|
|
|
Moving it away shrinks pp_hot.c; shrinking pp_hot.c helps speed perl up. |
2369
|
|
|
|
|
|
|
2370
|
|
|
|
|
|
=cut |
2371
|
|
|
|
|
|
*/ |
2372
|
|
|
|
|
|
|
2373
|
|
|
|
|
|
PerlIO * |
2374
|
438
|
|
|
|
|
Perl_start_glob (pTHX_ SV *tmpglob, IO *io) |
2375
|
|
|
|
|
|
{ |
2376
|
|
|
|
|
|
dVAR; |
2377
|
438
|
|
|
|
|
SV * const tmpcmd = newSV(0); |
2378
|
|
|
|
|
|
PerlIO *fp; |
2379
|
|
|
|
|
|
|
2380
|
|
|
|
|
|
PERL_ARGS_ASSERT_START_GLOB; |
2381
|
|
|
|
|
|
|
2382
|
438
|
50
|
|
|
|
if (!IS_SAFE_SYSCALL(tmpglob, "pattern", "glob")) |
2383
|
|
|
|
|
|
return NULL; |
2384
|
|
|
|
|
|
|
2385
|
438
|
|
|
|
|
ENTER; |
2386
|
438
|
|
|
|
|
SAVEFREESV(tmpcmd); |
2387
|
|
|
|
|
|
#ifdef VMS /* expand the wildcards right here, rather than opening a pipe, */ |
2388
|
|
|
|
|
|
/* since spawning off a process is a real performance hit */ |
2389
|
|
|
|
|
|
|
2390
|
|
|
|
|
|
PerlIO * |
2391
|
|
|
|
|
|
Perl_vms_start_glob |
2392
|
|
|
|
|
|
(pTHX_ SV *tmpglob, |
2393
|
|
|
|
|
|
IO *io); |
2394
|
|
|
|
|
|
|
2395
|
|
|
|
|
|
fp = Perl_vms_start_glob(aTHX_ tmpglob, io); |
2396
|
|
|
|
|
|
|
2397
|
|
|
|
|
|
#else /* !VMS */ |
2398
|
|
|
|
|
|
#ifdef DOSISH |
2399
|
|
|
|
|
|
#ifdef OS2 |
2400
|
|
|
|
|
|
sv_setpv(tmpcmd, "for a in "); |
2401
|
|
|
|
|
|
sv_catsv(tmpcmd, tmpglob); |
2402
|
|
|
|
|
|
sv_catpv(tmpcmd, "; do echo \"$a\\0\\c\"; done |"); |
2403
|
|
|
|
|
|
#else |
2404
|
|
|
|
|
|
#ifdef DJGPP |
2405
|
|
|
|
|
|
sv_setpv(tmpcmd, "/dev/dosglob/"); /* File System Extension */ |
2406
|
|
|
|
|
|
sv_catsv(tmpcmd, tmpglob); |
2407
|
|
|
|
|
|
#else |
2408
|
|
|
|
|
|
sv_setpv(tmpcmd, "perlglob "); |
2409
|
|
|
|
|
|
sv_catsv(tmpcmd, tmpglob); |
2410
|
|
|
|
|
|
sv_catpv(tmpcmd, " |"); |
2411
|
|
|
|
|
|
#endif /* !DJGPP */ |
2412
|
|
|
|
|
|
#endif /* !OS2 */ |
2413
|
|
|
|
|
|
#else /* !DOSISH */ |
2414
|
|
|
|
|
|
#if defined(CSH) |
2415
|
|
|
|
|
|
sv_setpvn(tmpcmd, PL_cshname, PL_cshlen); |
2416
|
|
|
|
|
|
sv_catpv(tmpcmd, " -cf 'set nonomatch; glob "); |
2417
|
|
|
|
|
|
sv_catsv(tmpcmd, tmpglob); |
2418
|
|
|
|
|
|
sv_catpv(tmpcmd, "' 2>/dev/null |"); |
2419
|
|
|
|
|
|
#else |
2420
|
438
|
|
|
|
|
sv_setpv(tmpcmd, "echo "); |
2421
|
438
|
|
|
|
|
sv_catsv(tmpcmd, tmpglob); |
2422
|
|
|
|
|
|
#if 'z' - 'a' == 25 |
2423
|
438
|
|
|
|
|
sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|"); |
2424
|
|
|
|
|
|
#else |
2425
|
|
|
|
|
|
sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|"); |
2426
|
|
|
|
|
|
#endif |
2427
|
|
|
|
|
|
#endif /* !CSH */ |
2428
|
|
|
|
|
|
#endif /* !DOSISH */ |
2429
|
|
|
|
|
|
{ |
2430
|
438
|
|
|
|
|
GV * const envgv = gv_fetchpvs("ENV", 0, SVt_PVHV); |
2431
|
438
|
|
|
|
|
SV ** const home = hv_fetchs(GvHV(envgv), "HOME", 0); |
2432
|
438
|
|
|
|
|
SV ** const path = hv_fetchs(GvHV(envgv), "PATH", 0); |
2433
|
438
|
50
|
|
|
|
if (home && *home) SvGETMAGIC(*home); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
2434
|
438
|
50
|
|
|
|
if (path && *path) SvGETMAGIC(*path); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
2435
|
438
|
|
|
|
|
save_hash(gv_fetchpvs("ENV", 0, SVt_PVHV)); |
2436
|
438
|
50
|
|
|
|
if (home && *home) SvSETMAGIC(*home); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
2437
|
438
|
50
|
|
|
|
if (path && *path) SvSETMAGIC(*path); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
2438
|
|
|
|
|
|
} |
2439
|
438
|
|
|
|
|
(void)do_open(PL_last_in_gv, (char*)SvPVX_const(tmpcmd), SvCUR(tmpcmd), |
2440
|
|
|
|
|
|
FALSE, O_RDONLY, 0, NULL); |
2441
|
438
|
|
|
|
|
fp = IoIFP(io); |
2442
|
|
|
|
|
|
#endif /* !VMS */ |
2443
|
438
|
|
|
|
|
LEAVE; |
2444
|
438
|
|
|
|
|
return fp; |
2445
|
|
|
|
|
|
} |
2446
|
|
|
|
|
|
|
2447
|
|
|
|
|
|
/* |
2448
|
|
|
|
|
|
* Local variables: |
2449
|
|
|
|
|
|
* c-indentation-style: bsd |
2450
|
|
|
|
|
|
* c-basic-offset: 4 |
2451
|
|
|
|
|
|
* indent-tabs-mode: nil |
2452
|
|
|
|
|
|
* End: |
2453
|
|
|
|
|
|
* |
2454
|
|
|
|
|
|
* ex: set ts=8 sts=4 sw=4 et: |
2455
|
|
|
|
|
|
*/ |