From bb79df932b8b4e5695ffdac7532b4a080becc908 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 19 Mar 2021 04:51:31 +0300 Subject: [PATCH] net/os: deprecate write_str() in favor of write_string() --- vlib/net/tcp.v | 6 ++++++ vlib/os/file.c.v | 9 ++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/vlib/net/tcp.v b/vlib/net/tcp.v index 8f2b5e4fcf..e5eca4728d 100644 --- a/vlib/net/tcp.v +++ b/vlib/net/tcp.v @@ -67,10 +67,16 @@ pub fn (mut c TcpConn) write(bytes []byte) ?int { } // write_str blocks and attempts to write all data +[deprecated: 'use TcpConn.write_string() instead'] pub fn (mut c TcpConn) write_str(s string) ?int { return c.write_ptr(s.str, s.len) } +// write_string blocks and attempts to write all data +pub fn (mut c TcpConn) write_string(s string) ?int { + return c.write_ptr(s.str, s.len) +} + pub fn (mut c TcpConn) read_ptr(buf_ptr byteptr, len int) ?int { mut res := wrap_read_result(C.recv(c.sock.handle, buf_ptr, len, 0)) ? $if trace_tcp ? { diff --git a/vlib/os/file.c.v b/vlib/os/file.c.v index 939f76e830..96b27a2bdd 100644 --- a/vlib/os/file.c.v +++ b/vlib/os/file.c.v @@ -311,14 +311,9 @@ pub fn (mut f File) flush() { // write_str writes the bytes of a string into a file, // *including* the terminating 0 byte. +[deprecated: 'use File.write_string() instead'] pub fn (mut f File) write_str(s string) ? { - if !f.is_opened { - return error('file is closed') - } - written := int(C.fwrite(voidptr(s.str), s.len, 1, f.cfile)) - if written == 0 && s.len != 0 { - return error('0 bytes written') - } + f.write_string(s) or { return err } } // read_struct reads a single struct of type `T`