test_fcntl.py revision fb01d4b1a4e48f38c6466461c1bd80af557e7c85
1#! /usr/bin/env python
2"""Test program for the fcntl C module.
3   Roger E. Masse
4"""
5import struct
6import fcntl
7import FCNTL
8import os
9
10verbose = 0
11if __name__ == '__main__':
12    verbose = 1
13
14filename = '/tmp/delete-me'
15
16# the example from the library docs
17f = open(filename,'w')
18rv = fcntl.fcntl(f.fileno(), FCNTL.O_NDELAY, 1)
19if verbose:
20    print 'Status from fnctl with O_NDELAY: ', rv
21
22lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
23if verbose:
24    print 'struct.pack: ', lockdata
25
26rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata)
27if verbose:
28    print 'String from fcntl with F_SETLKW: ', rv
29
30f.close()
31os.unlink(filename)
32