diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 16:58:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 16:58:41 +0000 |
commit | e1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe (patch) | |
tree | f5cc731bedcac0fb7fe14d952e4581e749f8bb87 /tests/seek-data-capable | |
parent | Initial commit. (diff) | |
download | coreutils-e1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe.tar.xz coreutils-e1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe.zip |
Adding upstream version 9.4.upstream/9.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/seek-data-capable')
-rw-r--r-- | tests/seek-data-capable | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/seek-data-capable b/tests/seek-data-capable new file mode 100644 index 0000000..cc63722 --- /dev/null +++ b/tests/seek-data-capable @@ -0,0 +1,33 @@ +import sys, os, errno, platform + +# Pass an _empty_ file +if len(sys.argv) != 2: + sys.exit(1) + +if not hasattr(os, 'SEEK_DATA'): + # Not available on python 2, or on darwin python 3 + # Also Darwin swaps SEEK_DATA/SEEK_HOLE definitions + if platform.system() == "Darwin": + SEEK_DATA = 4 + else: + SEEK_DATA = 3 # Valid on Linux, FreeBSD, Solaris +else: + SEEK_DATA = os.SEEK_DATA + +# Even if os supports SEEK_DATA or SEEK_HOLE, +# the file system may not, in which case it would report +# current and eof positions respectively. +# Therefore work with an empty file, +# ensuring SEEK_DATA returns ENXIO (no more data) +try: + fd = os.open(sys.argv[1], os.O_RDONLY) +except: + sys.exit(1) + +try: + data = os.lseek(fd, 0, SEEK_DATA) +except OSError as e: + if e.errno == errno.ENXIO: + sys.exit(0) + +sys.exit(1) |