py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Lib / test / test_fcntl.py
bloba64a5e1b6169dbeeac46d6c5d7e5067bb8b56a6a
1 #! /usr/bin/env python
2 """Test program for the fcntl C module.
3 Roger E. Masse
4 """
5 import struct
6 import fcntl
7 import os, sys
8 from test_support import verbose, TESTFN
10 filename = 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)
19 else:
20 lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0)
21 if verbose:
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)
28 if verbose:
29 print 'Status from fnctl with O_NONBLOCK: ', rv
31 rv = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW, lockdata)
32 if verbose:
33 print 'String from fcntl with F_SETLKW: ', `rv`
35 f.close()
36 os.unlink(filename)
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)
45 f.close()
46 os.unlink(filename)