numfmt: prefer signed types
[coreutils.git] / tests / seek-data-capable
blobcc63722144cd3a8657690cfb9165677d3ad925bc
1 import sys, os, errno, platform
3 # Pass an _empty_ file
4 if len(sys.argv) != 2:
5     sys.exit(1)
7 if not hasattr(os, 'SEEK_DATA'):
8     # Not available on python 2, or on darwin python 3
9     # Also Darwin swaps SEEK_DATA/SEEK_HOLE definitions
10     if platform.system() == "Darwin":
11         SEEK_DATA = 4
12     else:
13         SEEK_DATA = 3 # Valid on Linux, FreeBSD, Solaris
14 else:
15     SEEK_DATA = os.SEEK_DATA
17 # Even if os supports SEEK_DATA or SEEK_HOLE,
18 # the file system may not, in which case it would report
19 # current and eof positions respectively.
20 # Therefore work with an empty file,
21 # ensuring SEEK_DATA returns ENXIO (no more data)
22 try:
23     fd = os.open(sys.argv[1], os.O_RDONLY)
24 except:
25     sys.exit(1)
27 try:
28     data = os.lseek(fd, 0, SEEK_DATA)
29 except OSError as e:
30     if e.errno == errno.ENXIO:
31       sys.exit(0)
33 sys.exit(1)