]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_win32util.c
ncurses 6.5 - patch 20240504
[ncurses.git] / ncurses / tinfo / lib_win32util.c
index d5bcd70199ed9e189cfcec228e12f9383e499fe0..c67c8ceb98625604c0685727453bddb2193ce39e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2020-2021,2023 Thomas E. Dickey                                *
  * Copyright 1998-2009,2010 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -34,7 +34,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_win32util.c,v 1.1 2020/08/14 21:57:01 juergen Exp $")
+MODULE_ID("$Id: lib_win32util.c,v 1.4 2023/06/17 17:19:06 tom Exp $")
 
 #ifdef _NC_WINDOWS
 #include <io.h>
@@ -48,13 +48,13 @@ MODULE_ID("$Id: lib_win32util.c,v 1.1 2020/08/14 21:57:01 juergen Exp $")
 
 /*   This function tests, whether or not the ncurses application
      is running as a descendant of MSYS2/cygwin mintty terminal
-     application. mintty doesn't use Windows Console for it's screen
+     application. mintty doesn't use Windows Console for its screen
      I/O, so the native Windows _isatty doesn't recognize it as
      character device. But we can discover we are at the end of an
      Pipe and can query the server side of the pipe, looking whether
      or not this is mintty.
      For now we terminate the program if we discover that situation.
-     Althogh in theory it would be possible, to remotely manipulate
+     Although in theory it would be possible, to remotely manipulate
      the terminal state of mintty, this is out of scope for now and
      not worth the significant effort.
  */
@@ -68,10 +68,10 @@ _nc_console_checkmintty(int fd, LPHANDLE pMinTTY)
     T((T_CALLED("lib_winhelper::_nc_console_checkmintty(%d, %p)"), fd, pMinTTY));
 
     if (handle != INVALID_HANDLE_VALUE) {
-        dw = GetFileType(handle);
+       dw = GetFileType(handle);
        if (dw == FILE_TYPE_PIPE) {
            if (GetNamedPipeInfo(handle, 0, 0, 0, 0)) {
-               ULONG pPid;
+               ULONG pPid;
                /* Requires NT6 */
                if (GetNamedPipeServerProcessId(handle, &pPid)) {
                    TCHAR buf[MAX_PATH];
@@ -79,8 +79,7 @@ _nc_console_checkmintty(int fd, LPHANDLE pMinTTY)
                    /* These security attributes may allow us to
                       create a remote thread in mintty to manipulate
                       the terminal state remotely */
-                   HANDLE pHandle = OpenProcess(
-                                                PROCESS_CREATE_THREAD
+                   HANDLE pHandle = OpenProcess(PROCESS_CREATE_THREAD
                                                 | PROCESS_QUERY_INFORMATION
                                                 | PROCESS_VM_OPERATION
                                                 | PROCESS_VM_WRITE
@@ -88,20 +87,19 @@ _nc_console_checkmintty(int fd, LPHANDLE pMinTTY)
                                                 FALSE,
                                                 pPid);
                    if (pMinTTY)
-                       *pMinTTY = INVALID_HANDLE_VALUE;
+                       *pMinTTY = INVALID_HANDLE_VALUE;
                    if (pHandle != INVALID_HANDLE_VALUE) {
-                       if ((len = GetProcessImageFileName(
-                                                          pHandle,
+                       if ((len = GetProcessImageFileName(pHandle,
                                                           buf,
                                                           (DWORD)
                                                           array_length(buf)))) {
                            TCHAR *pos = _tcsrchr(buf, _T('\\'));
                            if (pos) {
-                               pos++;
+                               pos++;
                                if (_tcsnicmp(pos, _TEXT("mintty.exe"), 10)
                                    == 0) {
                                    if (pMinTTY)
-                                       *pMinTTY = pHandle;
+                                       *pMinTTY = pHandle;
                                    code = 1;
                                }
                            }
@@ -114,7 +112,8 @@ _nc_console_checkmintty(int fd, LPHANDLE pMinTTY)
     returnCode(code);
 }
 #endif /* _NC_CHECK_MINTTY */
-\f
+
+#if HAVE_GETTIMEOFDAY == 2
 #define JAN1970 116444736000000000LL   /* the value for 01/01/1970 00:00 */
 
 NCURSES_EXPORT(int)
@@ -130,5 +129,6 @@ _nc_gettimeofday(struct timeval *tv, void *tz GCC_UNUSED)
     tv->tv_sec = (long) ((data.since1601 - JAN1970) / 10000000LL);
     return (0);
 }
+#endif // HAVE_GETTIMEOFDAY == 2
 
 #endif // _NC_WINDOWS