home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Lib / test / test_fcntl.py < prev    next >
Text File  |  1997-12-02  |  905b  |  34 lines

  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, sys
  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')
  15. rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK)
  16. if verbose:
  17.     print 'Status from fnctl with O_NONBLOCK: ', rv
  18.     
  19. if sys.platform in ('netbsd1', 'freebsd2', 'freebsd3'):
  20.     lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, FCNTL.F_WRLCK, 0)
  21. elif sys.platform in ['aix3', 'aix4']:
  22.     lockdata = struct.pack('hhlllii', FCNTL.F_WRLCK, 0, 0, 0, 0, 0, 0)
  23. else:
  24.     lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
  25. if verbose:
  26.     print 'struct.pack: ', `lockdata`
  27.     
  28. rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata)
  29. if verbose:
  30.     print 'String from fcntl with F_SETLKW: ', `rv`
  31.  
  32. f.close()
  33. os.unlink(filename)
  34.