From bedde6b69b2c678d93c13ea323b36927c0dfc636 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Thu, 17 Jun 2021 18:05:47 +0200 Subject: [PATCH] Cleanup IO functions --- src/component/io.cpp | 49 +++----------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/src/component/io.cpp b/src/component/io.cpp index c6f9164..8b8316e 100644 --- a/src/component/io.cpp +++ b/src/component/io.cpp @@ -22,10 +22,7 @@ namespace io gsc::function::add("fremove", [](gsc::function_args args) { const auto path = args[0].as(); - - const auto result = std::remove(path); - - return result; + return std::remove(path); }); gsc::function::add("fopen", [](gsc::function_args args) @@ -43,56 +40,16 @@ namespace io return handle; }); - gsc::function::add("fgetc", [](gsc::function_args args) - { - const auto handle = args[0].as_ptr(); - - const char c = fgetc(handle); - const char str[2] = {c, '\0'}; - - return std::string(str); - }); - - gsc::function::add("fgets", [](gsc::function_args args) - { - const auto handle = args[0].as_ptr(); - const auto n = args[1].as(); - - char* buffer = (char*)calloc(n, sizeof(char)); - - fgets(buffer, n, handle); - - const std::string result = buffer; - - free(buffer); - - return result; - }); - - gsc::function::add("feof", [](gsc::function_args args) - { - const auto handle = args[0].as_ptr(); - return feof(handle); - }); - gsc::function::add("fclose", [](gsc::function_args args) { const auto handle = args[0].as_ptr(); return fclose(handle); }); - gsc::function::add("fputs", [](gsc::function_args args) + gsc::function::add("fwrite", [](gsc::function_args args) { - const auto text = args[0].as(); const auto handle = args[0].as_ptr(); - - return fputs(text, handle); - }); - - gsc::function::add("fprintf", [](gsc::function_args args) - { - const auto text = args[0].as(); - const auto handle = args[1].as_ptr(); + const auto text = args[1].as(); return fprintf(handle, text); });