2018-11-16 00:31:39 +01:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
2011-03-20 23:53:39 +01:00
|
|
|
|
2010-09-25 19:35:19 +02:00
|
|
|
#ifndef _TFWOPEN_H
|
|
|
|
#define _TFWOPEN_H
|
|
|
|
|
2013-01-31 14:04:30 +01:00
|
|
|
#ifdef UNICODE
|
|
|
|
|
2010-09-25 19:35:19 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FILE *_tfwopen(const char *filename, const char *mode );
|
|
|
|
int _twremove(const char *filename );
|
2011-05-07 03:11:42 +02:00
|
|
|
int _twopen(const char *filename, int oflag, int pmode);
|
2019-01-15 23:23:39 +01:00
|
|
|
char *_twfullpath(char* dst, const char* src, int len);
|
2010-09-25 19:35:19 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-31 14:04:30 +01:00
|
|
|
#endif // UNICODE
|
|
|
|
|
2010-09-25 19:35:19 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
class Utf8ToWide {
|
|
|
|
private:
|
|
|
|
wchar_t *wideChars;
|
|
|
|
public:
|
|
|
|
Utf8ToWide(const char *utf8Chars);
|
|
|
|
~Utf8ToWide() { delete [] wideChars; }
|
|
|
|
operator wchar_t *() { return wideChars; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class WideToUtf8 {
|
|
|
|
private:
|
|
|
|
char *utf8Chars;
|
|
|
|
public:
|
|
|
|
WideToUtf8(const wchar_t *wideChars);
|
|
|
|
~WideToUtf8() { delete [] utf8Chars; }
|
|
|
|
operator char *() { return utf8Chars; }
|
|
|
|
};
|
|
|
|
|
2012-10-18 15:44:42 +02:00
|
|
|
class CPToWide {
|
2012-07-22 14:57:35 +02:00
|
|
|
private:
|
|
|
|
wchar_t *wideChars;
|
|
|
|
public:
|
2012-10-18 15:44:42 +02:00
|
|
|
CPToWide(const char *chars, unsigned int cp);
|
|
|
|
~CPToWide() { delete [] wideChars; }
|
2012-07-22 14:57:35 +02:00
|
|
|
operator wchar_t *() { return wideChars; }
|
|
|
|
};
|
|
|
|
|
2012-10-18 15:44:42 +02:00
|
|
|
class WideToCP {
|
|
|
|
private:
|
|
|
|
char *cpchars;
|
|
|
|
public:
|
|
|
|
WideToCP(const wchar_t *wideChars, unsigned int cp);
|
|
|
|
~WideToCP() { delete [] cpchars; }
|
|
|
|
operator char *() { return cpchars; }
|
|
|
|
};
|
|
|
|
|
2013-01-31 14:04:30 +01:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
#ifdef UNICODE
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <fstream>
|
|
|
|
|
2010-09-25 19:35:19 +02:00
|
|
|
namespace std {
|
|
|
|
class u8nifstream: public std::ifstream
|
|
|
|
{
|
|
|
|
public:
|
2023-01-27 00:06:45 +01:00
|
|
|
void __CLR_OR_THIS_CALL open(const char *_Filename, ios_base::openmode _Mode)
|
2010-09-25 19:35:19 +02:00
|
|
|
{
|
|
|
|
std::ifstream::open(Utf8ToWide(_Filename), (ios_base::openmode)_Mode);
|
|
|
|
}
|
|
|
|
|
2023-01-27 00:06:45 +01:00
|
|
|
void __CLR_OR_THIS_CALL open(const wchar_t *_Filename, ios_base::openmode _Mode)
|
2010-09-25 19:35:19 +02:00
|
|
|
{
|
|
|
|
std::ifstream::open(_Filename, (ios_base::openmode)_Mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
__CLR_OR_THIS_CALL u8nifstream()
|
|
|
|
: std::ifstream() {}
|
|
|
|
|
|
|
|
explicit __CLR_OR_THIS_CALL u8nifstream(const char *_Filename,
|
|
|
|
ios_base::openmode _Mode = ios_base::in,
|
|
|
|
int _Prot = (int)ios_base::_Openprot)
|
|
|
|
: std::ifstream(Utf8ToWide(_Filename),_Mode) {}
|
|
|
|
|
|
|
|
explicit __CLR_OR_THIS_CALL u8nifstream(const wchar_t *_Filename,
|
|
|
|
ios_base::openmode _Mode = ios_base::in,
|
|
|
|
int _Prot = (int)ios_base::_Openprot)
|
|
|
|
: std::ifstream(_Filename,_Mode,_Prot) {}
|
|
|
|
|
|
|
|
#ifdef _NATIVE_WCHAR_T_DEFINED
|
|
|
|
explicit __CLR_OR_THIS_CALL u8nifstream(const unsigned short *_Filename,
|
|
|
|
ios_base::openmode _Mode = ios_base::in,
|
|
|
|
int _Prot = (int)ios_base::_Openprot)
|
|
|
|
: std::ifstream(_Filename,_Mode,_Prot) {}
|
|
|
|
#endif /* _NATIVE_WCHAR_T_DEFINED */
|
|
|
|
|
2018-08-15 13:22:32 +02:00
|
|
|
explicit __CLR_OR_THIS_CALL u8nifstream(FILE *_File)
|
2010-09-25 19:35:19 +02:00
|
|
|
: std::ifstream(_File) {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#define ifstream u8nifstream
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
#define fopen _tfwopen
|
2011-05-07 03:11:42 +02:00
|
|
|
#undef remove
|
2012-07-30 19:48:21 +02:00
|
|
|
__forceinline static int remove(const char *filename) {
|
2011-05-07 03:11:42 +02:00
|
|
|
return _twremove(filename);
|
|
|
|
}
|
|
|
|
#undef open
|
2012-07-30 19:48:21 +02:00
|
|
|
__forceinline static int open(const char *filename, int oflag, int pmode) {
|
2011-05-07 03:11:42 +02:00
|
|
|
return _twopen(filename, oflag, pmode);
|
|
|
|
}
|
2010-09-25 19:35:19 +02:00
|
|
|
|
2013-01-31 14:04:30 +01:00
|
|
|
#endif // UNICODE
|
|
|
|
|
2018-11-16 00:31:39 +01:00
|
|
|
#endif // _TFWOPEN_H
|