]> git.saurik.com Git - wxWidgets.git/blame - src/unix/stdpaths.cpp
Added missing arg
[wxWidgets.git] / src / unix / stdpaths.cpp
CommitLineData
c320b3e3
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: unix/stdpaths.cpp
a98ce49a 3// Purpose: wxStandardPaths implementation for Unix & OpenVMS systems
c320b3e3
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 2004-10-19
7// RCS-ID: $Id$
8// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9// License: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
07158944
VZ
27#if wxUSE_STDPATHS
28
ab9f9e71
PC
29#include "wx/stdpaths.h"
30
c320b3e3 31#ifndef WX_PRECOMP
ab9f9e71 32 #include "wx/utils.h"
c320b3e3
VZ
33#endif //WX_PRECOMP
34
35#include "wx/filename.h"
36
a98ce49a 37#if defined( __LINUX__ ) || defined( __VMS )
c320b3e3
VZ
38 #include <unistd.h>
39#endif
40
41// ============================================================================
d3b9c627 42// common VMS/Unix part of wxStandardPaths implementation
c320b3e3
VZ
43// ============================================================================
44
c320b3e3
VZ
45void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
46{
47 m_prefix = prefix;
48}
49
d3b9c627
VZ
50wxString wxStandardPaths::GetUserConfigDir() const
51{
52 return wxFileName::GetHomeDir();
53}
54
d3b9c627
VZ
55// ============================================================================
56// wxStandardPaths implementation for VMS
57// ============================================================================
58
59#ifdef __VMS
60
61wxString wxStandardPaths::GetInstallPrefix() const
62{
63 if ( m_prefix.empty() )
64 {
65 wx_const_cast(wxStandardPaths *, this)->m_prefix = wxT("/sys$system");
66 }
cc4d9903
VZ
67
68 return m_prefix;
d3b9c627
VZ
69}
70
71wxString wxStandardPaths::GetConfigDir() const
72{
73 return _T("/sys$manager");
74}
75
76wxString wxStandardPaths::GetDataDir() const
77{
78 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
79}
80
81wxString wxStandardPaths::GetLocalDataDir() const
82{
83 return AppendAppName(_T("/sys$manager"));
84}
85
86wxString wxStandardPaths::GetUserDataDir() const
87{
88 return wxFileName::GetHomeDir();
89}
90
cc4d9903
VZ
91wxString wxStandardPaths::GetPluginsDir() const
92{
93 return wxString(); // TODO: this is wrong, it should return something
94}
95
3af9f2de
VZ
96wxString
97wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
98 ResourceCat category) const
99{
100 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
101}
102
d3b9c627
VZ
103#else // !__VMS
104
105// ============================================================================
106// wxStandardPaths implementation for Unix
107// ============================================================================
108
ac7ad70d 109wxString wxStandardPaths::GetExecutablePath() const
c320b3e3 110{
3abcfa9b 111#ifdef __LINUX__
3abcfa9b
VZ
112 wxString exeStr;
113
114 char buf[4096];
115 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
116 if ( result != -1 )
c320b3e3 117 {
3abcfa9b 118 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
c320b3e3 119
3abcfa9b
VZ
120 // if the /proc/self/exe symlink has been dropped by the kernel for
121 // some reason, then readlink() could also return success but
122 // "(deleted)" as link destination...
123 if ( strcmp(buf, "(deleted)") != 0 )
124 exeStr = wxString(buf, wxConvLibc);
125 }
126
127 if ( exeStr.empty() )
128 {
129 // UPX-specific hack: when using UPX on linux, the kernel will drop the
130 // /proc/self/exe link; in this case we try to look for a special
131 // environment variable called " " which is created by UPX to save
132 // /proc/self/exe contents. See
133 // http://sf.net/tracker/?func=detail&atid=309863&aid=1565357&group_id=9863
134 // for more information about this issue.
135 wxGetEnv(wxT(" "), &exeStr);
136 }
137
ac7ad70d
RR
138 if ( !exeStr.empty() )
139 return exeStr;
140#endif // __LINUX__
141
142 return wxStandardPathsBase::GetExecutablePath();
143}
144
145void wxStandardPaths::DetectPrefix()
146{
147 // we can try to infer the prefix from the location of the executable
148 wxString exeStr = GetExecutablePath();
3abcfa9b
VZ
149 if ( !exeStr.empty() )
150 {
151 // consider that we're in the last "bin" subdirectory of our prefix
152 size_t pos = exeStr.rfind(wxT("/bin/"));
153 if ( pos != wxString::npos )
154 m_prefix.assign(exeStr, 0, pos);
155 }
74ebd406 156
3abcfa9b
VZ
157 if ( m_prefix.empty() )
158 {
159 m_prefix = wxT("/usr/local");
160 }
161}
162
163wxString wxStandardPaths::GetInstallPrefix() const
164{
165 if ( m_prefix.empty() )
166 {
167 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
168 pathPtr->DetectPrefix();
c320b3e3
VZ
169 }
170
171 return m_prefix;
172}
173
174// ----------------------------------------------------------------------------
175// public functions
176// ----------------------------------------------------------------------------
177
178wxString wxStandardPaths::GetConfigDir() const
179{
a98ce49a 180 return _T("/etc");
c320b3e3
VZ
181}
182
183wxString wxStandardPaths::GetDataDir() const
184{
a98ce49a 185 return AppendAppName(GetInstallPrefix() + _T("/share"));
c320b3e3
VZ
186}
187
188wxString wxStandardPaths::GetLocalDataDir() const
189{
a98ce49a 190 return AppendAppName(_T("/etc"));
c320b3e3
VZ
191}
192
193wxString wxStandardPaths::GetUserDataDir() const
194{
a98ce49a 195 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
c320b3e3
VZ
196}
197
cc4d9903
VZ
198wxString wxStandardPaths::GetPluginsDir() const
199{
200 return AppendAppName(GetInstallPrefix() + _T("/lib"));
201}
202
3af9f2de
VZ
203wxString
204wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
205 ResourceCat category) const
206{
207 if ( category != ResourceCat_Messages )
208 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
209
210 return GetInstallPrefix() + _T("/share/locale/") + lang + _T("/LC_MESSAGES");
211}
212
d3b9c627 213#endif // __VMS/!__VMS
c320b3e3 214
07158944 215#endif // wxUSE_STDPATHS