From 3773a812bd3c65f30d45ba18ee0734bdc19701f4 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Fri, 28 Jan 2022 15:39:57 -0500 Subject: [PATCH] Incorporate realtakase's suggestions. --- src/api/process.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/process.c b/src/api/process.c index cabcbf17..8f8a724b 100644 --- a/src/api/process.c +++ b/src/api/process.c @@ -330,8 +330,9 @@ static int f_write(lua_State* L) { #if _WIN32 DWORD dwWritten; if (!WriteFile(self->child_pipes[STDIN_FD][1], data, data_size, &dwWritten, NULL)) { + int lastError = GetLastError(); signal_process(self, SIGNAL_TERM); - return luaL_error(L, "error writing to process: %d", GetLastError()); + return luaL_error(L, "error writing to process: %d", lastError); } length = dwWritten; #else @@ -339,8 +340,9 @@ static int f_write(lua_State* L) { if (length < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) length = 0; else if (length < 0) { + const char* lastError = strerror(errno); signal_process(self, SIGNAL_TERM); - return luaL_error(L, "error writing to process: %s", strerror(errno)); + return luaL_error(L, "error writing to process: %s", lastError); } #endif lua_pushinteger(L, length);