4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /* Include platform-specific files here */
31 /* Normal includes go here */
32 #include "file_utils.h"
33 #include "encoding_convert.h"
38 /* Tries to open the specified file. If successful, it'll read in its entire
39 contents into a wstring, and apply the specified conversion. */
40 int ReadEncodedFile(const char *filename
, wstring
& dest
,
41 const char *src_encoding
) {
42 ifstream
ifile(filename
, ios::in
| ios::binary
);
45 while(!ifile
.eof() && !ifile
.fail())
48 if(ifile
.fail()) return REF_FILE_OPEN_ERROR
;
50 dest
= ConvertString
<char, wchar_t>
51 (data
.str().c_str(), src_encoding
, wcType
.c_str());
54 } else return REF_FILE_NOT_FOUND
;
57 /* Platform-independent getcwd function. */
61 /* Yes, the size for the buffer used in
62 this function is maybe overkill. */
64 wchar_t *buffer
= new wchar_t[0x10000];
65 GetCurrentDirectoryW(0x10000, buffer
);
66 s
= utfconv_wm(buffer
);
68 char *buffer
= new char[0x10000];
69 if(getcwd(buffer
, 0x10000))
77 bool FileExists(const char *filename
) {