lib/pattern: Support binary pattern buffers on windows
authorLogan Gunthorpe <logang@deltatee.com>
Fri, 18 Nov 2022 23:16:00 +0000 (16:16 -0700)
committerVincent Fu <vincent.fu@samsung.com>
Sat, 19 Nov 2022 00:36:10 +0000 (19:36 -0500)
On windows, binary files used as pattern buffers may be mangled or
truncated seeing the files are openned in text mode.

Fix this by passing O_BINARY on windows when openning the file.

Suggested-by: Vincent Fu <vincentfu@gmail.com>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
lib/pattern.c

index 1ae05758f7684457ac1308db87e93e85593c56fe..9be29af6bcf591adea3323dafee9b48684002c44 100644 (file)
@@ -47,7 +47,11 @@ static const char *parse_file(const char *beg, char *out,
        if (file == NULL)
                goto err_out;
 
+#ifdef _WIN32
+       fd = open(file, O_RDONLY | O_BINARY);
+#else
        fd = open(file, O_RDONLY);
+#endif
        if (fd < 0)
                goto err_free_out;