Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +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 | from test_support import verbose |
| 10 | |
| 11 | filename = '/tmp/delete-me' |
| 12 | |
| 13 | # the example from the library docs |
| 14 | f = open(filename,'w') |
Guido van Rossum | f1e6354 | 1997-05-22 20:48:03 +0000 | [diff] [blame] | 15 | rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK) |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 16 | if verbose: |
Guido van Rossum | f1e6354 | 1997-05-22 20:48:03 +0000 | [diff] [blame] | 17 | print 'Status from fnctl with O_NONBLOCK: ', rv |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 18 | |
| 19 | lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0) |
| 20 | if verbose: |
Guido van Rossum | f1e6354 | 1997-05-22 20:48:03 +0000 | [diff] [blame] | 21 | print 'struct.pack: ', `lockdata` |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 22 | |
| 23 | rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata) |
| 24 | if verbose: |
Guido van Rossum | f1e6354 | 1997-05-22 20:48:03 +0000 | [diff] [blame] | 25 | print 'String from fcntl with F_SETLKW: ', `rv` |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 26 | |
| 27 | f.close() |
| 28 | os.unlink(filename) |