use one #ifdef __VMS instead of doing it in each and every function
[wxWidgets.git] / src / unix / stdpaths.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: unix/stdpaths.cpp
3 // Purpose: wxStandardPaths implementation for Unix & OpenVMS systems
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
27 #if wxUSE_STDPATHS
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #endif //WX_PRECOMP
32
33 #include "wx/filename.h"
34
35 #include "wx/stdpaths.h"
36
37 #if defined( __LINUX__ ) || defined( __VMS )
38 #include <unistd.h>
39 #endif
40
41 // ============================================================================
42 // common VMS/Unix part of wxStandardPaths implementation
43 // ============================================================================
44
45 void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
46 {
47 m_prefix = prefix;
48 }
49
50 wxString wxStandardPaths::GetUserConfigDir() const
51 {
52 return wxFileName::GetHomeDir();
53 }
54
55 wxString wxStandardPaths::GetPluginsDir() const
56 {
57 return wxString();
58 }
59
60 // ============================================================================
61 // wxStandardPaths implementation for VMS
62 // ============================================================================
63
64 #ifdef __VMS
65
66 wxString wxStandardPaths::GetInstallPrefix() const
67 {
68 if ( m_prefix.empty() )
69 {
70 wx_const_cast(wxStandardPaths *, this)->m_prefix = wxT("/sys$system");
71 }
72 }
73
74 wxString wxStandardPaths::GetConfigDir() const
75 {
76 return _T("/sys$manager");
77 }
78
79 wxString wxStandardPaths::GetDataDir() const
80 {
81 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
82 }
83
84 wxString wxStandardPaths::GetLocalDataDir() const
85 {
86 return AppendAppName(_T("/sys$manager"));
87 }
88
89 wxString wxStandardPaths::GetUserDataDir() const
90 {
91 return wxFileName::GetHomeDir();
92 }
93
94 #else // !__VMS
95
96 // ============================================================================
97 // wxStandardPaths implementation for Unix
98 // ============================================================================
99
100 wxString wxStandardPaths::GetInstallPrefix() const
101 {
102 if ( m_prefix.empty() )
103 {
104 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
105
106 #ifdef __LINUX__
107 // under Linux, we can try to infer the prefix from the location of the
108 // executable
109 char buf[4096];
110 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
111 if ( result != -1 )
112 {
113 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
114
115 const wxString exeStr(buf, wxConvLibc);
116
117 // consider that we're in the last "bin" subdirectory of our prefix
118 size_t pos = exeStr.rfind(wxT("/bin/"));
119 if ( pos != wxString::npos )
120 pathPtr->m_prefix.assign(exeStr, 0, pos);
121 }
122 #endif // __LINUX__
123
124 if ( m_prefix.empty() )
125 {
126 pathPtr->m_prefix = wxT("/usr/local");
127 }
128 }
129
130 return m_prefix;
131 }
132
133 // ----------------------------------------------------------------------------
134 // public functions
135 // ----------------------------------------------------------------------------
136
137 wxString wxStandardPaths::GetConfigDir() const
138 {
139 return _T("/etc");
140 }
141
142 wxString wxStandardPaths::GetDataDir() const
143 {
144 return AppendAppName(GetInstallPrefix() + _T("/share"));
145 }
146
147 wxString wxStandardPaths::GetLocalDataDir() const
148 {
149 return AppendAppName(_T("/etc"));
150 }
151
152 wxString wxStandardPaths::GetUserDataDir() const
153 {
154 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
155 }
156
157 #endif // __VMS/!__VMS
158
159 #endif // wxUSE_STDPATHS