2 """Test program for the fcntl C module.
8 from test_support
import verbose
, TESTFN
12 if sys
.platform
in ('netbsd1', 'Darwin1.2', 'darwin1',
13 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
14 'bsdos2', 'bsdos3', 'bsdos4',
15 'openbsd', 'openbsd2'):
16 lockdata
= struct
.pack('lxxxxlxxxxlhh', 0, 0, 0, fcntl
.F_WRLCK
, 0)
17 elif sys
.platform
in ['aix3', 'aix4', 'hp-uxB', 'unixware7']:
18 lockdata
= struct
.pack('hhlllii', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0, 0)
20 lockdata
= struct
.pack('hhllhh', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0)
22 print 'struct.pack: ', `lockdata`
25 # the example from the library docs
26 f
= open(filename
, 'w')
27 rv
= fcntl
.fcntl(f
.fileno(), fcntl
.F_SETFL
, os
.O_NONBLOCK
)
29 print 'Status from fnctl with O_NONBLOCK: ', rv
31 rv
= fcntl
.fcntl(f
.fileno(), fcntl
.F_SETLKW
, lockdata
)
33 print 'String from fcntl with F_SETLKW: ', `rv`
39 # Again, but pass the file rather than numeric descriptor:
40 f
= open(filename
, 'w')
41 rv
= fcntl
.fcntl(f
, fcntl
.F_SETFL
, os
.O_NONBLOCK
)
43 rv
= fcntl
.fcntl(f
, fcntl
.F_SETLKW
, lockdata
)