From b670747d9e565d76e7becd7b30ba803b8c47b470 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 24 Nov 2021 07:53:58 -0800 Subject: consistent file ops Now we're down to 1 real warning and 1 false positive. --- src/lua.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lua.c b/src/lua.c index 3c97ce5..e983879 100644 --- a/src/lua.c +++ b/src/lua.c @@ -318,18 +318,18 @@ void save_to_current_definition_and_editor_buffer (lua_State *L, const char *def lua_getfield(L, -1, Current_definition); const char *contents = lua_tostring(L, -1); lua_pop(L, 1); - int outfd = open("teliva_editbuffer", O_WRONLY|O_CREAT|O_TRUNC, 0644); + FILE *out = fopen("teliva_editbuffer", "w"); if (contents != NULL) - write(outfd, contents, strlen(contents)); - close(outfd); + fprintf(out, "%s", contents); + fclose(out); lua_settop(L, 0); } static void read_contents (char *filename, char *out) { - int infd = open(filename, O_RDONLY); - read(infd, out, 8190); /* TODO: handle overly large file */ - close(infd); + FILE *in = fopen(filename, "r"); + fread(out, 8190, 1, in); /* TODO: handle overly large file */ + fclose(in); } -- cgit 1.4.1-2-gfad0