Browse Source

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.
Iain Patterson 6 years ago
parent
commit
ca07ff62f7
2 changed files with 17 additions and 0 deletions
  1. 13 0
      io.cpp
  2. 4 0
      io.h

+ 13 - 0
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];

+ 4 - 0
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 *);