]> sourceware.org Git - newlib-cygwin.git/blobdiff - winsup/utils/cygcheck.cc
Cygwin: add 3.2.1 release file and add fixes up to this point
[newlib-cygwin.git] / winsup / utils / cygcheck.cc
index 2560b07f16bcf2c7c2acddc1b83538d884dd13fa..a45ab5d4d4f6d03848aef3a83c3edbd5e6774cd5 100644 (file)
@@ -1,14 +1,12 @@
 /* cygcheck.cc
 
-   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009, 2010, 2011, 2012 Red Hat, Inc.
-
    This file is part of Cygwin.
 
    This software is a copyrighted work licensed under the terms of the
    Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
    details. */
 
+#define _WIN32_WINNT 0x0a00
 #define cygwin_internal cygwin_internal_dontuse
 #include <stdio.h>
 #include <stdlib.h>
@@ -16,6 +14,7 @@
 #include <string.h>
 #include <sys/time.h>
 #include <ctype.h>
+#include <fcntl.h>
 #include <io.h>
 #include <windows.h>
 #include <wininet.h>
@@ -24,8 +23,8 @@
 #include <getopt.h>
 #include "../cygwin/include/cygwin/version.h"
 #include "../cygwin/include/sys/cygwin.h"
+#define _NOMNTENT_MACROS
 #include "../cygwin/include/mntent.h"
-#include "../cygwin/cygprops.h"
 #undef cygwin_internal
 #include "loadlib.h"
 
@@ -48,14 +47,9 @@ int find_package = 0;
 int list_package = 0;
 int grep_packages = 0;
 int del_orphaned_reg = 0;
-int unique_object_name_opt = 0;
 
 static char emptystr[] = "";
 
-/* This is global because it's used in both internet_display_error as well
-   as package_grep.  */
-BOOL (WINAPI *pInternetCloseHandle) (HINTERNET);
-
 #ifdef __GNUC__
 typedef long long longlong;
 #else
@@ -68,8 +62,6 @@ void package_find (int, char **);
 void package_list (int, char **);
 /* In bloda.cc  */
 void dump_dodgy_apps (int verbose);
-/* Forward declaration */
-static void usage (FILE *, int);
 
 static const char *known_env_vars[] = {
   "c_include_path",
@@ -105,28 +97,43 @@ static common_apps[] = {
   {"awk", 0},
   {"bash", 0},
   {"cat", 0},
+  {"certutil", 0},
+  {"clinfo", 0},
+  {"comp", 0},
+  {"convert", 0},
   {"cp", 0},
   {"cpp", 1},
   {"crontab", 0},
+  {"curl", 0},
+  {"expand", 0},
   {"find", 0},
+  {"ftp", 0},
   {"gcc", 0},
   {"gdb", 0},
   {"grep", 0},
+  {"hostname", 0},
   {"kill", 0},
+  {"klist", 0},
   {"ld", 0},
   {"ls", 0},
   {"make", 0},
   {"mv", 0},
+  {"nslookup", 0},
   {"patch", 0},
   {"perl", 0},
+  {"replace", 0},
   {"rm", 0},
   {"sed", 0},
-  {"ssh", 0},
   {"sh", 0},
+  {"shutdown", 0},
+  {"sort", 0},
+  {"ssh", 0},
   {"tar", 0},
   {"test", 0},
+  {"timeout", 0},
   {"vi", 0},
   {"vim", 0},
+  {"whoami", 0},
   {0, 0}
 };
 
@@ -134,9 +141,6 @@ static common_apps[] = {
 enum
 {
   CO_DELETE_KEYS = 0x100,
-  CO_ENABLE_UON = 0x101,
-  CO_DISABLE_UON = 0x102,
-  CO_SHOW_UON = 0x103
 };
 
 static int num_paths, max_paths;
@@ -229,7 +233,7 @@ display_internet_error (const char *message, ...)
 
   va_start (hptr, message);
   while ((h = va_arg (hptr, HINTERNET)) != 0)
-    pInternetCloseHandle (h);
+    InternetCloseHandle (h);
   va_end (hptr);
 
   return 1;
@@ -321,10 +325,7 @@ pathlike::check_existence (const char *fn, int showall, int verbose,
                           char* first, const char *ext1, const char *ext2)
 {
   char file[4000];
-  strcpy (file, dir);
-  strcat (file, fn);
-  strcat (file, ext1);
-  strcat (file, ext2);
+  snprintf (file, sizeof file, "%s%s%s%s", dir, fn, ext1, ext2);
 
   wide_path wpath (file);
   if (GetFileAttributesW (wpath) != (DWORD) - 1)
@@ -360,7 +361,8 @@ find_on_path (const char *in_file, const char *ext, bool showall = false,
 {
   static char rv[4000];
 
-  /* Sort of a kludge but we've already tested this once, so don't try it again */
+  /* Sort of a kludge but we've already tested this once, so don't try it
+     again */
   if (in_file == rv)
     return in_file;
 
@@ -373,13 +375,15 @@ find_on_path (const char *in_file, const char *ext, bool showall = false,
   *rv = '\0';
   if (!in_file)
     {
-      display_error ("internal error find_on_path: NULL pointer for file", false, false);
+      display_error ("internal error find_on_path: NULL pointer for file",
+                    false, false);
       return 0;
     }
 
   if (!ext)
     {
-      display_error ("internal error find_on_path: NULL pointer for default_extension", false, false);
+      display_error ("internal error find_on_path: "
+                    "NULL pointer for default_extension", false, false);
       return 0;
     }
 
@@ -399,7 +403,8 @@ find_on_path (const char *in_file, const char *ext, bool showall = false,
 
   if (!file)
     {
-      display_error ("internal error find_on_path: cygpath conversion failed for %s\n", in_file);
+      display_error ("internal error find_on_path: "
+                    "cygpath conversion failed for %s\n", in_file);
       return 0;
     }
 
@@ -413,7 +418,8 @@ find_on_path (const char *in_file, const char *ext, bool showall = false,
        pth->check_existence (file, showall, verbose, rv, ext);
 
        if (checklinks)
-         pth->check_existence (file, showall, verbose, rv, ext, LINK_EXTENSION);
+         pth->check_existence (file, showall, verbose, rv, ext,
+                               LINK_EXTENSION);
 
        if (!*ext)
          continue;
@@ -594,9 +600,39 @@ dll_info (const char *path, HANDLE fh, int lvl, int recurse)
 {
   DWORD junk;
   int i;
+  if (is_symlink (fh))
+    {
+      if (!verbose)
+       puts ("");
+      else
+       {
+         char buf[PATH_MAX + 1] = "";
+         readlink (fh, buf, sizeof(buf) - 1);
+         printf (" (symlink to %s)\n", buf);
+       }
+      return;
+    }
   int pe_header_offset = get_dword (fh, 0x3c);
   if (GetLastError () != NO_ERROR)
     display_error ("get_dword");
+  WORD arch = get_word (fh, pe_header_offset + 4);
+  if (GetLastError () != NO_ERROR)
+    display_error ("get_word");
+#ifdef __x86_64__
+  if (arch != IMAGE_FILE_MACHINE_AMD64)
+    {
+      puts (verbose ? " (not x86_64 dll)" : "\n");
+      return;
+    }
+  int base_off = 108;
+#else
+  if (arch != IMAGE_FILE_MACHINE_I386)
+    {
+      puts (verbose ? " (not x86 dll)" : "\n");
+      return;
+    }
+  int base_off = 92;
+#endif
   int opthdr_ofs = pe_header_offset + 4 + 20;
   unsigned short v[6];
 
@@ -619,19 +655,19 @@ dll_info (const char *path, HANDLE fh, int lvl, int recurse)
   else
     printf ("\n");
 
-  int num_entries = get_dword (fh, opthdr_ofs + 92);
+  int num_entries = get_dword (fh, opthdr_ofs + base_off + 0);
   if (GetLastError () != NO_ERROR)
     display_error ("get_dword");
-  int export_rva = get_dword (fh, opthdr_ofs + 96);
+  int export_rva = get_dword (fh, opthdr_ofs + base_off + 4);
   if (GetLastError () != NO_ERROR)
     display_error ("get_dword");
-  int export_size = get_dword (fh, opthdr_ofs + 100);
+  int export_size = get_dword (fh, opthdr_ofs + base_off + 8);
   if (GetLastError () != NO_ERROR)
     display_error ("get_dword");
-  int import_rva = get_dword (fh, opthdr_ofs + 104);
+  int import_rva = get_dword (fh, opthdr_ofs + base_off + 12);
   if (GetLastError () != NO_ERROR)
     display_error ("get_dword");
-  int import_size = get_dword (fh, opthdr_ofs + 108);
+  int import_size = get_dword (fh, opthdr_ofs + base_off + 16);
   if (GetLastError () != NO_ERROR)
     display_error ("get_dword");
 
@@ -667,17 +703,20 @@ dll_info (const char *path, HANDLE fh, int lvl, int recurse)
 
          ExpDirectory *ed = (ExpDirectory *) exp;
          int ofs = ed->name_rva - export_rva;
-         struct tm *tm = localtime ((const time_t *) &(ed->timestamp));
-         if (tm->tm_year < 60)
+         time_t ts = ed->timestamp;    /* timestamp is only 4 bytes! */
+         struct tm *tm = localtime (&ts);
+         if (tm && tm->tm_year < 60)
            tm->tm_year += 2000;
-         if (tm->tm_year < 200)
+         if (tm && tm->tm_year < 200)
            tm->tm_year += 1900;
          printf ("%*c", lvl + 2, ' ');
-         printf ("\"%s\" v%d.%d ts=", exp + ofs,
+         printf ("\"%s\" v%d.%d", exp + ofs,
                  ed->major_ver, ed->minor_ver);
-         printf ("%d/%d/%d %d:%02d\n",
-                 tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
-                 tm->tm_hour, tm->tm_min);
+         if (tm)
+           printf (" ts=%04d-%02d-%02d %02d:%02d",
+                   tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+                   tm->tm_hour, tm->tm_min);
+         putchar ('\n');
        }
     }
 
@@ -733,7 +772,12 @@ track_down (const char *file, const char *suffix, int lvl)
   const char *path = find_on_path (file, suffix, false, true);
   if (!path)
     {
-      display_error ("track_down: could not find %s\n", file);
+      /* The api-ms-win-*.dll files are in system32/downlevel and not in the
+        DLL search path, so find_on_path doesn't find them.  Since they are
+        never actually linked against by the executables, they are of no
+        interest to us.  Skip any error message in not finding them. */
+      if (strncasecmp (file, "api-ms-win-", 11) || strcasecmp (suffix, ".dll"))
+       display_error ("track_down: could not find %s\n", file);
       return false;
     }
 
@@ -767,12 +811,6 @@ track_down (const char *file, const char *suffix, int lvl)
   if (lvl)
     printf ("%*c", lvl, ' ');
 
-  if (!path)
-    {
-      display_error ("file not found - '%s'\n", file);
-      return false;
-    }
-
   printf ("%s", path);
 
   wide_path wpath (path);
@@ -1115,7 +1153,7 @@ pretty_id ()
   sz = -sz;
   for (char **g = groups; g <= ng; g++)
     if ((g != ng) && (++i < n))
-      printf ("%*s", sz, *g);
+      printf ("%*s", (int) sz, *g);
     else
       {
        puts (*g);
@@ -1161,15 +1199,17 @@ dump_sysinfo_services ()
   int ret = fscanf (f, "cygrunsrv V%u.%u", &maj, &min);
   if (ferror (f) || feof (f) || ret == EOF || maj < 1 || min < 10)
     {
-      puts ("The version of cygrunsrv installed is too old to dump service info.\n");
+      puts ("The version of cygrunsrv installed is too old to dump "
+           "service info.\n");
       return;
     }
-  fclose (f);
+  pclose (f);
 
   /* For verbose mode, just run cygrunsrv --list --verbose and copy output
      verbatim; otherwise run cygrunsrv --list and then cygrunsrv --query for
      each service.  */
-  snprintf (buf, sizeof (buf), (verbose ? "\"%s\" --list --verbose" : "\"%s\" --list"),
+  snprintf (buf, sizeof (buf),
+           (verbose ? "\"%s\" --list --verbose" : "\"%s\" --list"),
            cygrunsrv);
   if ((f = popen (buf, "rt")) == NULL)
     {
@@ -1203,7 +1243,8 @@ dump_sysinfo_services ()
            snprintf (buf2, sizeof (buf2), "\"%s\" --query %s", cygrunsrv, srv);
            if ((f = popen (buf2, "rt")) == NULL)
              {
-               printf ("Failed to execute '%s', skipping services check.\n", buf2);
+               printf ("Failed to execute '%s', skipping services check.\n",
+                       buf2);
                return;
              }
 
@@ -1305,88 +1346,7 @@ memmem (char *haystack, size_t haystacklen,
   return NULL;
 }
 
-int
-handle_unique_object_name (int opt, char *path)
-{
-  HANDLE fh, fm;
-  void *haystack = NULL;
-
-  if (!path || !*path)
-    usage (stderr, 1);
-
-  DWORD access, share, protect, mapping;
-
-  if (opt == CO_SHOW_UON)
-    {
-      access = GENERIC_READ;
-      share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
-      protect = PAGE_READONLY;
-      mapping = FILE_MAP_READ;
-    }
-  else
-    {
-      access = GENERIC_READ | GENERIC_WRITE;
-      share = 0;
-      protect = PAGE_READWRITE;
-      mapping = FILE_MAP_WRITE;
-    }
-
-  fh = CreateFile (path, access, share, NULL, OPEN_EXISTING,
-                  FILE_FLAG_BACKUP_SEMANTICS, NULL);
-  if (fh == INVALID_HANDLE_VALUE)
-    {
-      DWORD err = GetLastError ();
-      switch (err)
-       {
-       case ERROR_SHARING_VIOLATION:
-         display_error ("%s still used by other Cygwin processes.\n"
-                        "Please stop all of them and retry.", path);
-         break;
-       case ERROR_ACCESS_DENIED:
-         display_error (
-           "Your permissions are not sufficient to change the file \"%s\"",
-           path);
-         break;
-       case ERROR_FILE_NOT_FOUND:
-         display_error ("%s: No such file.", path);
-         break;
-       default:
-         display_error (path, true, false);
-         break;
-       }
-      return 1;
-    }
-  if (!(fm = CreateFileMapping (fh, NULL, protect, 0, 0, NULL)))
-    display_error ("CreateFileMapping");
-  else if (!(haystack = MapViewOfFile (fm, mapping, 0, 0, 0)))
-    display_error ("MapViewOfFile");
-  else
-    {
-      size_t haystacklen = GetFileSize (fh, NULL);
-      cygwin_props_t *cygwin_props = (cygwin_props_t *)
-              memmem ((char *) haystack, haystacklen,
-                      CYGWIN_PROPS_MAGIC, sizeof (CYGWIN_PROPS_MAGIC));
-      if (!cygwin_props)
-       display_error ("Can't find Cygwin properties in %s", path);
-      else
-       {
-         if (opt != CO_SHOW_UON)
-           cygwin_props->disable_key = opt - CO_ENABLE_UON;
-         printf ("Unique object names are %s\n",
-                 cygwin_props->disable_key ? "disabled" : "enabled");
-         UnmapViewOfFile (haystack);
-         CloseHandle (fm);
-         CloseHandle (fh);
-         return 0;
-       }
-    }
-  if (haystack)
-    UnmapViewOfFile (haystack);
-  if (fm)
-    CloseHandle (fm);
-  CloseHandle (fh);
-  return 1;
-}
+extern "C" NTSTATUS NTAPI RtlGetVersion (PRTL_OSVERSIONINFOEXW);
 
 static void
 dump_sysinfo ()
@@ -1396,56 +1356,71 @@ dump_sysinfo ()
   time_t now;
   char *found_cygwin_dll;
   bool is_nt = false;
-  bool more_info = true;
   char osname[128];
   DWORD obcaseinsensitive = 1;
   HKEY key;
 
+  /* MSVCRT popen (called by pretty_id and dump_sysinfo_services) SEGVs if
+     COMSPEC isn't set correctly.  Simply enforce it here.  Using
+     Get/SetEnvironmentVariable to set the dir does *not* help, btw.
+     Apparently MSVCRT keeps its own copy of the environment and changing
+     that requires to use _wputenv. */
+  if (!_wgetenv (L"COMSPEC"))
+    {
+      WCHAR comspec[MAX_PATH + 17];
+      wcscpy (comspec, L"COMSPEC=");
+      GetSystemDirectoryW (comspec + 8, MAX_PATH);
+      wcsncat (comspec, L"\\cmd.exe", sizeof comspec);
+      _wputenv (comspec);
+    }
+
   printf ("\nCygwin Configuration Diagnostics\n");
   time (&now);
   printf ("Current System Time: %s\n", ctime (&now));
 
-  OSVERSIONINFOEX osversion;
-  osversion.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
-  if (!GetVersionEx (reinterpret_cast<LPOSVERSIONINFO>(&osversion)))
-    {
-      more_info = false;
-      osversion.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
-      if (!GetVersionEx (reinterpret_cast<LPOSVERSIONINFO>(&osversion)))
-       display_error ("dump_sysinfo: GetVersionEx()");
-    }
-
-  HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
+  RTL_OSVERSIONINFOEXW osversion;
+  osversion.dwOSVersionInfoSize = sizeof (RTL_OSVERSIONINFOEXW);
+  RtlGetVersion (&osversion);
 
   switch (osversion.dwPlatformId)
     {
-    case VER_PLATFORM_WIN32s:
-      strcpy (osname, "32s (not supported)");
-      break;
-    case VER_PLATFORM_WIN32_WINDOWS:
-      strcpy (osname, "95/98/Me (not supported)");
-      break;
     case VER_PLATFORM_WIN32_NT:
       is_nt = true;
-      if (osversion.dwMajorVersion == 6)
+      if (osversion.dwMajorVersion >= 6)
        {
+         HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
          BOOL (WINAPI *GetProductInfo) (DWORD, DWORD, DWORD, DWORD, PDWORD) =
                  (BOOL (WINAPI *)(DWORD, DWORD, DWORD, DWORD, PDWORD))
                  GetProcAddress (k32, "GetProductInfo");
-         switch (osversion.dwMinorVersion)
+         if (osversion.dwMajorVersion == 6)
+           switch (osversion.dwMinorVersion)
+             {
+             case 0:
+               strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+                               ? "Vista" : "2008");
+               break;
+             case 1:
+               strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+                               ? "7" : "2008 R2");
+               break;
+             case 2:
+               strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+                               ? "8" : "2012");
+               break;
+             case 3:
+               strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+                               ? "8.1" : "2012 R2");
+               break;
+             case 4:
+             default:
+               strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
+                               ? "10 Preview" : "2016 Preview");
+               break;
+             }
+         else if (osversion.dwMajorVersion == 10)
            {
-           case 0:
-             strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
-                             ? "Vista" : "2008");
-             break;
-           case 1:
              strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
-                             ? "7" : "2008 R2");
-             break;
-           default:
-             strcpy (osname, osversion.wProductType == VER_NT_WORKSTATION
-                             ? "8" : "2012");
-             break;
+                             ? "10" : "2016");
            }
          DWORD prod;
          if (GetProductInfo (osversion.dwMajorVersion,
@@ -1454,10 +1429,6 @@ dump_sysinfo ()
                              osversion.wServicePackMinor,
                              &prod))
            {
-#define       PRODUCT_UNLICENSED 0xabcdabcd
-#ifndef PRODUCT_PROFESSIONAL_WMC
-#define       PRODUCT_PROFESSIONAL_WMC 0x00000067
-#endif
              const char *products[] =
                {
  /* 0x00000000 */ "",
@@ -1491,7 +1462,7 @@ dump_sysinfo ()
  /* 0x0000001c */ " Ultimate N",
  /* 0x0000001d */ " Web Server Core",
  /* 0x0000001e */ " Essential Business Server Management Server",
- /* 0x0000001f */ " Essential Business Server Security Server"
+ /* 0x0000001f */ " Essential Business Server Security Server",
  /* 0x00000020 */ " Essential Business Server Messaging Server",
  /* 0x00000021 */ " Server Foundation",
  /* 0x00000022 */ " Home Server 2011",
@@ -1510,7 +1481,7 @@ dump_sysinfo ()
  /* 0x0000002f */ " Starter N",
  /* 0x00000030 */ " Professional",
  /* 0x00000031 */ " Professional N",
- /* 0x00000032 */ " Small Business Server 2011 Essentials"
+ /* 0x00000032 */ " Small Business Server 2011 Essentials",
  /* 0x00000033 */ " Server For SB Solutions",
  /* 0x00000034 */ " Server Solutions Premium",
  /* 0x00000035 */ " Server Solutions Premium Core",
@@ -1531,7 +1502,7 @@ dump_sysinfo ()
  /* 0x00000044 */ " Home Premium E",
  /* 0x00000045 */ " Professional E",
  /* 0x00000046 */ " Enterprise E",
- /* 0x00000047 */ " Ultimate E"
+ /* 0x00000047 */ " Ultimate E",
  /* 0x00000048 */ " Server Enterprise (Evaluation inst.)",
  /* 0x00000049 */ "",
  /* 0x0000004a */ "",
@@ -1558,16 +1529,46 @@ dump_sysinfo ()
  /* 0x0000005f */ " Storage Server Workgroup (Evaluation inst.)",
  /* 0x00000060 */ " Storage Server Standard (Evaluation inst.)",
  /* 0x00000061 */ "",
- /* 0x00000062 */ " N",                        /* "8 N" */
- /* 0x00000063 */ " China",            /* "8 China" */
- /* 0x00000064 */ " Single Language",  /* "8 Single Language" */
- /* 0x00000065 */ "",                  /* "8" */
+ /* 0x00000062 */ " N",
+ /* 0x00000063 */ " China",
+ /* 0x00000064 */ " Single Language",
+ /* 0x00000065 */ " Home",
  /* 0x00000066 */ "",
- /* 0x00000067 */ " Professional with Media Center"
+ /* 0x00000067 */ " Professional with Media Center",
+ /* 0x00000068 */ " Mobile",
+ /* 0x00000069 */ "",
+ /* 0x0000006a */ "",
+ /* 0x0000006b */ "",
+ /* 0x0000006c */ "",
+ /* 0x0000006d */ "",
+ /* 0x0000006e */ "",
+ /* 0x0000006f */ "",
+ /* 0x00000070 */ "",
+ /* 0x00000071 */ "",
+ /* 0x00000072 */ "",
+ /* 0x00000073 */ "",
+ /* 0x00000074 */ "",
+ /* 0x00000075 */ "",
+ /* 0x00000076 */ "",
+ /* 0x00000077 */ "",
+ /* 0x00000078 */ "",
+ /* 0x00000079 */ " Education",
+ /* 0x0000007a */ " Education N",
+ /* 0x0000007b */ "",
+ /* 0x0000007c */ "",
+ /* 0x0000007d */ "",
+ /* 0x0000007e */ "",
+ /* 0x0000007f */ "",
+ /* 0x00000080 */ "",
+ /* 0x00000081 */ "",
+ /* 0x00000082 */ "",
+ /* 0x00000083 */ "",
+ /* 0x00000084 */ "",
+ /* 0x00000085 */ " Mobile Enterprise",
                };
              if (prod == PRODUCT_UNLICENSED)
                strcat (osname, "Unlicensed");
-             else if (prod > PRODUCT_PROFESSIONAL_WMC)
+             else if (prod > 0x00000085)
                strcat (osname, "");
              else
                strcat (osname, products[prod]);
@@ -1576,64 +1577,6 @@ dump_sysinfo ()
            {
            }
        }
-      else if (osversion.dwMajorVersion == 5)
-       {
-         if (osversion.dwMinorVersion == 0)
-           {
-             strcpy (osname, "2000");
-             if (osversion.wProductType == VER_NT_WORKSTATION)
-               strcat (osname, " Professional");
-             else if (osversion.wSuiteMask & VER_SUITE_DATACENTER)
-               strcat (osname, " Datacenter Server");
-             else if (osversion.wSuiteMask & VER_SUITE_ENTERPRISE)
-               strcat (osname, " Advanced Server");
-             else
-               strcat (osname, " Server");
-           }
-         else if (osversion.dwMinorVersion == 1)
-           {
-             strcpy (osname, "XP");
-             if (GetSystemMetrics (SM_MEDIACENTER))
-               strcat (osname, " Media Center Edition");
-             else if (GetSystemMetrics (SM_TABLETPC))
-               strcat (osname, " Tablet PC Edition");
-             else if (GetSystemMetrics (SM_STARTER))
-               strcat (osname, " Starter Edition");
-             else if (osversion.wSuiteMask & VER_SUITE_PERSONAL)
-               strcat (osname, " Home Edition");
-             else
-               strcat (osname, " Professional");
-           }
-         else if (osversion.dwMinorVersion == 2)
-           {
-             strcpy (osname, "2003 Server");
-             if (GetSystemMetrics (SM_SERVERR2))
-               strcat (osname, " R2");
-             if (osversion.wSuiteMask & VER_SUITE_BLADE)
-               strcat (osname, " Web Edition");
-             else if (osversion.wSuiteMask & VER_SUITE_DATACENTER)
-               strcat (osname, " Datacenter Edition");
-             else if (osversion.wSuiteMask & VER_SUITE_ENTERPRISE)
-               strcat (osname, " Enterprise Edition");
-             else if (osversion.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
-               strcat (osname, " Compute Cluster Edition");
-           }
-       }
-      else if (osversion.dwMajorVersion == 4)
-       {
-         strcpy (osname, "NT 4");
-         if (more_info)
-           {
-             if (osversion.wProductType == VER_NT_WORKSTATION)
-               strcat (osname, " Workstation");
-             else
-               {
-                 strcat (osname, " Server");
-                 if (osversion.wSuiteMask & VER_SUITE_ENTERPRISE)
-                   strcat (osname, " Enterprise Edition");
-               }
-           }
-       }
       else
        strcpy (osname, "NT");
       break;
@@ -1641,26 +1584,22 @@ dump_sysinfo ()
       strcpy (osname, "??");
       break;
     }
-  printf ("Windows %s Ver %lu.%lu Build %lu %s\n", osname,
+  printf ("Windows %s Ver %lu.%lu Build %lu %ls\n", osname,
          osversion.dwMajorVersion, osversion.dwMinorVersion,
          osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
          osversion.dwBuildNumber : (osversion.dwBuildNumber & 0xffff),
          osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
-         osversion.szCSDVersion : "");
+         osversion.szCSDVersion : L"");
 
   if (osversion.dwPlatformId == VER_PLATFORM_WIN32s
       || osversion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
     exit (EXIT_FAILURE);
 
-  BOOL (WINAPI *wow64_func) (HANDLE, PBOOL) = (BOOL (WINAPI *) (HANDLE, PBOOL))
-    GetProcAddress (k32, "IsWow64Process");
   BOOL is_wow64 = FALSE;
-  if (wow64_func && wow64_func (GetCurrentProcess (), &is_wow64) && is_wow64)
+  if (IsWow64Process (GetCurrentProcess (), &is_wow64) && is_wow64)
     {
-      void (WINAPI *nativinfo) (LPSYSTEM_INFO) = (void (WINAPI *)
-       (LPSYSTEM_INFO)) GetProcAddress (k32, "GetNativeSystemInfo");
       SYSTEM_INFO natinfo;
-      nativinfo (&natinfo);
+      GetNativeSystemInfo (&natinfo);
       fputs ("\nRunning under WOW64 on ", stdout);
       switch (natinfo.wProcessorArchitecture)
        {
@@ -1691,7 +1630,7 @@ dump_sysinfo ()
        {
          for (e = s; *e && *e != sep; e++);
          if (e-s)
-           printf ("\t%.*s\n", e - s, s);
+           printf ("\t%.*s\n", (int) (e - s), s);
          else
            puts ("\t.");
          count_path_items++;
@@ -1796,10 +1735,6 @@ dump_sysinfo ()
     SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
   int drivemask = GetLogicalDrives ();
 
-  BOOL (WINAPI * gdfse) (LPCSTR, long long *, long long *, long long *) =
-    (BOOL (WINAPI *) (LPCSTR, long long *, long long *, long long *))
-    GetProcAddress (k32, "GetDiskFreeSpaceExA");
-
   for (i = 0; i < 26; i++)
     {
       if (!(drivemask & (1 << i)))
@@ -1849,11 +1784,14 @@ dump_sysinfo ()
       long capacity_mb = -1;
       int percent_full = -1;
 
-      long long free_me = 0ULL, free_bytes = 0ULL, total_bytes = 1ULL;
-      if (gdfse != NULL && gdfse (drive, &free_me, &total_bytes, &free_bytes))
+      ULARGE_INTEGER free_me, free_bytes, total_bytes;
+      free_me.QuadPart = free_bytes.QuadPart = 0ULL;
+      total_bytes.QuadPart = 1ULL;
+      if (GetDiskFreeSpaceEx (drive, &free_me, &total_bytes, &free_bytes))
        {
-         capacity_mb = total_bytes / (1024L * 1024L);
-         percent_full = 100 - (int) ((100.0 * free_me) / total_bytes);
+         capacity_mb = total_bytes.QuadPart / (1024L * 1024L);
+         percent_full = 100 - (int) ((100.0 * free_me.QuadPart)
+                                     / total_bytes.QuadPart);
        }
       else
        {
@@ -1870,20 +1808,14 @@ dump_sysinfo ()
        printf ("%7dMb %3d%% ", (int) capacity_mb, (int) percent_full);
       else
        printf ("    N/A    N/A ");
-      printf ("%s %s %s %s %s %s  %s\n",
+      printf ("%s %s %s %s %s %s %s  %s\n",
              flags & FS_CASE_IS_PRESERVED ? "CP" : "  ",
              flags & FS_CASE_SENSITIVE ? "CS" : "  ",
              flags & FS_UNICODE_STORED_ON_DISK ? "UN" : "  ",
              flags & FS_PERSISTENT_ACLS ? "PA" : "  ",
              flags & FS_FILE_COMPRESSION ? "FC" : "  ",
              flags & FS_VOL_IS_COMPRESSED ? "VC" : "  ",
-#if 0
-             flags & FILE_SUPPORTS_ENCRYPTION ? "EN" : "  ",
-             flags & FILE_SUPPORTS_OBJECT_IDS ? "OI" : "  ",
-             flags & FILE_SUPPORTS_REPARSE_POINTS ? "RP" : "  ",
-             flags & FILE_SUPPORTS_SPARSE_FILES ? "SP" : "  ",
              flags & FILE_VOLUME_QUOTAS ? "QU" : "  ",
-#endif
              name);
     }
 
@@ -2087,13 +2019,20 @@ check_keys ()
   return 0;
 }
 
-/* RFC1738 says that these do not need to be escaped.  */
-static const char safe_chars[] = "$-_.+!*'(),";
+/* These do not need to be escaped in application/x-www-form-urlencoded */
+static const char safe_chars[] = "$-_.!*'(),";
 
 /* the URL to query.  */
 static const char base_url[] =
        "http://cygwin.com/cgi-bin2/package-grep.cgi?text=1&grep=";
 
+#ifdef __x86_64__
+#define ARCH_STR  "&arch=x86_64"
+#else
+#define ARCH_STR  "&arch=x86"
+#endif
+static const char *ARCH_str = ARCH_STR;
+
 /* Queries Cygwin web site for packages containing files matching a regexp.
    Return value is 1 if there was a problem, otherwise 0.  */
 static int
@@ -2101,45 +2040,9 @@ package_grep (char *search)
 {
   char buf[1024];
 
-  /* Attempt to dynamically load the necessary WinInet API functions so that
-     cygcheck can still function on older systems without IE.  */
-  HMODULE hWinInet;
-  if (!(hWinInet = LoadLibrary ("wininet.dll")))
-    {
-      fputs ("Unable to locate WININET.DLL.  This feature requires Microsoft "
-            "Internet Explorer v3 or later to function.\n", stderr);
-      return 1;
-    }
-
-  /* InternetCloseHandle is used outside this function so it is declared
-     global.  The rest of these functions are only used here, so declare them
-     and call GetProcAddress for each of them with the following macro.  */
-
-  pInternetCloseHandle = (BOOL (WINAPI *) (HINTERNET))
-                           GetProcAddress (hWinInet, "InternetCloseHandle");
-#define make_func_pointer(name, ret, args) ret (WINAPI * p##name) args = \
-           (ret (WINAPI *) args) GetProcAddress (hWinInet, #name);
-  make_func_pointer (InternetAttemptConnect, DWORD, (DWORD));
-  make_func_pointer (InternetOpenA, HINTERNET, (LPCSTR, DWORD, LPCSTR, LPCSTR,
-                                               DWORD));
-  make_func_pointer (InternetOpenUrlA, HINTERNET, (HINTERNET, LPCSTR, LPCSTR,
-                                                  DWORD, DWORD, DWORD));
-  make_func_pointer (InternetReadFile, BOOL, (HINTERNET, PVOID, DWORD, PDWORD));
-  make_func_pointer (HttpQueryInfoA, BOOL, (HINTERNET, DWORD, PVOID, PDWORD,
-                                           PDWORD));
-#undef make_func_pointer
-
-  if(!pInternetCloseHandle || !pInternetAttemptConnect || !pInternetOpenA
-     || !pInternetOpenUrlA || !pInternetReadFile || !pHttpQueryInfoA)
-    {
-      fputs ("Unable to load one or more functions from WININET.DLL.  This "
-            "feature requires Microsoft Internet Explorer v3 or later to "
-            "function.\n", stderr);
-      return 1;
-    }
-
   /* construct the actual URL by escaping  */
-  char *url = (char *) alloca (sizeof (base_url) + strlen (search) * 3);
+  char *url = (char *) alloca (sizeof (base_url) + strlen (ARCH_str)
+                              + strlen (search) * 3);
   strcpy (url, base_url);
 
   char *dest;
@@ -2157,10 +2060,10 @@ package_grep (char *search)
          dest += 2;
        }
     }
-  *dest = 0;
+  strcpy (dest, ARCH_str);
 
   /* Connect to the net and open the URL.  */
-  if (pInternetAttemptConnect (0) != ERROR_SUCCESS)
+  if (InternetAttemptConnect (0) != ERROR_SUCCESS)
     {
       fputs ("An internet connection is required for this function.\n", stderr);
       return 1;
@@ -2168,16 +2071,17 @@ package_grep (char *search)
 
   /* Initialize WinInet and attempt to fetch our URL.  */
   HINTERNET hi = NULL, hurl = NULL;
-  if (!(hi = pInternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0)))
+  if (!(hi = InternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG,
+                           NULL, NULL, 0)))
     return display_internet_error ("InternetOpen() failed", NULL);
 
-  if (!(hurl = pInternetOpenUrlA (hi, url, NULL, 0, 0, 0)))
+  if (!(hurl = InternetOpenUrlA (hi, url, NULL, 0, 0, 0)))
     return display_internet_error ("unable to contact cygwin.com site, "
                                   "InternetOpenUrl() failed", hi, NULL);
 
   /* Check the HTTP response code.  */
   DWORD rc = 0, rc_s = sizeof (DWORD);
-  if (!pHttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
+  if (!HttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
                      (void *) &rc, &rc_s, NULL))
     return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL);
 
@@ -2192,19 +2096,19 @@ package_grep (char *search)
   DWORD numread;
   do
     {
-      if (!pInternetReadFile (hurl, (void *) buf, sizeof (buf), &numread))
+      if (!InternetReadFile (hurl, (void *) buf, sizeof (buf), &numread))
        return display_internet_error ("InternetReadFile failed", hurl, hi, NULL);
       if (numread)
        fwrite ((void *) buf, (size_t) numread, 1, stdout);
     }
   while (numread);
 
-  pInternetCloseHandle (hurl);
-  pInternetCloseHandle (hi);
+  InternetCloseHandle (hurl);
+  InternetCloseHandle (hi);
   return 0;
 }
 
-static void
+static void __attribute__ ((__noreturn__))
 usage (FILE * stream, int status)
 {
   fprintf (stream, "\
@@ -2216,9 +2120,6 @@ Usage: cygcheck [-v] [-h] PROGRAM\n\
        cygcheck -l [PACKAGE]...\n\
        cygcheck -p REGEXP\n\
        cygcheck --delete-orphaned-installation-keys\n\
-       cygcheck --enable-unique-object-names Cygwin-DLL\n\
-       cygcheck --disable-unique-object-names Cygwin-DLL\n\
-       cygcheck --show-unique-object-names Cygwin-DLL\n\
        cygcheck -h\n\n\
 List system information, check installed packages, or query package database.\n\
 \n\
@@ -2240,15 +2141,6 @@ At least one command option or a PROGRAM is required, as shown above.\n\
                       Delete installation keys of old, now unused\n\
                       installations from the registry.  Requires the right\n\
                       to change the registry.\n\
-  --enable-unique-object-names Cygwin-DLL\n\
-  --disable-unique-object-names Cygwin-DLL\n\
-  --show-unique-object-names Cygwin-DLL\n\
-                      Enable, disable, or show the setting of the\n\
-                      \"unique object names\" setting in the Cygwin DLL\n\
-                      given as argument to this option.  The DLL path must\n\
-                      be given as valid Windows(!) path.\n\
-                      See the users guide for more information.\n\
-                      If you don't know what this means, don't change it.\n\
   -v, --verbose        produce more verbose output\n\
   -h, --help           annotate output with explanatory comments when given\n\
                       with another command, otherwise print this help\n\
@@ -2272,9 +2164,6 @@ struct option longopts[] = {
   {"list-package", no_argument, NULL, 'l'},
   {"package-query", no_argument, NULL, 'p'},
   {"delete-orphaned-installation-keys", no_argument, NULL, CO_DELETE_KEYS},
-  {"enable-unique-object-names", no_argument, NULL, CO_ENABLE_UON},
-  {"disable-unique-object-names", no_argument, NULL, CO_DISABLE_UON},
-  {"show-unique-object-names", no_argument, NULL, CO_SHOW_UON},
   {"help", no_argument, NULL, 'h'},
   {"version", no_argument, 0, 'V'},
   {0, no_argument, NULL, 0}
@@ -2287,9 +2176,11 @@ print_version ()
 {
   printf ("cygcheck (cygwin) %d.%d.%d\n"
          "System Checker for Cygwin\n"
-         "Copyright (C) 1998 - %s Red Hat, Inc.\n"
-         "This is free software; see the source for copying conditions.  There is NO\n"
-         "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+         "Copyright (C) 1998 - %s Cygwin Authors\n"
+         "This is free software; see the source for copying conditions.  "
+         "There is NO\n"
+         "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR "
+         "PURPOSE.\n",
          CYGWIN_VERSION_DLL_MAJOR / 1000,
          CYGWIN_VERSION_DLL_MAJOR % 1000,
          CYGWIN_VERSION_DLL_MINOR,
@@ -2307,7 +2198,7 @@ nuke (char *ev)
 }
 
 extern "C" {
-unsigned long (*cygwin_internal) (int, ...);
+uintptr_t (*cygwin_internal) (int, ...);
 WCHAR cygwin_dll_path[32768];
 };
 
@@ -2319,12 +2210,14 @@ load_cygwin (int& argc, char **&argv)
   if (!(h = LoadLibrary ("cygwin1.dll")))
     return;
   GetModuleFileNameW (h, cygwin_dll_path, 32768);
-  if ((cygwin_internal = (DWORD (*) (int, ...)) GetProcAddress (h, "cygwin_internal")))
+  if ((cygwin_internal = (uintptr_t (*) (int, ...))
+                        GetProcAddress (h, "cygwin_internal")))
     {
       char **av = (char **) cygwin_internal (CW_ARGV);
-      if (av && ((DWORD) av != (DWORD) -1))
+      if (av && ((uintptr_t) av != (uintptr_t) -1))
        {
-         /* Copy cygwin's idea of the argument list into this Window application. */
+         /* Copy cygwin's idea of the argument list into this Window
+            application. */
          for (argc = 0; av[argc]; argc++)
            continue;
          argv = (char **) calloc (argc + 1, sizeof (char *));
@@ -2334,10 +2227,10 @@ load_cygwin (int& argc, char **&argv)
 
 
       char **envp = (char **) cygwin_internal (CW_ENVP);
-      if (envp && ((DWORD) envp != (DWORD) -1))
+      if (envp && ((uintptr_t) envp != (uintptr_t) -1))
        {
-         /* Store path and revert to this value, otherwise path gets overwritten
-            by the POSIXy Cygwin variation, which breaks cygcheck.
+         /* Store path and revert to this value, otherwise path gets
+            overwritten by the POSIXy Cygwin variation, which breaks cygcheck.
             Another approach would be to use the Cygwin PATH and convert it to
             Win32 again. */
          char *path = NULL;
@@ -2355,7 +2248,10 @@ load_cygwin (int& argc, char **&argv)
            putenv (path);
        }
     }
-  FreeLibrary (h);
+  /* GDB chokes when the DLL got unloaded and, for some reason, fails to set
+     any breakpoint after the fact. */
+  if (!IsDebuggerPresent ())
+    FreeLibrary (h);
 }
 
 int
@@ -2365,6 +2261,9 @@ main (int argc, char **argv)
   bool ok = true;
   load_cygwin (argc, argv);
 
+  _setmode (1, _O_BINARY);
+  _setmode (2, _O_BINARY);
+
   /* Need POSIX sorting while parsing args, but don't forget the
      user's original environment.  */
   char *posixly = getenv ("POSIXLY_CORRECT");
@@ -2406,11 +2305,6 @@ main (int argc, char **argv)
       case CO_DELETE_KEYS:
        del_orphaned_reg = 1;
        break;
-      case CO_ENABLE_UON:
-      case CO_DISABLE_UON:
-      case CO_SHOW_UON:
-       unique_object_name_opt = i;
-       break;
       case 'V':
        print_version ();
        exit (0);
@@ -2434,7 +2328,7 @@ main (int argc, char **argv)
     }
 
   if ((check_setup || sysinfo || find_package || list_package || grep_packages
-       || del_orphaned_reg || unique_object_name_opt)
+       || del_orphaned_reg)
       && keycheck)
     usage (stderr, 1);
 
@@ -2442,11 +2336,6 @@ main (int argc, char **argv)
       && (check_setup || del_orphaned_reg))
     usage (stderr, 1);
 
-  if ((check_setup || sysinfo || find_package || list_package || grep_packages
-       || del_orphaned_reg)
-      && unique_object_name_opt)
-    usage (stderr, 1);
-
   if (dump_only && !check_setup && !sysinfo)
     usage (stderr, 1);
 
@@ -2455,8 +2344,6 @@ main (int argc, char **argv)
 
   if (keycheck)
     return check_keys ();
-  if (unique_object_name_opt)
-    return handle_unique_object_name (unique_object_name_opt, *argv);
   if (del_orphaned_reg)
     del_orphaned_reg_installations ();
   if (grep_packages)
This page took 0.049288 seconds and 5 git commands to generate.