[46692] | 1 | /** $Id: VBoxReplaceDll.cpp 98106 2023-01-17 22:43:07Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[46694] | 3 | * VBoxReplaceDll - helper for replacing a dll when it's in use by the system
|
---|
[46692] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2013-2023 Oracle and/or its affiliates.
|
---|
[46692] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[46692] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
[57358] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[46692] | 32 | #define INCL_BASE
|
---|
| 33 | #include <os2.h>
|
---|
| 34 | #include <stdio.h>
|
---|
| 35 | #include <string.h>
|
---|
| 36 |
|
---|
[98106] | 37 | #include <VBox/version.h>
|
---|
[48942] | 38 |
|
---|
[98106] | 39 |
|
---|
[46692] | 40 | static int usage(const char *argv0)
|
---|
| 41 | {
|
---|
| 42 | char *psz1 = strrchr(argv0, '\\');
|
---|
| 43 | if (psz1)
|
---|
| 44 | argv0 = psz1 + 1;
|
---|
| 45 | psz1 = strrchr(argv0, '/');
|
---|
| 46 | if (psz1)
|
---|
| 47 | argv0 = psz1 + 1;
|
---|
| 48 | psz1 = strrchr(argv0, ':');
|
---|
| 49 | if (psz1)
|
---|
| 50 | argv0 = psz1 + 1;
|
---|
| 51 |
|
---|
| 52 | printf("Usage: %s <dll1> [dll2 ...[dllN]]\n"
|
---|
| 53 | "\n"
|
---|
| 54 | "Tells the kernel to cache the specified DLLs in memory and close the\n"
|
---|
| 55 | "files on disk, allowing new DLL versions to be installed.\n"
|
---|
| 56 | "\n"
|
---|
[98106] | 57 | "Copyright (C) 2013-" VBOX_C_YEAR " Oracle Corporation\n",
|
---|
[46692] | 58 | argv0);
|
---|
| 59 | return 0;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | int main(int argc, char **argv)
|
---|
| 63 | {
|
---|
| 64 | int fOptions = 1;
|
---|
| 65 | int cProcessed = 0;
|
---|
| 66 | int i;
|
---|
| 67 | for (i = 1; i < argc; i++)
|
---|
| 68 | {
|
---|
[48942] | 69 | if ( fOptions
|
---|
[46692] | 70 | && argv[i][0] == '-')
|
---|
| 71 | {
|
---|
| 72 | if (!strcmp(argv[i], "--"))
|
---|
| 73 | fOptions = 0;
|
---|
| 74 | else if ( !strcmp(argv[i], "--help")
|
---|
| 75 | || !strcmp(argv[i], "-help")
|
---|
| 76 | || !strcmp(argv[i], "-h")
|
---|
| 77 | || !strcmp(argv[i], "-?") )
|
---|
| 78 | return usage(argv[0]);
|
---|
| 79 | else if ( !strcmp(argv[i], "--version")
|
---|
| 80 | || !strcmp(argv[i], "-V") )
|
---|
| 81 | {
|
---|
| 82 | printf("$Revision: 98106 $\n");
|
---|
| 83 | return 0;
|
---|
| 84 | }
|
---|
| 85 | else
|
---|
| 86 | {
|
---|
| 87 | fprintf(stderr, "syntax error: Invalid option '%s'!\n", argv[i]);
|
---|
| 88 | return 2;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | else
|
---|
| 92 | {
|
---|
[48942] | 93 | /*
|
---|
[46692] | 94 | * Replace the specified DLL.
|
---|
| 95 | */
|
---|
| 96 | APIRET rc = DosReplaceModule((PCSZ)argv[i], NULL, NULL);
|
---|
| 97 | if (rc == NO_ERROR)
|
---|
| 98 | printf("info: Successfully cached '%s'.\n", argv[i]);
|
---|
| 99 | else
|
---|
| 100 | {
|
---|
[68585] | 101 | fprintf(stderr, "error: DosReplaceModule failed with rc=%lu on '%s'.\n", rc, argv[i]);
|
---|
[46692] | 102 | return 1;
|
---|
| 103 | }
|
---|
| 104 | cProcessed++;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | if (cProcessed == 0)
|
---|
| 109 | {
|
---|
| 110 | fprintf(stderr, "syntax error: No DLLs specified. (Consult --help for usage.)\n");
|
---|
| 111 | return 1;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | return 0;
|
---|
| 115 | }
|
---|
| 116 |
|
---|