This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #38464] chdir() on closed handles
[perl5.git] / t / lib / warnings / pp_sys
CommitLineData
599cee73
PM
1 pp_sys.c AOK
2
767a6a26 3 untie attempted while %d inner references still exist [pp_untie]
599cee73
PM
4 sub TIESCALAR { bless [] } ; tie $a, 'main'; untie $a ;
5
c289d2f7
JH
6 fileno() on unopened filehandle abc [pp_fileno]
7 $a = "abc"; fileno($a)
8
9 binmode() on unopened filehandle abc [pp_binmode]
10 $a = "abc"; fileno($a)
11
12 printf() on unopened filehandle abc [pp_prtf]
13 $a = "abc"; printf $a "fred"
14
767a6a26 15 Filehandle %s opened only for input [pp_leavewrite]
599cee73
PM
16 format STDIN =
17 .
18 write STDIN;
19
9a7dcd9c 20 write() on closed filehandle %s [pp_leavewrite]
599cee73
PM
21 format STDIN =
22 .
23 close STDIN;
24 write STDIN ;
25
767a6a26 26 page overflow [pp_leavewrite]
599cee73 27
2dd78f96 28 printf() on unopened filehandle abc [pp_prtf]
599cee73
PM
29 $a = "abc"; printf $a "fred"
30
767a6a26 31 Filehandle %s opened only for input [pp_prtf]
599cee73
PM
32 $a = "abc";
33 printf $a "fred"
34
9a7dcd9c 35 printf() on closed filehandle %s [pp_prtf]
599cee73
PM
36 close STDIN ;
37 printf STDIN "fred"
38
69282e91 39 syswrite() on closed filehandle %s [pp_send]
599cee73
PM
40 close STDIN;
41 syswrite STDIN, "fred", 1;
42
69282e91 43 send() on closed socket %s [pp_send]
599cee73
PM
44 close STDIN;
45 send STDIN, "fred", 1
46
69282e91 47 bind() on closed socket %s [pp_bind]
599cee73
PM
48 close STDIN;
49 bind STDIN, "fred" ;
50
51
69282e91 52 connect() on closed socket %s [pp_connect]
599cee73
PM
53 close STDIN;
54 connect STDIN, "fred" ;
55
69282e91 56 listen() on closed socket %s [pp_listen]
599cee73
PM
57 close STDIN;
58 listen STDIN, 2;
59
69282e91 60 accept() on closed socket %s [pp_accept]
599cee73 61 close STDIN;
69282e91 62 accept "fred", STDIN ;
599cee73 63
69282e91 64 shutdown() on closed socket %s [pp_shutdown]
599cee73
PM
65 close STDIN;
66 shutdown STDIN, 0;
67
69282e91
GS
68 setsockopt() on closed socket %s [pp_ssockopt]
69 getsockopt() on closed socket %s [pp_ssockopt]
599cee73
PM
70 close STDIN;
71 setsockopt STDIN, 1,2,3;
72 getsockopt STDIN, 1,2;
73
69282e91
GS
74 getsockname() on closed socket %s [pp_getpeername]
75 getpeername() on closed socket %s [pp_getpeername]
599cee73
PM
76 close STDIN;
77 getsockname STDIN;
78 getpeername STDIN;
79
69282e91 80 flock() on closed socket %s [pp_flock]
bc37a18f 81 flock() on closed socket [pp_flock]
69282e91
GS
82 close STDIN;
83 flock STDIN, 8;
bc37a18f 84 flock $a, 8;
69282e91 85
767a6a26 86 warn(warn_nl, "stat"); [pp_stat]
599cee73 87
2dd78f96
JH
88 -T on closed filehandle %s
89 stat() on closed filehandle %s
90 close STDIN ; -T STDIN ; stat(STDIN) ;
599cee73 91
767a6a26 92 warn(warn_nl, "open"); [pp_fttext]
599cee73
PM
93 -T "abc\ndef" ;
94
767a6a26
PM
95 Filehandle %s opened only for output [pp_sysread]
96 my $file = "./xcv" ;
97 open(F, ">$file") ;
98 my $a = sysread(F, $a,10) ;
5d3e98de 99
90133b69
RGS
100 lstat on filehandle %s [pp_lstat]
101
102 getc() on unopened filehandle [pp_getc]
103
104 getc() on closed filehandle [pp_getc]
599cee73 105
4ef2275c
GA
106 Non-string passed as bitmask [pp_sselect]
107
599cee73 108__END__
767a6a26 109# pp_sys.c [pp_untie]
4438c4b7 110use warnings 'untie' ;
599cee73
PM
111sub TIESCALAR { bless [] } ;
112$b = tie $a, 'main';
113untie $a ;
4438c4b7 114no warnings 'untie' ;
0453d815
PM
115$c = tie $d, 'main';
116untie $d ;
599cee73
PM
117EXPECT
118untie attempted while 1 inner references still exist at - line 5.
119########
767a6a26 120# pp_sys.c [pp_leavewrite]
4438c4b7 121use warnings 'io' ;
599cee73
PM
122format STDIN =
123.
124write STDIN;
4438c4b7 125no warnings 'io' ;
0453d815 126write STDIN;
599cee73 127EXPECT
43693395 128Filehandle STDIN opened only for input at - line 5.
599cee73 129########
767a6a26 130# pp_sys.c [pp_leavewrite]
4438c4b7 131use warnings 'closed' ;
599cee73
PM
132format STDIN =
133.
134close STDIN;
135write STDIN;
69282e91
GS
136opendir STDIN, ".";
137write STDIN;
138closedir STDIN;
4438c4b7 139no warnings 'closed' ;
0453d815 140write STDIN;
69282e91
GS
141opendir STDIN, ".";
142write STDIN;
599cee73 143EXPECT
43693395
GS
144write() on closed filehandle STDIN at - line 6.
145write() on closed filehandle STDIN at - line 8.
146 (Are you trying to call write() on dirhandle STDIN?)
599cee73 147########
767a6a26 148# pp_sys.c [pp_leavewrite]
4438c4b7 149use warnings 'io' ;
599cee73
PM
150format STDOUT_TOP =
151abc
152.
153format STDOUT =
154def
155ghi
156.
157$= = 1 ;
158$- =1 ;
3eeba6fb 159open STDOUT, ">".($^O eq 'VMS'? 'NL:' : '/dev/null') ;
599cee73 160write ;
4438c4b7 161no warnings 'io' ;
0453d815 162write ;
599cee73
PM
163EXPECT
164page overflow at - line 13.
165########
767a6a26 166# pp_sys.c [pp_prtf]
4438c4b7 167use warnings 'unopened' ;
599cee73 168$a = "abc";
0453d815 169printf $a "fred";
4438c4b7 170no warnings 'unopened' ;
0453d815 171printf $a "fred";
599cee73 172EXPECT
2dd78f96 173printf() on unopened filehandle abc at - line 4.
599cee73 174########
767a6a26 175# pp_sys.c [pp_prtf]
4438c4b7 176use warnings 'closed' ;
599cee73 177close STDIN ;
0453d815 178printf STDIN "fred";
69282e91
GS
179opendir STDIN, ".";
180printf STDIN "fred";
181closedir STDIN;
4438c4b7 182no warnings 'closed' ;
0453d815 183printf STDIN "fred";
69282e91
GS
184opendir STDIN, ".";
185printf STDIN "fred";
599cee73 186EXPECT
43693395
GS
187printf() on closed filehandle STDIN at - line 4.
188printf() on closed filehandle STDIN at - line 6.
189 (Are you trying to call printf() on dirhandle STDIN?)
599cee73 190########
767a6a26 191# pp_sys.c [pp_prtf]
4438c4b7 192use warnings 'io' ;
0453d815 193printf STDIN "fred";
4438c4b7 194no warnings 'io' ;
0453d815 195printf STDIN "fred";
599cee73 196EXPECT
43693395 197Filehandle STDIN opened only for input at - line 3.
599cee73 198########
767a6a26 199# pp_sys.c [pp_send]
4438c4b7 200use warnings 'closed' ;
599cee73
PM
201close STDIN;
202syswrite STDIN, "fred", 1;
69282e91
GS
203opendir STDIN, ".";
204syswrite STDIN, "fred", 1;
205closedir STDIN;
4438c4b7 206no warnings 'closed' ;
0453d815 207syswrite STDIN, "fred", 1;
69282e91
GS
208opendir STDIN, ".";
209syswrite STDIN, "fred", 1;
599cee73 210EXPECT
43693395
GS
211syswrite() on closed filehandle STDIN at - line 4.
212syswrite() on closed filehandle STDIN at - line 6.
213 (Are you trying to call syswrite() on dirhandle STDIN?)
69282e91
GS
214########
215# pp_sys.c [pp_flock]
f0963acb
GS
216use Config;
217BEGIN {
9bdf8ebc
JH
218 if ( !$Config{d_flock} &&
219 !$Config{d_fcntl_can_lock} &&
220 !$Config{d_lockf} ) {
f0963acb
GS
221 print <<EOM ;
222SKIPPED
223# flock not present
224EOM
225 exit ;
226 }
227}
bc37a18f 228use warnings qw(unopened closed);
69282e91
GS
229close STDIN;
230flock STDIN, 8;
231opendir STDIN, ".";
232flock STDIN, 8;
bc37a18f
RG
233flock FOO, 8;
234flock $a, 8;
235no warnings qw(unopened closed);
69282e91
GS
236flock STDIN, 8;
237opendir STDIN, ".";
238flock STDIN, 8;
bc37a18f
RG
239flock FOO, 8;
240flock $a, 8;
69282e91 241EXPECT
43693395 242flock() on closed filehandle STDIN at - line 16.
c934501c 243flock() on closed filehandle STDIN at - line 18.
43693395 244 (Are you trying to call flock() on dirhandle STDIN?)
c934501c
JH
245flock() on unopened filehandle FOO at - line 19.
246flock() on unopened filehandle at - line 20.
599cee73 247########
767a6a26 248# pp_sys.c [pp_prtf pp_send pp_bind pp_connect pp_listen pp_accept pp_shutdown pp_ssockopt ppp_getpeername]
4438c4b7 249use warnings 'io' ;
599cee73
PM
250use Config;
251BEGIN {
252 if ( $^O ne 'VMS' and ! $Config{d_socket}) {
253 print <<EOM ;
254SKIPPED
255# send not present
256# bind not present
257# connect not present
258# accept not present
259# shutdown not present
260# setsockopt not present
261# getsockopt not present
262# getsockname not present
263# getpeername not present
264EOM
265 exit ;
266 }
267}
268close STDIN;
269send STDIN, "fred", 1;
270bind STDIN, "fred" ;
271connect STDIN, "fred" ;
272listen STDIN, 2;
69282e91
GS
273accept "fred", STDIN;
274shutdown STDIN, 0;
275setsockopt STDIN, 1,2,3;
276getsockopt STDIN, 1,2;
277getsockname STDIN;
278getpeername STDIN;
279opendir STDIN, ".";
280send STDIN, "fred", 1;
281bind STDIN, "fred" ;
282connect STDIN, "fred" ;
283listen STDIN, 2;
284accept "fred", STDIN;
599cee73
PM
285shutdown STDIN, 0;
286setsockopt STDIN, 1,2,3;
287getsockopt STDIN, 1,2;
288getsockname STDIN;
289getpeername STDIN;
69282e91 290closedir STDIN;
4438c4b7 291no warnings 'io' ;
0453d815
PM
292send STDIN, "fred", 1;
293bind STDIN, "fred" ;
294connect STDIN, "fred" ;
295listen STDIN, 2;
296accept STDIN, "fred" ;
297shutdown STDIN, 0;
298setsockopt STDIN, 1,2,3;
299getsockopt STDIN, 1,2;
300getsockname STDIN;
301getpeername STDIN;
69282e91
GS
302opendir STDIN, ".";
303send STDIN, "fred", 1;
304bind STDIN, "fred" ;
305connect STDIN, "fred" ;
306listen STDIN, 2;
307accept "fred", STDIN;
308shutdown STDIN, 0;
309setsockopt STDIN, 1,2,3;
310getsockopt STDIN, 1,2;
311getsockname STDIN;
312getpeername STDIN;
599cee73 313EXPECT
43693395
GS
314send() on closed socket STDIN at - line 22.
315bind() on closed socket STDIN at - line 23.
316connect() on closed socket STDIN at - line 24.
317listen() on closed socket STDIN at - line 25.
318accept() on closed socket STDIN at - line 26.
319shutdown() on closed socket STDIN at - line 27.
320setsockopt() on closed socket STDIN at - line 28.
321getsockopt() on closed socket STDIN at - line 29.
322getsockname() on closed socket STDIN at - line 30.
323getpeername() on closed socket STDIN at - line 31.
324send() on closed socket STDIN at - line 33.
325 (Are you trying to call send() on dirhandle STDIN?)
326bind() on closed socket STDIN at - line 34.
327 (Are you trying to call bind() on dirhandle STDIN?)
328connect() on closed socket STDIN at - line 35.
329 (Are you trying to call connect() on dirhandle STDIN?)
330listen() on closed socket STDIN at - line 36.
331 (Are you trying to call listen() on dirhandle STDIN?)
332accept() on closed socket STDIN at - line 37.
333 (Are you trying to call accept() on dirhandle STDIN?)
334shutdown() on closed socket STDIN at - line 38.
335 (Are you trying to call shutdown() on dirhandle STDIN?)
336setsockopt() on closed socket STDIN at - line 39.
337 (Are you trying to call setsockopt() on dirhandle STDIN?)
338getsockopt() on closed socket STDIN at - line 40.
339 (Are you trying to call getsockopt() on dirhandle STDIN?)
340getsockname() on closed socket STDIN at - line 41.
341 (Are you trying to call getsockname() on dirhandle STDIN?)
342getpeername() on closed socket STDIN at - line 42.
343 (Are you trying to call getpeername() on dirhandle STDIN?)
599cee73 344########
767a6a26 345# pp_sys.c [pp_stat]
4438c4b7 346use warnings 'newline' ;
599cee73 347stat "abc\ndef";
4438c4b7 348no warnings 'newline' ;
0453d815 349stat "abc\ndef";
599cee73
PM
350EXPECT
351Unsuccessful stat on filename containing newline at - line 3.
352########
767a6a26 353# pp_sys.c [pp_fttext]
2dd78f96 354use warnings qw(unopened closed) ;
599cee73
PM
355close STDIN ;
356-T STDIN ;
9ddeeac9 357stat(STDIN) ;
2dd78f96
JH
358-T HOCUS;
359stat(POCUS);
360no warnings qw(unopened closed) ;
0453d815 361-T STDIN ;
9ddeeac9 362stat(STDIN);
2dd78f96
JH
363-T HOCUS;
364stat(POCUS);
599cee73 365EXPECT
2dd78f96
JH
366-T on closed filehandle STDIN at - line 4.
367stat() on closed filehandle STDIN at - line 5.
368-T on unopened filehandle HOCUS at - line 6.
369stat() on unopened filehandle POCUS at - line 7.
599cee73 370########
767a6a26 371# pp_sys.c [pp_fttext]
4438c4b7 372use warnings 'newline' ;
599cee73 373-T "abc\ndef" ;
4438c4b7 374no warnings 'newline' ;
0453d815 375-T "abc\ndef" ;
599cee73
PM
376EXPECT
377Unsuccessful open on filename containing newline at - line 3.
767a6a26
PM
378########
379# pp_sys.c [pp_sysread]
380use warnings 'io' ;
6bbf1b34 381if ($^O eq 'dos') {
382 print <<EOM ;
383SKIPPED
384# skipped on dos
385EOM
386 exit ;
387}
767a6a26
PM
388my $file = "./xcv" ;
389open(F, ">$file") ;
390my $a = sysread(F, $a,10) ;
391no warnings 'io' ;
392my $a = sysread(F, $a,10) ;
393close F ;
b5fe5ca2
SR
394use warnings 'io' ;
395sysread(F, $a, 10);
396read(F, $a, 10);
397sysread(NONEXISTENT, $a, 10);
398read(NONEXISTENT, $a, 10);
767a6a26
PM
399unlink $file ;
400EXPECT
c6f2523f 401Filehandle F opened only for output at - line 12.
b5fe5ca2
SR
402sysread() on closed filehandle F at - line 17.
403read() on closed filehandle F at - line 18.
404sysread() on unopened filehandle NONEXISTENT at - line 19.
405read() on unopened filehandle NONEXISTENT at - line 20.
c289d2f7
JH
406########
407# pp_sys.c [pp_binmode]
408use warnings 'unopened' ;
409binmode(BLARG);
410$a = "BLERG";binmode($a);
411EXPECT
412binmode() on unopened filehandle BLARG at - line 3.
413binmode() on unopened filehandle at - line 4.
5d3e98de
RGS
414########
415# pp_sys.c [pp_lstat]
416use warnings 'io';
365c80fa
RGS
417open FH, "harness" or die "# $!";
418lstat FH;
5d3e98de
RGS
419open my $fh, $0 or die "# $!";
420lstat $fh;
421no warnings 'io';
365c80fa 422lstat FH;
5d3e98de 423lstat $fh;
365c80fa 424close FH;
5d3e98de
RGS
425close $fh;
426EXPECT
365c80fa
RGS
427lstat() on filehandle FH at - line 4.
428lstat() on filehandle $fh at - line 6.
90133b69
RGS
429########
430# pp_sys.c [pp_getc]
431use warnings qw(unopened closed) ;
432getc FOO;
433close STDIN;
434getc STDIN;
97e322ff
RGS
435# Create an empty file
436$file = 'getcwarn.tmp';
437open FH1, ">$file" or die "# $!"; close FH1;
438open FH2, $file or die "# $!";
439getc FH2; # Should not warn at EOF
440close FH2;
441getc FH2; # Warns, now
442unlink $file;
90133b69
RGS
443no warnings qw(unopened closed) ;
444getc FOO;
445getc STDIN;
97e322ff 446getc FH2;
90133b69
RGS
447EXPECT
448getc() on unopened filehandle FOO at - line 3.
449getc() on closed filehandle STDIN at - line 5.
97e322ff 450getc() on closed filehandle FH2 at - line 12.
4ef2275c
GA
451########
452# pp_sys.c [pp_sselect]
453use warnings 'misc';
454$x = 1;
455select $x, undef, undef, undef;
456no warnings 'misc';
457select $x, undef, undef, undef;
458EXPECT
459Non-string passed as bitmask at - line 4.
4dc171f0
PD
460########
461opendir FOO, '.'; closedir FOO;
462open BAR, '.'; close BAR;
463opendir $dh, '.'; closedir $dh;
464open $fh, '.'; close $fh;
465chdir FOO;
466chdir BAR;
467chdir $dh;
468chdir $fh;
469use warnings qw(unopened closed) ;
470chdir FOO;
471chdir BAR;
472chdir $dh;
473chdir $fh;
474EXPECT
475chdir() on unopened filehandle FOO at - line 10.
476chdir() on closed filehandle BAR at - line 11.
477chdir() on unopened filehandle $dh at - line 12.
478chdir() on closed filehandle $fh at - line 13.