6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync/** $Id$ */
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync/** @file
0d39579b024b5bdc9ec28616c9da099866766cdcvboxsync * VBoxReplaceDll - helper for replacing a dll when it's in use by the system
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync */
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync/*
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * Copyright (C) 2013 Oracle Corporation
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync *
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * available from http://www.virtualbox.org. This file is free software;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * you can redistribute it and/or modify it under the terms of the GNU
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * General Public License (GPL) as published by the Free Software
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync */
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync/*******************************************************************************
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync* Header Files *
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync*******************************************************************************/
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync#define INCL_BASE
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync#include <os2.h>
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync#include <stdio.h>
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync#include <string.h>
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
4d1226da58f42754f7b947e5ab65fb391de20946vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsyncstatic int usage(const char *argv0)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync{
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync char *psz1 = strrchr(argv0, '\\');
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync if (psz1)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync argv0 = psz1 + 1;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync psz1 = strrchr(argv0, '/');
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync if (psz1)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync argv0 = psz1 + 1;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync psz1 = strrchr(argv0, ':');
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync if (psz1)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync argv0 = psz1 + 1;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync printf("Usage: %s <dll1> [dll2 ...[dllN]]\n"
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync "\n"
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync "Tells the kernel to cache the specified DLLs in memory and close the\n"
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync "files on disk, allowing new DLL versions to be installed.\n"
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync "\n"
4d1226da58f42754f7b947e5ab65fb391de20946vboxsync "Copyright (C) 2013 Oracle Corporation\n",
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync argv0);
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync return 0;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync}
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsyncint main(int argc, char **argv)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync{
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync int fOptions = 1;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync int cProcessed = 0;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync int i;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync for (i = 1; i < argc; i++)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync {
4d1226da58f42754f7b947e5ab65fb391de20946vboxsync if ( fOptions
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync && argv[i][0] == '-')
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync {
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync if (!strcmp(argv[i], "--"))
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync fOptions = 0;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync else if ( !strcmp(argv[i], "--help")
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync || !strcmp(argv[i], "-help")
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync || !strcmp(argv[i], "-h")
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync || !strcmp(argv[i], "-?") )
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync return usage(argv[0]);
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync else if ( !strcmp(argv[i], "--version")
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync || !strcmp(argv[i], "-V") )
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync {
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync printf("$Revision$\n");
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync return 0;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync }
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync else
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync {
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync fprintf(stderr, "syntax error: Invalid option '%s'!\n", argv[i]);
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync return 2;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync }
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync }
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync else
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync {
4d1226da58f42754f7b947e5ab65fb391de20946vboxsync /*
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync * Replace the specified DLL.
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync */
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync APIRET rc = DosReplaceModule((PCSZ)argv[i], NULL, NULL);
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync if (rc == NO_ERROR)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync printf("info: Successfully cached '%s'.\n", argv[i]);
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync else
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync {
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync fprintf(stderr, "error: DosReplaceModule failed with rc=%u on '%s'.\n", rc, argv[i]);
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync return 1;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync }
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync cProcessed++;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync }
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync }
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync if (cProcessed == 0)
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync {
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync fprintf(stderr, "syntax error: No DLLs specified. (Consult --help for usage.)\n");
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync return 1;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync }
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync return 0;
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync}
6ebc06c9cd87d26f64680c2b58e6805b6b504728vboxsync