VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/io/SpecialSystemDirectory.cpp

最後變更 在這個檔案是 101962,由 vboxsync 提交於 13 月 前

libs/xpcom: Convert PR_GetEnv/PR_SetEnv to IPRT RTEnv* API, bugref:10545

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.8 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Doug Turner <[email protected]>
25 * IBM Corp.
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41#include "SpecialSystemDirectory.h"
42#include "nsString.h"
43#include "nsDependentString.h"
44
45
46#if defined(XP_UNIX)
47
48#include <unistd.h>
49#include <stdlib.h>
50#include <sys/param.h>
51# if defined(XP_MACOSX) && defined(VBOX_WITH_NEWER_OSX_SDK)
52# include <Folders.h>
53# endif
54
55#endif
56
57#include <iprt/env.h>
58
59NS_COM void StartupSpecialSystemDirectory()
60{
61}
62
63NS_COM void ShutdownSpecialSystemDirectory()
64{
65}
66
67
68nsresult
69GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
70 nsILocalFile** aFile)
71{
72 switch (aSystemSystemDirectory)
73 {
74 case OS_DriveDirectory:
75 return NS_NewNativeLocalFile(nsDependentCString("/"),
76 PR_TRUE,
77 aFile);
78 case OS_TemporaryDirectory:
79#if defined(XP_MACOSX)
80 {
81 return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
82 }
83
84#elif defined(XP_UNIX)
85 {
86 static const char *tPath = nsnull;
87 if (!tPath) {
88 tPath = RTEnvGet("TMPDIR");
89 if (!tPath || !*tPath) {
90 tPath = RTEnvGet("TMP");
91 if (!tPath || !*tPath) {
92 tPath = RTEnvGet("TEMP");
93 if (!tPath || !*tPath) {
94 tPath = "/tmp/";
95 }
96 }
97 }
98 }
99 return NS_NewNativeLocalFile(nsDependentCString(tPath),
100 PR_TRUE,
101 aFile);
102 }
103#else
104 break;
105#endif
106
107#if defined(XP_UNIX)
108 case Unix_LocalDirectory:
109 return NS_NewNativeLocalFile(nsDependentCString("/usr/local/netscape/"),
110 PR_TRUE,
111 aFile);
112 case Unix_LibDirectory:
113 return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"),
114 PR_TRUE,
115 aFile);
116
117 case Unix_HomeDirectory:
118 return NS_NewNativeLocalFile(nsDependentCString(RTEnvGet("HOME")),
119 PR_TRUE,
120 aFile);
121#endif
122 default:
123 break;
124 }
125 return NS_ERROR_NOT_AVAILABLE;
126}
127
128#if defined (XP_MACOSX)
129nsresult
130GetOSXFolderType(short aDomain, OSType aFolderType, nsILocalFile **localFile)
131{
132 OSErr err;
133 FSRef fsRef;
134 nsresult rv = NS_ERROR_FAILURE;
135
136 err = ::FSFindFolder(aDomain, aFolderType, kCreateFolder, &fsRef);
137 if (err == noErr)
138 {
139 NS_NewLocalFile(EmptyString(), PR_TRUE, localFile);
140 nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(*localFile));
141 if (localMacFile)
142 rv = localMacFile->InitWithFSRef(&fsRef);
143 }
144 return rv;
145}
146#endif
147
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette