Merge "Add SEEK_DATA and SEEK_HOLE constants."
diff --git a/libc/include/bits/seek_constants.h b/libc/include/bits/seek_constants.h
index 6b88606..6f3f22d 100644
--- a/libc/include/bits/seek_constants.h
+++ b/libc/include/bits/seek_constants.h
@@ -39,3 +39,23 @@
#define SEEK_CUR 1
/** Seek relative to the end of the file. */
#define SEEK_END 2
+
+#if defined(__USE_GNU)
+
+/**
+ * Seek to the first data (non-hole) location in the file
+ * greater than or equal to the given offset.
+ *
+ * See [lseek(2)](http://man7.org/linux/man-pages/man2/lseek.2.html).
+ */
+#define SEEK_DATA 3
+
+/**
+ * Seek to the first hole (non-data) location in the file
+ * greater than or equal to the given offset.
+ *
+ * See [lseek(2)](http://man7.org/linux/man-pages/man2/lseek.2.html).
+ */
+#define SEEK_HOLE 4
+
+#endif
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index c237d6d..01b4dba 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -19,6 +19,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <linux/fs.h>
#include <math.h>
#include <stdio.h>
#include <sys/types.h>
@@ -2599,3 +2600,13 @@
funlockfile(fp1);
fclose(fp1);
}
+
+TEST(STDIO_TEST, SEEK_macros) {
+ ASSERT_EQ(0, SEEK_SET);
+ ASSERT_EQ(1, SEEK_CUR);
+ ASSERT_EQ(2, SEEK_END);
+ ASSERT_EQ(3, SEEK_DATA);
+ ASSERT_EQ(4, SEEK_HOLE);
+ // So we'll notice if Linux grows another constant in <linux/fs.h>...
+ ASSERT_EQ(SEEK_MAX, SEEK_HOLE);
+}