---
 mingw-w64-crt/testcases/Makefile.am           |  1 +
 mingw-w64-crt/testcases/t_fseeki64_ftelli64.c | 41 +++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 mingw-w64-crt/testcases/t_fseeki64_ftelli64.c

diff --git a/mingw-w64-crt/testcases/Makefile.am 
b/mingw-w64-crt/testcases/Makefile.am
index 426557648788..c9fed4007dc0 100644
--- a/mingw-w64-crt/testcases/Makefile.am
+++ b/mingw-w64-crt/testcases/Makefile.am
@@ -22,6 +22,7 @@ testcase_progs = \
   t_findfirst \
   t_float  \
   t_fseeki64 \
+  t_fseeki64_ftelli64 \
   t_fstat \
   t_fstat_f64 \
   t_fstat_t64 \
diff --git a/mingw-w64-crt/testcases/t_fseeki64_ftelli64.c 
b/mingw-w64-crt/testcases/t_fseeki64_ftelli64.c
new file mode 100644
index 000000000000..b87e1a224fff
--- /dev/null
+++ b/mingw-w64-crt/testcases/t_fseeki64_ftelli64.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <assert.h>
+
+int main() {
+    FILE *file;
+
+    /* create temporary file which is automatically deleted when process 
terminates */
+    file = tmpfile();
+    assert(file);
+
+    /* absolute offset which fits into 32-bit signed type */
+    assert(_fseeki64(file, 0x10, SEEK_SET) == 0);
+    assert(_ftelli64(file) == 0x10);
+
+    /* TODO: _fseeki64(SEEK_CUR) and _ftelli64() do not work when current 
position does not fit into 32-bit signed type for pre-msvcrt40 */
+#if __MSVCRT_VERSION__ < 0x400
+    return 77;
+#endif
+
+    /* relative offset which fits into 32-bit signed type, but absolute does 
not */
+    assert(_fseeki64(file, 0x7FFFFFFF, SEEK_CUR) == 0);
+    assert(_ftelli64(file) == 0x7FFFFFFFLL + 0x10);
+
+    /* absolute offset which fits into 32-bit unsigned type but does not into 
32-bit signed type */
+    assert(_fseeki64(file, 0x90000000, SEEK_SET) == 0);
+    assert(_ftelli64(file) == 0x90000000);
+
+    /* relative offset which fits into 32-bit unsigned type but absolute does 
not */
+    assert(_fseeki64(file, 0xFFFFFFFF, SEEK_CUR) == 0);
+    assert(_ftelli64(file) == 0xFFFFFFFFLL + 0x90000000);
+
+    /* absolute offset which does not fit into 32-bit unsigned type */
+    assert(_fseeki64(file, 0x100000000, SEEK_SET) == 0);
+    assert(_ftelli64(file) == 0x100000000);
+
+    /* relative offset which does not fit into 32-bit unsigned type */
+    assert(_fseeki64(file, 0x100000000, SEEK_CUR) == 0);
+    assert(_ftelli64(file) == 0x200000000);
+
+    return 0;
+}
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to