]> git.saurik.com Git - wxWidgets.git/blame - src/unix/stdpaths.cpp
fixed obscure compilation problem at line 139
[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
c320b3e3
VZ
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
a98ce49a 37#if defined( __LINUX__ ) || defined( __VMS )
c320b3e3
VZ
38 #include <unistd.h>
39#endif
40
789e2d57
JS
41#if defined(__WXMAC__)
42 #include "wx/mac/private.h"
43#endif
44
c320b3e3
VZ
45// ============================================================================
46// wxStandardPaths implementation
47// ============================================================================
48
49// ----------------------------------------------------------------------------
50// prefix management
51// ----------------------------------------------------------------------------
52
53void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
54{
55 m_prefix = prefix;
56}
57
58wxString wxStandardPaths::GetInstallPrefix() const
59{
d5437b85 60 if ( m_prefix.empty() )
c320b3e3 61 {
74ebd406 62 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
c320b3e3
VZ
63
64#ifdef __LINUX__
d5437b85
VZ
65 // under Linux, we can try to infer the prefix from the location of the
66 // executable
67 char buf[4096];
68 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
69 if ( result != -1 )
c320b3e3 70 {
d5437b85
VZ
71 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
72
73 wxString exeStr(buf, wxConvLibc);
c39e7599 74
c320b3e3 75 // consider that we're in the last "bin" subdirectory of our prefix
d5437b85
VZ
76 wxString basename(wxString(wxTheApp->argv[0]).AfterLast(_T('/')));
77 size_t pos = exeStr.find(wxT("/bin/") + basename);
78 if ( pos != wxString::npos )
79 pathPtr->m_prefix.assign(exeStr, 0, pos);
c320b3e3 80 }
c320b3e3 81#endif // __LINUX__
74ebd406 82
d5437b85 83 if ( m_prefix.empty() )
c320b3e3 84 {
a98ce49a 85#ifdef __VMS
d5437b85 86 pathPtr->m_prefix = wxT("/sys$system");
a98ce49a 87#else
d5437b85 88 pathPtr->m_prefix = wxT("/usr/local");
a98ce49a 89#endif
c320b3e3
VZ
90 }
91 }
92
93 return m_prefix;
94}
95
96// ----------------------------------------------------------------------------
97// public functions
98// ----------------------------------------------------------------------------
99
100wxString wxStandardPaths::GetConfigDir() const
101{
a98ce49a
JJ
102#ifdef __VMS
103 return _T("/sys$manager");
104#else
105 return _T("/etc");
106#endif
c320b3e3
VZ
107}
108
109wxString wxStandardPaths::GetUserConfigDir() const
110{
111 return wxFileName::GetHomeDir();
112}
113
114wxString wxStandardPaths::GetDataDir() const
115{
a98ce49a
JJ
116#ifdef __VMS
117 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
118#else
119 return AppendAppName(GetInstallPrefix() + _T("/share"));
120#endif
c320b3e3
VZ
121}
122
123wxString wxStandardPaths::GetLocalDataDir() const
124{
a98ce49a
JJ
125#ifdef __VMS
126 return AppendAppName(_T("/sys$manager"));
127#else
128 return AppendAppName(_T("/etc"));
129#endif
c320b3e3
VZ
130}
131
132wxString wxStandardPaths::GetUserDataDir() const
133{
a98ce49a
JJ
134#ifdef __VMS
135 return wxFileName::GetHomeDir();
789e2d57
JS
136#elif defined(__WXMAC__)
137 return AppendAppName(wxMacFindFolder((short) kUserDomain, kApplicationSupportFolderType, kDontCreateFolder));
a98ce49a
JJ
138#else
139 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
140#endif
c320b3e3
VZ
141}
142
143wxString wxStandardPaths::GetPluginsDir() const
144{
145 return wxString();
146}
147
07158944 148#endif // wxUSE_STDPATHS