fixed compilation bug in prior checkin (Pt. 2)
[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 // wxStandardPaths implementation
43 // ============================================================================
44
45 // ----------------------------------------------------------------------------
46 // prefix management
47 // ----------------------------------------------------------------------------
48
49 void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
50 {
51 m_prefix = prefix;
52 }
53
54 wxString wxStandardPaths::GetInstallPrefix() const
55 {
56 if (m_prefix.empty())
57 {
58 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
59
60 #ifdef __LINUX__
61 // under Linux, we can get location of the executable
62 wxChar buf[4096];
63 int result;
64
65 // FIXME: is readlink() Unicode-aware or not???
66 result = readlink( (const char*)wxT("/proc/self/exe"), (char*)buf, WXSIZEOF(buf) - sizeof(wxChar) );
67 if (result != -1)
68 {
69 buf[result] = wxChar(0);
70 wxString exeStr( buf, wxConvLibc );
71
72 // consider that we're in the last "bin" subdirectory of our prefix
73 wxString basename( wxString(wxTheApp->argv[0]).AfterLast( wxChar('/')) );
74 size_t pos = exeStr.find( wxT("/bin/") + basename );
75 if (pos != wxString::npos)
76 pathPtr->m_prefix.assign( exeStr, 0, pos );
77 }
78 #endif // __LINUX__
79
80 if (m_prefix.empty())
81 {
82 #ifdef __VMS
83 pathPtr->m_prefix = wxT("/sys$system");
84 #else
85 pathPtr->m_prefix = wxT("/usr/local");
86 #endif
87 }
88 }
89
90 return m_prefix;
91 }
92
93 // ----------------------------------------------------------------------------
94 // public functions
95 // ----------------------------------------------------------------------------
96
97 wxString wxStandardPaths::GetConfigDir() const
98 {
99 #ifdef __VMS
100 return _T("/sys$manager");
101 #else
102 return _T("/etc");
103 #endif
104 }
105
106 wxString wxStandardPaths::GetUserConfigDir() const
107 {
108 return wxFileName::GetHomeDir();
109 }
110
111 wxString wxStandardPaths::GetDataDir() const
112 {
113 #ifdef __VMS
114 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
115 #else
116 return AppendAppName(GetInstallPrefix() + _T("/share"));
117 #endif
118 }
119
120 wxString wxStandardPaths::GetLocalDataDir() const
121 {
122 #ifdef __VMS
123 return AppendAppName(_T("/sys$manager"));
124 #else
125 return AppendAppName(_T("/etc"));
126 #endif
127 }
128
129 wxString wxStandardPaths::GetUserDataDir() const
130 {
131 #ifdef __VMS
132 return wxFileName::GetHomeDir();
133 #else
134 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
135 #endif
136 }
137
138 wxString wxStandardPaths::GetPluginsDir() const
139 {
140 return wxString();
141 }
142
143 #endif // wxUSE_STDPATHS