Added close_handle().
authorIain Patterson <me@iain.cx>
Tue, 30 Aug 2016 07:34:19 +0000 (08:34 +0100)
committerIain Patterson <me@iain.cx>
Mon, 5 Sep 2016 07:44:23 +0000 (08:44 +0100)
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
io.h

diff --git a/io.cpp b/io.cpp
index ce455a3..3460cdc 100644 (file)
--- a/io.cpp
+++ b/io.cpp
@@ -83,6 +83,19 @@ static inline void write_bom(logger_t *logger, unsigned long *out) {
   }\r
 }\r
 \r
+void close_handle(HANDLE *handle, HANDLE *remember) {\r
+  if (remember) *remember = INVALID_HANDLE_VALUE;\r
+  if (! handle) return;\r
+  if (! *handle) return;\r
+  CloseHandle(*handle);\r
+  if (remember) *remember = *handle;\r
+  *handle = 0;\r
+}\r
+\r
+void close_handle(HANDLE *handle) {\r
+  close_handle(handle, NULL);\r
+}\r
+\r
 /* Get path, share mode, creation disposition and flags for a stream. */\r
 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) {\r
   TCHAR value[NSSM_STDIO_LENGTH];\r
diff --git a/io.h b/io.h
index 2bb6782..31f1e0d 100644 (file)
--- a/io.h
+++ b/io.h
@@ -22,10 +22,14 @@ typedef struct {
   __int64 size;\r
   unsigned long *tid_ptr;\r
   unsigned long *rotate_online;\r
+  bool timestamp_log;\r
+  __int64 line_length;\r
   bool copy_and_truncate;\r
   unsigned long rotate_delay;\r
 } logger_t;\r
 \r
+void close_handle(HANDLE *, HANDLE *);\r
+void close_handle(HANDLE *);\r
 int get_createfile_parameters(HKEY, TCHAR *, TCHAR *, unsigned long *, unsigned long, unsigned long *, unsigned long, unsigned long *, unsigned long, bool *);\r
 int set_createfile_parameter(HKEY, TCHAR *, TCHAR *, unsigned long);\r
 int delete_createfile_parameter(HKEY, TCHAR *, TCHAR *);\r