blob: 10144c3031206f265ae52cef8a884770cbafe801 [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
Guido van Rossum91221c21997-12-02 20:30:29 +00008import os, sys
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
Guido van Rossum5ef8f0c1999-02-23 04:13:37 +000019if sys.platform in ('netbsd1',
20 'freebsd2', 'freebsd3',
21 'bsdos2', 'bsdos3', 'bsdos4'):
Guido van Rossum91221c21997-12-02 20:30:29 +000022 lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, FCNTL.F_WRLCK, 0)
23elif sys.platform in ['aix3', 'aix4']:
24 lockdata = struct.pack('hhlllii', FCNTL.F_WRLCK, 0, 0, 0, 0, 0, 0)
25else:
26 lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
Roger E. Massefb01d4b1996-12-17 17:41:09 +000027if verbose:
Guido van Rossum16dffdc1997-05-09 02:06:05 +000028 print 'struct.pack: ', `lockdata`
Roger E. Massefb01d4b1996-12-17 17:41:09 +000029
30rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata)
31if verbose:
Guido van Rossum16dffdc1997-05-09 02:06:05 +000032 print 'String from fcntl with F_SETLKW: ', `rv`
Roger E. Massefb01d4b1996-12-17 17:41:09 +000033
34f.close()
35os.unlink(filename)