removed wxMac stuff from here, unless I'm missing something this file is not used...
[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 try to infer the prefix from the location of the
62 // executable
63 char buf[4096];
64 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
65 if ( result != -1 )
66 {
67 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
68
69 const wxString exeStr(buf, wxConvLibc);
70
71 // consider that we're in the last "bin" subdirectory of our prefix
72 size_t pos = exeStr.rfind(wxT("/bin/"));
73 if ( pos != wxString::npos )
74 pathPtr->m_prefix.assign(exeStr, 0, pos);
75 }
76 #endif // __LINUX__
77
78 if ( m_prefix.empty() )
79 {
80 #ifdef __VMS
81 pathPtr->m_prefix = wxT("/sys$system");
82 #else
83 pathPtr->m_prefix = wxT("/usr/local");
84 #endif
85 }
86 }
87
88 return m_prefix;
89 }
90
91 // ----------------------------------------------------------------------------
92 // public functions
93 // ----------------------------------------------------------------------------
94
95 wxString wxStandardPaths::GetConfigDir() const
96 {
97 #ifdef __VMS
98 return _T("/sys$manager");
99 #else
100 return _T("/etc");
101 #endif
102 }
103
104 wxString wxStandardPaths::GetUserConfigDir() const
105 {
106 return wxFileName::GetHomeDir();
107 }
108
109 wxString wxStandardPaths::GetDataDir() const
110 {
111 #ifdef __VMS
112 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
113 #else
114 return AppendAppName(GetInstallPrefix() + _T("/share"));
115 #endif
116 }
117
118 wxString wxStandardPaths::GetLocalDataDir() const
119 {
120 #ifdef __VMS
121 return AppendAppName(_T("/sys$manager"));
122 #else
123 return AppendAppName(_T("/etc"));
124 #endif
125 }
126
127 wxString wxStandardPaths::GetUserDataDir() const
128 {
129 #ifdef __VMS
130 return wxFileName::GetHomeDir();
131 #else
132 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
133 #endif
134 }
135
136 wxString wxStandardPaths::GetPluginsDir() const
137 {
138 return wxString();
139 }
140
141 #endif // wxUSE_STDPATHS