[vlc-devel] [PATCH] core: fix block_test on Win32
Steve Lhomme
robux4 at videolabs.io
Sat Jun 4 12:54:04 CEST 2016
fopen("wb+e") doesn't share the file we write in for reading
ReadFile() doesn't work on shared fileno
---
src/misc/block.c | 17 +++--------------
src/test/block_test.c | 11 ++++++++++-
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/src/misc/block.c b/src/misc/block.c
index f7ee8d8..0d51bca 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -378,23 +378,12 @@ block_t *block_shm_Alloc (void *addr, size_t length)
#ifdef _WIN32
-# include <io.h>
-
-static
ssize_t pread (int fd, void *buf, size_t count, off_t offset)
{
- HANDLE handle = (HANDLE)(intptr_t)_get_osfhandle (fd);
- if (handle == INVALID_HANDLE_VALUE)
+ if ( lseek (fd, offset, SEEK_SET) != offset ) {
return -1;
-
- OVERLAPPED olap; olap.Offset = offset; olap.OffsetHigh = (offset >> 32);
- DWORD written;
- /* This braindead API will override the file pointer even if we specify
- * an explicit read offset... So do not expect this to mix well with
- * regular read() calls. */
- if (ReadFile (handle, buf, count, &written, &olap))
- return written;
- return -1;
+ }
+ return read( fd, buf, count );
}
#endif
diff --git a/src/test/block_test.c b/src/test/block_test.c
index f11ea2f..9642d9c 100644
--- a/src/test/block_test.c
+++ b/src/test/block_test.c
@@ -23,6 +23,9 @@
#endif
#include <stdio.h>
+#ifdef _WIN32
+#include <share.h>
+#endif
#include <string.h>
#undef NDEBUG
#include <assert.h>
@@ -39,7 +42,11 @@ static void test_block_File (void)
FILE *stream;
int res;
+#ifdef _WIN32
+ stream = _fsopen ("testfile.txt", "wb+", _SH_DENYNO);
+#else
stream = fopen ("testfile.txt", "wb+e");
+#endif
assert (stream != NULL);
res = fputs (text, stream);
@@ -47,7 +54,9 @@ static void test_block_File (void)
res = fflush (stream);
assert (res != EOF);
- block_t *block = block_File (fileno (stream));
+ int fd = fileno (stream);
+ assert(fd != -1);
+ block_t *block = block_File (fd);
fclose (stream);
assert (block != NULL);
--
2.7.0
More information about the vlc-devel
mailing list