summaryrefslogtreecommitdiffstats
path: root/tests/seek-data-capable
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:11:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:11:47 +0000
commit758f820bcc0f68aeebac1717e537ca13a320b909 (patch)
tree48111ece75cf4f98316848b37a7e26356e00669e /tests/seek-data-capable
parentInitial commit. (diff)
downloadcoreutils-758f820bcc0f68aeebac1717e537ca13a320b909.tar.xz
coreutils-758f820bcc0f68aeebac1717e537ca13a320b909.zip
Adding upstream version 9.1.upstream/9.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/seek-data-capable')
-rw-r--r--tests/seek-data-capable33
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)