1import sys, os, errno, platform
2
3# Pass an _empty_ file
4if len(sys.argv) != 2:
5    sys.exit(1)
6
7if 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
14else:
15    SEEK_DATA = os.SEEK_DATA
16
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)
22try:
23    fd = os.open(sys.argv[1], os.O_RDONLY)
24except:
25    sys.exit(1)
26
27try:
28    data = os.lseek(fd, 0, SEEK_DATA)
29except OSError as e:
30    if e.errno == errno.ENXIO:
31      sys.exit(0)
32
33sys.exit(1)
34