Updated for 2.1a3
[python/dscho.git] / Lib / test / test_fcntl.py
blobb6d4dfa72f0361bca57ea2a1982990e8b72555e1
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 FCNTL
8 import os, sys
9 from test_support import verbose, TESTFN
11 filename = TESTFN
13 # the example from the library docs
14 f = open(filename, 'w')
15 rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK)
16 if verbose:
17 print 'Status from fnctl with O_NONBLOCK: ', rv
19 if sys.platform in ('netbsd1', 'Darwin1.2',
20 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
21 'bsdos2', 'bsdos3', 'bsdos4',
22 'openbsd', 'openbsd2'):
23 lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, FCNTL.F_WRLCK, 0)
24 elif sys.platform in ['aix3', 'aix4', 'hp-uxB']:
25 lockdata = struct.pack('hhlllii', FCNTL.F_WRLCK, 0, 0, 0, 0, 0, 0)
26 else:
27 lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
28 if verbose:
29 print 'struct.pack: ', `lockdata`
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)