diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llfile.cpp | 88 |
1 files changed, 68 insertions, 20 deletions
diff --git a/linden/indra/llcommon/llfile.cpp b/linden/indra/llcommon/llfile.cpp index fc0d481..b32437f 100644 --- a/linden/indra/llcommon/llfile.cpp +++ b/linden/indra/llcommon/llfile.cpp | |||
@@ -32,6 +32,10 @@ | |||
32 | * $/LicenseInfo$ | 32 | * $/LicenseInfo$ |
33 | */ | 33 | */ |
34 | 34 | ||
35 | #if LL_WINDOWS | ||
36 | #include <windows.h> | ||
37 | #endif | ||
38 | |||
35 | #include "linden_common.h" | 39 | #include "linden_common.h" |
36 | #include "llfile.h" | 40 | #include "llfile.h" |
37 | #include "llstring.h" | 41 | #include "llstring.h" |
@@ -40,7 +44,7 @@ | |||
40 | using namespace std; | 44 | using namespace std; |
41 | 45 | ||
42 | // static | 46 | // static |
43 | int LLFile::mkdir(const char* dirname, int perms) | 47 | int LLFile::mkdir(const std::string& dirname, int perms) |
44 | { | 48 | { |
45 | #if LL_WINDOWS | 49 | #if LL_WINDOWS |
46 | // permissions are ignored on Windows | 50 | // permissions are ignored on Windows |
@@ -48,12 +52,12 @@ int LLFile::mkdir(const char* dirname, int perms) | |||
48 | llutf16string utf16dirname = utf8str_to_utf16str(utf8dirname); | 52 | llutf16string utf16dirname = utf8str_to_utf16str(utf8dirname); |
49 | return _wmkdir(utf16dirname.c_str()); | 53 | return _wmkdir(utf16dirname.c_str()); |
50 | #else | 54 | #else |
51 | return ::mkdir(dirname, (mode_t)perms); | 55 | return ::mkdir(dirname.c_str(), (mode_t)perms); |
52 | #endif | 56 | #endif |
53 | } | 57 | } |
54 | 58 | ||
55 | // static | 59 | // static |
56 | int LLFile::rmdir(const char* dirname) | 60 | int LLFile::rmdir(const std::string& dirname) |
57 | { | 61 | { |
58 | #if LL_WINDOWS | 62 | #if LL_WINDOWS |
59 | // permissions are ignored on Windows | 63 | // permissions are ignored on Windows |
@@ -61,29 +65,29 @@ int LLFile::rmdir(const char* dirname) | |||
61 | llutf16string utf16dirname = utf8str_to_utf16str(utf8dirname); | 65 | llutf16string utf16dirname = utf8str_to_utf16str(utf8dirname); |
62 | return _wrmdir(utf16dirname.c_str()); | 66 | return _wrmdir(utf16dirname.c_str()); |
63 | #else | 67 | #else |
64 | return ::rmdir(dirname); | 68 | return ::rmdir(dirname.c_str()); |
65 | #endif | 69 | #endif |
66 | } | 70 | } |
67 | 71 | ||
68 | // static | 72 | // static |
69 | LLFILE* LLFile::fopen(const char* filename, const char* mode) /* Flawfinder: ignore */ | 73 | LLFILE* LLFile::fopen(const std::string& filename, const char* mode) /* Flawfinder: ignore */ |
70 | { | 74 | { |
71 | #if LL_WINDOWS | 75 | #if LL_WINDOWS |
72 | std::string utf8filename = filename; | 76 | std::string utf8filename = filename; |
73 | std::string utf8mode = mode; | 77 | std::string utf8mode = std::string(mode); |
74 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); | 78 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); |
75 | llutf16string utf16mode = utf8str_to_utf16str(utf8mode); | 79 | llutf16string utf16mode = utf8str_to_utf16str(utf8mode); |
76 | return _wfopen(utf16filename.c_str(),utf16mode.c_str()); | 80 | return _wfopen(utf16filename.c_str(),utf16mode.c_str()); |
77 | #else | 81 | #else |
78 | return ::fopen(filename,mode); /* Flawfinder: ignore */ | 82 | return ::fopen(filename.c_str(),mode); /* Flawfinder: ignore */ |
79 | #endif | 83 | #endif |
80 | } | 84 | } |
81 | 85 | ||
82 | LLFILE* LLFile::_fsopen(const char* filename, const char* mode, int sharingFlag) | 86 | LLFILE* LLFile::_fsopen(const std::string& filename, const char* mode, int sharingFlag) |
83 | { | 87 | { |
84 | #if LL_WINDOWS | 88 | #if LL_WINDOWS |
85 | std::string utf8filename = filename; | 89 | std::string utf8filename = filename; |
86 | std::string utf8mode = mode; | 90 | std::string utf8mode = std::string(mode); |
87 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); | 91 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); |
88 | llutf16string utf16mode = utf8str_to_utf16str(utf8mode); | 92 | llutf16string utf16mode = utf8str_to_utf16str(utf8mode); |
89 | return _wfsopen(utf16filename.c_str(),utf16mode.c_str(),sharingFlag); | 93 | return _wfsopen(utf16filename.c_str(),utf16mode.c_str(),sharingFlag); |
@@ -93,18 +97,18 @@ LLFILE* LLFile::_fsopen(const char* filename, const char* mode, int sharingFlag) | |||
93 | #endif | 97 | #endif |
94 | } | 98 | } |
95 | 99 | ||
96 | int LLFile::remove(const char* filename) | 100 | int LLFile::remove(const std::string& filename) |
97 | { | 101 | { |
98 | #if LL_WINDOWS | 102 | #if LL_WINDOWS |
99 | std::string utf8filename = filename; | 103 | std::string utf8filename = filename; |
100 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); | 104 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); |
101 | return _wremove(utf16filename.c_str()); | 105 | return _wremove(utf16filename.c_str()); |
102 | #else | 106 | #else |
103 | return ::remove(filename); | 107 | return ::remove(filename.c_str()); |
104 | #endif | 108 | #endif |
105 | } | 109 | } |
106 | 110 | ||
107 | int LLFile::rename(const char* filename, const char* newname) | 111 | int LLFile::rename(const std::string& filename, const std::string& newname) |
108 | { | 112 | { |
109 | #if LL_WINDOWS | 113 | #if LL_WINDOWS |
110 | std::string utf8filename = filename; | 114 | std::string utf8filename = filename; |
@@ -113,19 +117,63 @@ int LLFile::rename(const char* filename, const char* newname) | |||
113 | llutf16string utf16newname = utf8str_to_utf16str(utf8newname); | 117 | llutf16string utf16newname = utf8str_to_utf16str(utf8newname); |
114 | return _wrename(utf16filename.c_str(),utf16newname.c_str()); | 118 | return _wrename(utf16filename.c_str(),utf16newname.c_str()); |
115 | #else | 119 | #else |
116 | return ::rename(filename,newname); | 120 | return ::rename(filename.c_str(),newname.c_str()); |
117 | #endif | 121 | #endif |
118 | } | 122 | } |
119 | 123 | ||
120 | int LLFile::stat(const char* filename, llstat* filestatus) | 124 | int LLFile::stat(const std::string& filename, llstat* filestatus) |
121 | { | 125 | { |
122 | #if LL_WINDOWS | 126 | #if LL_WINDOWS |
123 | std::string utf8filename = filename; | 127 | std::string utf8filename = filename; |
124 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); | 128 | llutf16string utf16filename = utf8str_to_utf16str(utf8filename); |
125 | return _wstat(utf16filename.c_str(),filestatus); | 129 | return _wstat(utf16filename.c_str(),filestatus); |
126 | #else | 130 | #else |
127 | return ::stat(filename,filestatus); | 131 | return ::stat(filename.c_str(),filestatus); |
132 | #endif | ||
133 | } | ||
134 | |||
135 | bool LLFile::isdir(const std::string& filename) | ||
136 | { | ||
137 | llstat st; | ||
138 | |||
139 | return stat(filename, &st) == 0 && S_ISDIR(st.st_mode); | ||
140 | } | ||
141 | |||
142 | bool LLFile::isfile(const std::string& filename) | ||
143 | { | ||
144 | llstat st; | ||
145 | |||
146 | return stat(filename, &st) == 0 && S_ISREG(st.st_mode); | ||
147 | } | ||
148 | |||
149 | const char *LLFile::tmpdir() | ||
150 | { | ||
151 | static std::string utf8path; | ||
152 | |||
153 | if (utf8path.empty()) | ||
154 | { | ||
155 | char sep; | ||
156 | #if LL_WINDOWS | ||
157 | sep = '\\'; | ||
158 | |||
159 | DWORD len = GetTempPathW(0, L""); | ||
160 | llutf16string utf16path; | ||
161 | utf16path.resize(len + 1); | ||
162 | len = GetTempPathW(static_cast<DWORD>(utf16path.size()), &utf16path[0]); | ||
163 | utf8path = utf16str_to_utf8str(utf16path); | ||
164 | #else | ||
165 | sep = '/'; | ||
166 | |||
167 | char *env = getenv("TMPDIR"); | ||
168 | |||
169 | utf8path = env ? env : "/tmp/"; | ||
128 | #endif | 170 | #endif |
171 | if (utf8path[utf8path.size() - 1] != sep) | ||
172 | { | ||
173 | utf8path += sep; | ||
174 | } | ||
175 | } | ||
176 | return utf8path.c_str(); | ||
129 | } | 177 | } |
130 | 178 | ||
131 | 179 | ||
@@ -133,7 +181,7 @@ int LLFile::stat(const char* filename, llstat* filestatus) | |||
133 | 181 | ||
134 | #if USE_LLFILESTREAMS | 182 | #if USE_LLFILESTREAMS |
135 | 183 | ||
136 | LLFILE * LLFile::_Fiopen(const char *filename, std::ios::openmode mode,int) // protection currently unused | 184 | LLFILE * LLFile::_Fiopen(const std::string& filename, std::ios::openmode mode,int) // protection currently unused |
137 | { // open a file | 185 | { // open a file |
138 | static const char *mods[] = | 186 | static const char *mods[] = |
139 | { // fopen mode strings corresponding to valid[i] | 187 | { // fopen mode strings corresponding to valid[i] |
@@ -202,7 +250,7 @@ void llifstream::close() | |||
202 | } | 250 | } |
203 | } | 251 | } |
204 | 252 | ||
205 | void llifstream::open(const char* _Filename, /* Flawfinder: ignore */ | 253 | void llifstream::open(const std::string& _Filename, /* Flawfinder: ignore */ |
206 | ios_base::openmode _Mode, | 254 | ios_base::openmode _Mode, |
207 | int _Prot) | 255 | int _Prot) |
208 | { // open a C stream with specified mode | 256 | { // open a C stream with specified mode |
@@ -234,7 +282,7 @@ llifstream::~llifstream() | |||
234 | delete _Filebuffer; | 282 | delete _Filebuffer; |
235 | } | 283 | } |
236 | 284 | ||
237 | llifstream::llifstream(const char *_Filename, | 285 | llifstream::llifstream(const std::string& _Filename, |
238 | ios_base::openmode _Mode, | 286 | ios_base::openmode _Mode, |
239 | int _Prot) | 287 | int _Prot) |
240 | : std::basic_istream< char , std::char_traits< char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false) | 288 | : std::basic_istream< char , std::char_traits< char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false) |
@@ -253,7 +301,7 @@ bool llofstream::is_open() const | |||
253 | return false; | 301 | return false; |
254 | } | 302 | } |
255 | 303 | ||
256 | void llofstream::open(const char* _Filename, /* Flawfinder: ignore */ | 304 | void llofstream::open(const std::string& _Filename, /* Flawfinder: ignore */ |
257 | ios_base::openmode _Mode, | 305 | ios_base::openmode _Mode, |
258 | int _Prot) | 306 | int _Prot) |
259 | { // open a C stream with specified mode | 307 | { // open a C stream with specified mode |
@@ -279,7 +327,7 @@ void llofstream::close() | |||
279 | } | 327 | } |
280 | } | 328 | } |
281 | 329 | ||
282 | llofstream::llofstream(const char *_Filename, | 330 | llofstream::llofstream(const std::string& _Filename, |
283 | std::ios_base::openmode _Mode, | 331 | std::ios_base::openmode _Mode, |
284 | int _Prot) | 332 | int _Prot) |
285 | : std::basic_ostream<char,std::char_traits < char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false) | 333 | : std::basic_ostream<char,std::char_traits < char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false) |