From 2bf1015ae15cf65f5308e6c2159f120093916657 Mon Sep 17 00:00:00 2001 From: div72 <60045611+div72@users.noreply.github.com> Date: Wed, 18 Aug 2021 17:08:41 +0300 Subject: [PATCH] os: add File.read_into_ptr (#11219) --- vlib/os/file.c.v | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index 7383f5a781..3de227913f 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -463,6 +463,12 @@ pub fn (f &File) read_from(pos u64, mut buf []byte) ?int { return error('Could not read file') } +// read_into_ptr reads at most max_size bytes from the file and writes it into ptr. +// Returns the amount of bytes read or an error. +pub fn (f &File) read_into_ptr(ptr &byte, max_size int) ?int { + return fread(ptr, 1, max_size, f.cfile) +} + // **************************** Utility ops *********************** // flush writes any buffered unwritten data left in the file stream. pub fn (mut f File) flush() {