From 72c56ccc856a45d18607073afaf066eba447e8bb Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 24 Jul 2021 08:29:35 +0300 Subject: [PATCH] v.builder: use os.write_file/os.write_file_array for writing full files to disk. --- vlib/v/builder/c.v | 5 +---- vlib/v/builder/js.v | 4 +--- vlib/v/gen/native/gen.v | 4 +--- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index e39fd14c28..20f9f672d3 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -21,14 +21,11 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) { b.pref.out_name_c = os.real_path(out_file) b.info('build_c($out_file)') output2 := b.gen_c(v_files) - mut f := os.create(out_file) or { panic(err) } - f.writeln(output2) or { panic(err) } - f.close() + os.write_file(out_file, output2) or { panic(err) } if b.pref.is_stats { b.stats_lines = output2.count('\n') + 1 b.stats_bytes = output2.len } - // os.write_file(out_file, b.gen_c(v_files)) } pub fn (mut b Builder) compile_c() { diff --git a/vlib/v/builder/js.v b/vlib/v/builder/js.v index f136ac0ceb..241f6936fa 100644 --- a/vlib/v/builder/js.v +++ b/vlib/v/builder/js.v @@ -17,13 +17,11 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) { b.out_name_js = out_file b.info('build_js($out_file)') output := b.gen_js(v_files) - mut f := os.create(out_file) or { panic(err) } - f.writeln(output) or { panic(err) } + os.write_file(out_file, output) or { panic(err) } if b.pref.is_stats { b.stats_lines = output.count('\n') + 1 b.stats_bytes = output.len } - f.close() } pub fn (mut b Builder) compile_js() { diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index 5817c199d0..9695e4966b 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -113,10 +113,8 @@ pub fn (mut g Gen) generate_header() { pub fn (mut g Gen) create_executable() { // Create the binary // should be .o ? - mut f := os.create(g.out_name) or { panic(err) } + os.write_file_array(g.out_name, g.buf) or { panic(err) } os.chmod(g.out_name, 0o775) // make it executable - unsafe { f.write_ptr(g.buf.data, g.buf.len) } - f.close() if g.pref.is_verbose { println('\n$g.out_name: native binary has been successfully generated') }