Bug 1888033 - [Menu Redesign] Add a secret setting and feature flag for the menu...
[gecko.git] / toolkit / xre / CmdLineAndEnvUtils.cpp
blob634071bc9001e739c99f2e0df23f696ca5ff5f18
1 /* -*- Mode: C++; tab-width: 8; 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/. */
6 #include "nsCOMPtr.h"
7 #include "nsIFile.h"
8 #include "nsDependentString.h"
9 #include "prenv.h"
11 #ifdef XP_WIN
12 # include <windows.h>
13 #endif
15 namespace mozilla {
17 // Load the path of a file saved with SaveFileToEnv
18 already_AddRefed<nsIFile> GetFileFromEnv(const char* name) {
19 nsresult rv;
20 nsCOMPtr<nsIFile> file;
22 #ifdef XP_WIN
23 WCHAR path[_MAX_PATH];
24 if (!GetEnvironmentVariableW(NS_ConvertASCIItoUTF16(name).get(), path,
25 _MAX_PATH))
26 return nullptr;
28 rv = NS_NewLocalFile(nsDependentString(path), true, getter_AddRefs(file));
29 if (NS_FAILED(rv)) return nullptr;
31 return file.forget();
32 #else
33 const char* arg = PR_GetEnv(name);
34 if (!arg || !*arg) {
35 return nullptr;
38 rv = NS_NewNativeLocalFile(nsDependentCString(arg), true,
39 getter_AddRefs(file));
40 if (NS_FAILED(rv)) {
41 return nullptr;
44 return file.forget();
45 #endif
48 } // namespace mozilla