nsprpub/pr/tests/version.c

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

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

mercurial