2 """Test program for the fcntl C module.
3 OS/2+EMX doesn't support the file locking operations.
9 from test
.test_support
import verbose
, TESTFN
15 except AttributeError:
20 if sys
.platform
.startswith('atheos'):
23 if sys
.platform
in ('netbsd1', 'Darwin1.2', 'darwin',
24 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
25 'bsdos2', 'bsdos3', 'bsdos4',
26 'openbsd', 'openbsd2', 'openbsd3'):
27 lockdata
= struct
.pack('lxxxxlxxxxlhh', 0, 0, 0, fcntl
.F_WRLCK
, 0)
28 elif sys
.platform
in ['aix3', 'aix4', 'hp-uxB', 'unixware7']:
29 lockdata
= struct
.pack('hhlllii', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0, 0)
30 elif sys
.platform
in ['os2emx']:
33 lockdata
= struct
.pack('hh'+start_len
+'hh', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0)
36 print 'struct.pack: ', `lockdata`
38 # the example from the library docs
39 f
= open(filename
, 'w')
40 rv
= fcntl
.fcntl(f
.fileno(), fcntl
.F_SETFL
, os
.O_NONBLOCK
)
42 print 'Status from fnctl with O_NONBLOCK: ', rv
44 if sys
.platform
not in ['os2emx']:
45 rv
= fcntl
.fcntl(f
.fileno(), fcntl
.F_SETLKW
, lockdata
)
47 print 'String from fcntl with F_SETLKW: ', `rv`
53 # Again, but pass the file rather than numeric descriptor:
54 f
= open(filename
, 'w')
55 rv
= fcntl
.fcntl(f
, fcntl
.F_SETFL
, os
.O_NONBLOCK
)
57 if sys
.platform
not in ['os2emx']:
58 rv
= fcntl
.fcntl(f
, fcntl
.F_SETLKW
, lockdata
)