os: File.write_string()
parent
036e762446
commit
a1c0bb3585
|
@ -65,6 +65,19 @@ pub fn (mut f File) writeln(s string) ?int {
|
|||
return (written + 1)
|
||||
}
|
||||
|
||||
pub fn (mut f File) write_string(s string) ?int {
|
||||
if !f.is_opened {
|
||||
return error('file is not opened')
|
||||
}
|
||||
// TODO perf
|
||||
written := C.fwrite(s.str, s.len, 1, f.cfile)
|
||||
if written == 0 && s.len != 0 {
|
||||
return error('0 bytes written')
|
||||
}
|
||||
return written
|
||||
}
|
||||
|
||||
|
||||
// write_to implements the RandomWriter interface
|
||||
pub fn (mut f File) write_to(pos int, buf []byte) ?int {
|
||||
C.fseek(f.cfile, pos, C.SEEK_SET)
|
||||
|
|
|
@ -114,7 +114,8 @@ mut:
|
|||
// autofree_pregen_buf strings.Builder
|
||||
// autofree_tmp_vars []string // to avoid redefining the same tmp vars in a single function
|
||||
called_fn_name string
|
||||
cur_mod string
|
||||
cur_mod string // TODO remove
|
||||
cur_mod_node ast.Module
|
||||
is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)`
|
||||
// nr_vars_to_free int
|
||||
// doing_autofree_tmp bool
|
||||
|
@ -1090,6 +1091,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
|||
// g.is_builtin_mod = node.name == 'builtin'
|
||||
g.is_builtin_mod = node.name in ['builtin', 'os', 'strconv', 'strings', 'gg']
|
||||
g.cur_mod = node.name
|
||||
g.cur_mod_node = node
|
||||
}
|
||||
ast.Return {
|
||||
g.write_defer_stmts_when_needed()
|
||||
|
|
Loading…
Reference in New Issue