1*23f24377SWarner Loshecho T.close: test close built-in
2*23f24377SWarner Losh
3*23f24377SWarner Loshawk=${awk-../a.out}
4*23f24377SWarner Losh
5*23f24377SWarner Loshrm -f foo
6*23f24377SWarner Losh$awk '{ print >>"foo"; close("foo") }' /etc/passwd
7*23f24377SWarner Loshdiff /etc/passwd foo || echo 'BAD: T.close (1)'
8*23f24377SWarner Losh
9*23f24377SWarner Loshls -l >foo
10*23f24377SWarner Loshtail -1 foo >foo1
11*23f24377SWarner Losh$awk '{ print >"foo2"; close("foo2") }' foo
12*23f24377SWarner Loshdiff foo1 foo2 || echo 'BAD: T.close (2)'
13*23f24377SWarner Losh
14*23f24377SWarner Loshecho 0 >foo1
15*23f24377SWarner Losh$awk '	# non-accessible file
16*23f24377SWarner Losh  BEGIN { getline <"/etc/passwd"; print close("/etc/passwd"); }
17*23f24377SWarner Losh' >foo2
18*23f24377SWarner Loshdiff foo1 foo2 || echo 'BAD: T.close (3)'
19*23f24377SWarner Losh
20*23f24377SWarner Loshecho -1 >foo1
21*23f24377SWarner Losh$awk '	# file not opened
22*23f24377SWarner Losh  BEGIN { print close("glotch"); }
23*23f24377SWarner Losh' >foo2
24*23f24377SWarner Loshdiff foo1 foo2 || echo 'BAD: T.close (4)'
25*23f24377SWarner Losh
26*23f24377SWarner Loshecho 0 >foo1
27*23f24377SWarner Losh$awk '	# normal close
28*23f24377SWarner Losh  BEGIN { print "hello" > "foo"; print close("foo"); }
29*23f24377SWarner Losh' >foo2
30*23f24377SWarner Loshdiff foo1 foo2 || echo 'BAD: T.close (5)'
31*23f24377SWarner Losh
32*23f24377SWarner Loshecho 0 >foo1
33*23f24377SWarner Losh$awk '	# normal close
34*23f24377SWarner Losh  BEGIN { print "hello" | "cat >foo"; print close("cat >foo"); }
35*23f24377SWarner Losh' >foo2
36*23f24377SWarner Loshdiff foo1 foo2 || echo 'BAD: T.close (6)'
37