"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/win32/win32os.c" (4 Sep 2020, 2969 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "win32os.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #include <windows.h>
   13 
   14 #ifndef TESTVERSION
   15 #include <isc/win32os.h>
   16 #else /* ifndef TESTVERSION */
   17 #include <stdio.h>
   18 
   19 #include <isc/util.h>
   20 #endif /* ifndef TESTVERSION */
   21 #include <isc/print.h>
   22 
   23 int
   24 isc_win32os_versioncheck(unsigned int major, unsigned int minor,
   25              unsigned int spmajor, unsigned int spminor) {
   26     OSVERSIONINFOEX osVer;
   27     DWORD typeMask;
   28     ULONGLONG conditionMask;
   29 
   30     memset(&osVer, 0, sizeof(OSVERSIONINFOEX));
   31     osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   32     typeMask = 0;
   33     conditionMask = 0;
   34 
   35     /* Optimistic: likely greater */
   36     osVer.dwMajorVersion = major;
   37     typeMask |= VER_MAJORVERSION;
   38     conditionMask = VerSetConditionMask(conditionMask, VER_MAJORVERSION,
   39                         VER_GREATER);
   40     osVer.dwMinorVersion = minor;
   41     typeMask |= VER_MINORVERSION;
   42     conditionMask = VerSetConditionMask(conditionMask, VER_MINORVERSION,
   43                         VER_GREATER);
   44     osVer.wServicePackMajor = spmajor;
   45     typeMask |= VER_SERVICEPACKMAJOR;
   46     conditionMask = VerSetConditionMask(conditionMask, VER_SERVICEPACKMAJOR,
   47                         VER_GREATER);
   48     osVer.wServicePackMinor = spminor;
   49     typeMask |= VER_SERVICEPACKMINOR;
   50     conditionMask = VerSetConditionMask(conditionMask, VER_SERVICEPACKMINOR,
   51                         VER_GREATER);
   52     if (VerifyVersionInfo(&osVer, typeMask, conditionMask)) {
   53         return (1);
   54     }
   55 
   56     /* Failed: retry with equal */
   57     conditionMask = 0;
   58     conditionMask = VerSetConditionMask(conditionMask, VER_MAJORVERSION,
   59                         VER_EQUAL);
   60     conditionMask = VerSetConditionMask(conditionMask, VER_MINORVERSION,
   61                         VER_EQUAL);
   62     conditionMask = VerSetConditionMask(conditionMask, VER_SERVICEPACKMAJOR,
   63                         VER_EQUAL);
   64     conditionMask = VerSetConditionMask(conditionMask, VER_SERVICEPACKMINOR,
   65                         VER_EQUAL);
   66     if (VerifyVersionInfo(&osVer, typeMask, conditionMask)) {
   67         return (0);
   68     } else {
   69         return (-1);
   70     }
   71 }
   72 
   73 #ifdef TESTVERSION
   74 int
   75 main(int argc, char **argv) {
   76     unsigned int major = 0;
   77     unsigned int minor = 0;
   78     unsigned int spmajor = 0;
   79     unsigned int spminor = 0;
   80     int ret;
   81 
   82     if (argc > 1) {
   83         --argc;
   84         ++argv;
   85         major = (unsigned int)atoi(argv[0]);
   86     }
   87     if (argc > 1) {
   88         --argc;
   89         ++argv;
   90         minor = (unsigned int)atoi(argv[0]);
   91     }
   92     if (argc > 1) {
   93         --argc;
   94         ++argv;
   95         spmajor = (unsigned int)atoi(argv[0]);
   96     }
   97     if (argc > 1) {
   98         --argc;
   99         POST(argc);
  100         ++argv;
  101         spminor = (unsigned int)atoi(argv[0]);
  102     }
  103 
  104     ret = isc_win32os_versioncheck(major, minor, spmajor, spminor);
  105 
  106     printf("%s major %u minor %u SP major %u SP minor %u\n",
  107            ret > 0 ? "greater" : (ret == 0 ? "equal" : "less"), major,
  108            minor, spmajor, spminor);
  109     return (ret);
  110 }
  111 #endif /* ifdef TESTVERSION */