1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: fix bug where read_bytes would return only the first byte

This commit is contained in:
prime31 2019-12-17 13:16:56 -08:00 committed by Alexander Medvednikov
parent e68200538a
commit f00f9fbf5a

View File

@ -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.