blob: a5ea1e678f115ae1e3793fccb027434597d31111 [file] [log] [blame]
Guido van Rossum228b8e81997-04-02 06:13:34 +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
9from test_support import verbose
10
11filename = '/tmp/delete-me'
12
13# the example from the library docs
14f = open(filename,'w')
Guido van Rossumf1e63541997-05-22 20:48:03 +000015rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK)
Guido van Rossum228b8e81997-04-02 06:13:34 +000016if verbose:
Guido van Rossumf1e63541997-05-22 20:48:03 +000017 print 'Status from fnctl with O_NONBLOCK: ', rv
Guido van Rossum228b8e81997-04-02 06:13:34 +000018
19lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
20if verbose:
Guido van Rossumf1e63541997-05-22 20:48:03 +000021 print 'struct.pack: ', `lockdata`
Guido van Rossum228b8e81997-04-02 06:13:34 +000022
23rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata)
24if verbose:
Guido van Rossumf1e63541997-05-22 20:48:03 +000025 print 'String from fcntl with F_SETLKW: ', `rv`
Guido van Rossum228b8e81997-04-02 06:13:34 +000026
27f.close()
28os.unlink(filename)