Mercurial > molko
diff libmlk-core/core/zfile.c @ 309:0858e33a762d
misc: initial windows support
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 06 Sep 2021 09:53:41 +0200 |
parents | 48a09c9d3d00 |
children | b271a0e8ce52 |
line wrap: on
line diff
--- a/libmlk-core/core/zfile.c Fri Jul 09 11:29:36 2021 +0200 +++ b/libmlk-core/core/zfile.c Mon Sep 06 09:53:41 2021 +0200 @@ -37,6 +37,12 @@ # define ZSTD_MAGICNUMBER 0xFD2FB528 #endif +/* Windows thing. */ +#if !defined(O_BINARY) +# define O_BINARY +#endif + +#include "port.h" #include "zfile.h" static int @@ -61,11 +67,12 @@ char *in = NULL; unsigned long long datasz; struct stat st; + ssize_t nr; /* Load uncompressed data. */ if (fstat(fd, &st) < 0) goto fail; - if (!(in = calloc(1, st.st_size)) || read(fd, in, st.st_size) != st.st_size) + if (!(in = calloc(1, st.st_size)) || (nr = read(fd, in, st.st_size)) != st.st_size) goto fail; switch ((datasz = ZSTD_getFrameContentSize(in, st.st_size))) { @@ -129,7 +136,7 @@ memset(zf, 0, sizeof (*zf)); - if ((fd = open(path, O_RDONLY)) < 0) + if ((fd = open(path, O_RDONLY | O_BINARY)) < 0) return -1; return is_zstd(fd) ? decompress(fd, zf) : reopen(fd, zf);