xpcom/base/nsSetDllDirectory.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/base/nsSetDllDirectory.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsSetDllDirectory_h
    1.10 +#define nsSetDllDirectory_h
    1.11 +
    1.12 +#ifndef XP_WIN
    1.13 +#error This file only makes sense on Windows.
    1.14 +#endif
    1.15 +
    1.16 +#include <windows.h>
    1.17 +#include <nscore.h>
    1.18 +#include <stdlib.h>
    1.19 +
    1.20 +namespace mozilla {
    1.21 +
    1.22 +static void SanitizeEnvironmentVariables()
    1.23 +{
    1.24 +  DWORD bufferSize = GetEnvironmentVariableW(L"PATH", nullptr, 0);
    1.25 +  if (bufferSize) {
    1.26 +    wchar_t* originalPath = new wchar_t[bufferSize];
    1.27 +    if (bufferSize - 1 == GetEnvironmentVariableW(L"PATH", originalPath, bufferSize)) {
    1.28 +      bufferSize = ExpandEnvironmentStringsW(originalPath, nullptr, 0);
    1.29 +      if (bufferSize) {
    1.30 +        wchar_t* newPath = new wchar_t[bufferSize];
    1.31 +        if (ExpandEnvironmentStringsW(originalPath,
    1.32 +                                      newPath,
    1.33 +                                      bufferSize)) {
    1.34 +          SetEnvironmentVariableW(L"PATH", newPath);
    1.35 +        }
    1.36 +        delete[] newPath;
    1.37 +      }
    1.38 +    }
    1.39 +    delete[] originalPath;
    1.40 +  }
    1.41 +}
    1.42 +
    1.43 +}
    1.44 +
    1.45 +#endif

mercurial