blob: a5ea1e678f115ae1e3793fccb027434597d31111 [file] [log] [blame]
Roger E. Massefb01d4b1996-12-17 17:41:09 +00001#! /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
Roger E. Massefab8ab81996-12-20 22:36:52 +00009from test_support import verbose
Roger E. Massefb01d4b1996-12-17 17:41:09 +000010
11filename = '/tmp/delete-me'
12
13# the example from the library docs
14f = open(filename,'w')
Guido van Rossum0e351f31997-05-12 22:15:52 +000015rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK)
Roger E. Massefb01d4b1996-12-17 17:41:09 +000016if verbose:
Guido van Rossum0e351f31997-05-12 22:15:52 +000017 print 'Status from fnctl with O_NONBLOCK: ', rv
Roger E. Massefb01d4b1996-12-17 17:41:09 +000018
19lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
20if verbose:
Guido van Rossum16dffdc1997-05-09 02:06:05 +000021 print 'struct.pack: ', `lockdata`
Roger E. Massefb01d4b1996-12-17 17:41:09 +000022
23rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata)
24if verbose:
Guido van Rossum16dffdc1997-05-09 02:06:05 +000025 print 'String from fcntl with F_SETLKW: ', `rv`
Roger E. Massefb01d4b1996-12-17 17:41:09 +000026
27f.close()
28os.unlink(filename)