tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

version.c (2849B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "prio.h"
      7 #include "prprf.h"
      8 #include "prlink.h"
      9 #include "prvrsion.h"
     10 
     11 #include "plerror.h"
     12 #include "plgetopt.h"
     13 
     14 PR_IMPORT(const PRVersionDescription*) libVersionPoint(void);
     15 
     16 int main(int argc, char** argv) {
     17  PRIntn rv = 1;
     18  PLOptStatus os;
     19  PRIntn verbosity = 0;
     20  PRLibrary* runtime = NULL;
     21  const char* library_name = NULL;
     22  const PRVersionDescription* version_info;
     23  char buffer[100];
     24  PRExplodedTime exploded;
     25  PLOptState* opt = PL_CreateOptState(argc, argv, "d");
     26 
     27  PRFileDesc* err = PR_GetSpecialFD(PR_StandardError);
     28 
     29  while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) {
     30    if (PL_OPT_BAD == os) {
     31      continue;
     32    }
     33    switch (opt->option) {
     34      case 0: /* fully qualified library name */
     35        library_name = opt->value;
     36        break;
     37      case 'd': /* verbodity */
     38        verbosity += 1;
     39        break;
     40      default:
     41        PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
     42        return 2; /* but not a lot else */
     43    }
     44  }
     45  PL_DestroyOptState(opt);
     46 
     47  if (NULL != library_name) {
     48    runtime = PR_LoadLibrary(library_name);
     49    if (NULL == runtime) {
     50      PL_FPrintError(err, "PR_LoadLibrary");
     51      return 3;
     52    } else {
     53      versionEntryPointType versionPoint =
     54          (versionEntryPointType)PR_FindSymbol(runtime, "libVersionPoint");
     55      if (NULL == versionPoint) {
     56        PL_FPrintError(err, "PR_FindSymbol");
     57        return 4;
     58      }
     59      version_info = versionPoint();
     60    }
     61  } else {
     62    version_info = libVersionPoint(); /* NSPR's version info */
     63  }
     64 
     65  (void)PR_fprintf(err, "Runtime library version information\n");
     66  PR_ExplodeTime(version_info->buildTime, PR_GMTParameters, &exploded);
     67  (void)PR_FormatTime(buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
     68  (void)PR_fprintf(err, "  Build time: %s GMT\n", buffer);
     69  (void)PR_fprintf(err, "  Build time: %s\n", version_info->buildTimeString);
     70  (void)PR_fprintf(err, "  %s V%u.%u.%u (%s%s%s)\n", version_info->description,
     71                   version_info->vMajor, version_info->vMinor,
     72                   version_info->vPatch, (version_info->beta ? " beta " : ""),
     73                   (version_info->debug ? " debug " : ""),
     74                   (version_info->special ? " special" : ""));
     75  (void)PR_fprintf(err, "  filename: %s\n", version_info->filename);
     76  (void)PR_fprintf(err, "  security: %s\n", version_info->security);
     77  (void)PR_fprintf(err, "  copyright: %s\n", version_info->copyright);
     78  (void)PR_fprintf(err, "  comment: %s\n", version_info->comment);
     79  rv = 0;
     80  return rv;
     81 }
     82 
     83 /* version.c */