diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-07-07 17:42:33 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-07-07 17:42:33 -0400 |
commit | 5044062793b482155fb7995881e6e6dac326b96a (patch) | |
tree | 614a93c4c2b127b33090d6f8b613bb578ca55737 | |
parent | 577bafc3dec62f5d7c9b4b8e29102cd1e83373f6 (diff) |
oops fclose fixed
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | std/io.toc | 34 | ||||
-rw-r--r-- | test.toc | 13 | ||||
-rw-r--r-- | types.c | 2 |
4 files changed, 26 insertions, 28 deletions
@@ -18,4 +18,7 @@ std/*.o *.obj *.exe .vs -test.txt +test*.txt +c_test +toc_test +test.c @@ -20,7 +20,7 @@ raw_stdout - standard output raw_stderr - standard error raw_file_write - write to a raw file raw_file_open_write - open a raw file for writing -raw_file_close - flush and close a raw file +raw_file_close - close a raw file */ @@ -37,16 +37,16 @@ raw_file_close - flush and close a raw file O_CREAT ::= 0x40; RawFile ::= int; - raw_file_write ::= fn(file: RawFile, buf: &void, size: int) bool { + raw_file_write ::= fn(file: RawFile, buf: &void, size: int) err := FILE_ERR_OK { while size > 0 { bytes_written := write(file as #C int, buf, size as #C size_t); if bytes_written < 0 { - return false; + err = FILE_ERR_MISC; // @TODO + return; } size -= bytes_written; buf += bytes_written; } - return true; } raw_stdout ::= fn() RawFile { return 1; @@ -121,42 +121,46 @@ fopen_write ::= fn(name: []char) f: &File, error: FileError { } } -flush ::= fn(use f: &File) { - raw_file_write(raw, &buffer[0], buffer_used); +flush ::= fn(use f: &File) err: FileError { + err = raw_file_write(raw, &buffer[0], buffer_used); buffer_used = 0; } fclose ::= fn(f: &File) err: FileError { + flush(f); err = raw_file_close(f.raw); mem.del(f); } -fwrites ::= fn(use f: &File, s : []char) { +fwrites ::= fn(use f: &File, s : []char) FileError { if f.nobuffer { - raw_file_write(raw, &s[0], s.len); - return; + return raw_file_write(raw, &s[0], s.len); } if buffer_used + s.len > BUFSZ { flush(f); if s.len > BUFSZ { - raw_file_write(raw, &s[0], s.len); + return raw_file_write(raw, &s[0], s.len); } else { mem.mem_copy(&buffer[0], &s[0], s.len); buffer_used = s.len; + return FILE_ERR_OK; } } else { mem.mem_copy(&buffer[buffer_used], &s[0], s.len); buffer_used += s.len; + return FILE_ERR_OK; } } -fputs ::= fn(f: &File, s: []char) { - fwrites(f, s); - fwrites(f, "\n"); +fputs ::= fn(f: &File, s: []char) err : FileError { + err = fwrites(f, s); + if !err { + err = fwrites(f, "\n"); + } } -puts ::= fn(s: []char) { - fputs(&std_out, s); +puts ::= fn(s: []char) FileError { + return fputs(&std_out, s); } @@ -6,17 +6,8 @@ main ::= fn() { if err { base.error("Couldn't open file!"); } - io.fputs(file, "This file has some stuff in it."); - io.puts("Hello!"); - io.puts("yes"); - io.fputs(file, "here is more stuff for the file."); - for i := 1..1000 { - io.fwrites(file, "Here's a line in the file"); - for j := 1..i { - io.fwrites(file, "!"); - } - io.fwrites(file, "\n"); + for i := 1..100000000 { + io.fputs(file, "Hello"); } io.fclose(file); } -main(); @@ -3732,7 +3732,7 @@ top: r->expr.type = tr->fn->ret_type; } } else { - if (!type_is_void(&tr->fn->ret_type) || tr->fn->ret_decls) { + if (!type_is_void(&tr->fn->ret_type) && !tr->fn->ret_decls) { err_print(s->where, "No return value in non-void function."); return false; } |