VirtualBox

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

Last change on this file since 101866 was 101866, checked in by vboxsync, 16 months ago

libs/xpcom: Cleanup nsDirectoryService.cpp and SpecialSystemDirectory.{cpp,h} to include stuff we actually care for, bugref:10545

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
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 <dougt@netscape.com>
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#include "prenv.h"
52# if defined(XP_MACOSX) && defined(VBOX_WITH_NEWER_OSX_SDK)
53# include <Folders.h>
54# endif
55
56#endif
57
58NS_COM void StartupSpecialSystemDirectory()
59{
60}
61
62NS_COM void ShutdownSpecialSystemDirectory()
63{
64}
65
66
67nsresult
68GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
69 nsILocalFile** aFile)
70{
71 switch (aSystemSystemDirectory)
72 {
73 case OS_DriveDirectory:
74 return NS_NewNativeLocalFile(nsDependentCString("/"),
75 PR_TRUE,
76 aFile);
77 case OS_TemporaryDirectory:
78#if defined(XP_MACOSX)
79 {
80 return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
81 }
82
83#elif defined(XP_UNIX)
84 {
85 static const char *tPath = nsnull;
86 if (!tPath) {
87 tPath = PR_GetEnv("TMPDIR");
88 if (!tPath || !*tPath) {
89 tPath = PR_GetEnv("TMP");
90 if (!tPath || !*tPath) {
91 tPath = PR_GetEnv("TEMP");
92 if (!tPath || !*tPath) {
93 tPath = "/tmp/";
94 }
95 }
96 }
97 }
98 return NS_NewNativeLocalFile(nsDependentCString(tPath),
99 PR_TRUE,
100 aFile);
101 }
102#else
103 break;
104#endif
105
106#if defined(XP_UNIX)
107 case Unix_LocalDirectory:
108 return NS_NewNativeLocalFile(nsDependentCString("/usr/local/netscape/"),
109 PR_TRUE,
110 aFile);
111 case Unix_LibDirectory:
112 return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"),
113 PR_TRUE,
114 aFile);
115
116 case Unix_HomeDirectory:
117 return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")),
118 PR_TRUE,
119 aFile);
120#endif
121 default:
122 break;
123 }
124 return NS_ERROR_NOT_AVAILABLE;
125}
126
127#if defined (XP_MACOSX)
128nsresult
129GetOSXFolderType(short aDomain, OSType aFolderType, nsILocalFile **localFile)
130{
131 OSErr err;
132 FSRef fsRef;
133 nsresult rv = NS_ERROR_FAILURE;
134
135 err = ::FSFindFolder(aDomain, aFolderType, kCreateFolder, &fsRef);
136 if (err == noErr)
137 {
138 NS_NewLocalFile(EmptyString(), PR_TRUE, localFile);
139 nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(*localFile));
140 if (localMacFile)
141 rv = localMacFile->InitWithFSRef(&fsRef);
142 }
143 return rv;
144}
145#endif
146
Note: See TracBrowser for help on using the repository browser.

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