Roger E. Masse | fb01d4b | 1996-12-17 17:41:09 +0000 | [diff] [blame] | 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 |
| 9 | |
| 10 | verbose = 0 |
| 11 | if __name__ == '__main__': |
| 12 | verbose = 1 |
| 13 | |
| 14 | filename = '/tmp/delete-me' |
| 15 | |
| 16 | # the example from the library docs |
| 17 | f = open(filename,'w') |
| 18 | rv = fcntl.fcntl(f.fileno(), FCNTL.O_NDELAY, 1) |
| 19 | if verbose: |
| 20 | print 'Status from fnctl with O_NDELAY: ', rv |
| 21 | |
| 22 | lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0) |
| 23 | if verbose: |
| 24 | print 'struct.pack: ', lockdata |
| 25 | |
| 26 | rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata) |
| 27 | if verbose: |
| 28 | print 'String from fcntl with F_SETLKW: ', rv |
| 29 | |
| 30 | f.close() |
| 31 | os.unlink(filename) |