From f00f9fbf5a9502eb0a7f9c9405df953ee4cb8341 Mon Sep 17 00:00:00 2001 From: prime31 Date: Tue, 17 Dec 2019 13:16:56 -0800 Subject: [PATCH] os: fix bug where read_bytes would return only the first byte --- vlib/os/os.v | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vlib/os/os.v b/vlib/os/os.v index 1bff1bf629..4846cacc5e 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -96,11 +96,11 @@ pub fn read_bytes(path string) ?[]byte { C.fseek(fp, 0, C.SEEK_END) fsize := C.ftell(fp) C.rewind(fp) - println('fsize=$fsize') + mut res := [`0`].repeat(fsize) - nreadbytes := C.fread(res.data, fsize, 1, fp) + nreadelements := C.fread(res.data, fsize, 1, fp) C.fclose(fp) - return res[0..nreadbytes] + return res[0..nreadelements * fsize] } // read_file reads the file in `path` and returns the contents.