From ca07ff62f7896566f9cf5bf91abda99c9641137b Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Tue, 30 Aug 2016 08:34:19 +0100 Subject: [PATCH] Added close_handle(). New function to close then zero a handle. If we pass a second handle pointer, it will be set to the value of the handle that was closed, or INVALID_HANDLE_VALUE. We can inspect the remembered handle to see if we need to wait, eg for a thread. --- io.cpp | 13 +++++++++++++ io.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/io.cpp b/io.cpp index ce455a3..3460cdc 100644 --- a/io.cpp +++ b/io.cpp @@ -83,6 +83,19 @@ static inline void write_bom(logger_t *logger, unsigned long *out) { } } +void close_handle(HANDLE *handle, HANDLE *remember) { + if (remember) *remember = INVALID_HANDLE_VALUE; + if (! handle) return; + if (! *handle) return; + CloseHandle(*handle); + if (remember) *remember = *handle; + *handle = 0; +} + +void close_handle(HANDLE *handle) { + close_handle(handle, NULL); +} + /* Get path, share mode, creation disposition and flags for a stream. */ int get_createfile_parameters(HKEY key, TCHAR *prefix, TCHAR *path, unsigned long *sharing, unsigned long default_sharing, unsigned long *disposition, unsigned long default_disposition, unsigned long *flags, unsigned long default_flags, bool *copy_and_truncate) { TCHAR value[NSSM_STDIO_LENGTH]; diff --git a/io.h b/io.h index 2bb6782..31f1e0d 100644 --- a/io.h +++ b/io.h @@ -22,10 +22,14 @@ typedef struct { __int64 size; unsigned long *tid_ptr; unsigned long *rotate_online; + bool timestamp_log; + __int64 line_length; bool copy_and_truncate; unsigned long rotate_delay; } logger_t; +void close_handle(HANDLE *, HANDLE *); +void close_handle(HANDLE *); int get_createfile_parameters(HKEY, TCHAR *, TCHAR *, unsigned long *, unsigned long, unsigned long *, unsigned long, unsigned long *, unsigned long, bool *); int set_createfile_parameter(HKEY, TCHAR *, TCHAR *, unsigned long); int delete_createfile_parameter(HKEY, TCHAR *, TCHAR *); -- 2.7.4