avrdude: Add a Windows-aware fopen
This commit is contained in:
parent
a2ce4c00de
commit
fba4d109c8
3 changed files with 11 additions and 5 deletions
|
@ -325,7 +325,7 @@ int read_config(const char * file)
|
|||
FILE * f;
|
||||
int r;
|
||||
|
||||
f = fopen(file, "r");
|
||||
f = fopen_utf8(file, "r");
|
||||
if (f == NULL) {
|
||||
avrdude_message(MSG_INFO, "%s: can't open config file \"%s\": %s\n",
|
||||
progname, file, strerror(errno));
|
||||
|
|
|
@ -102,9 +102,8 @@ static int fmt_autodetect(char * fname, unsigned section);
|
|||
|
||||
|
||||
|
||||
static FILE *fopen_and_seek(const char *filename, const char *mode, unsigned section)
|
||||
FILE *fopen_utf8(const char *filename, const char *mode)
|
||||
{
|
||||
FILE *file;
|
||||
// On Windows we need to convert the filename to UTF-16
|
||||
#if defined(WIN32NATIVE)
|
||||
static wchar_t fname_buffer[PATH_MAX];
|
||||
|
@ -113,10 +112,15 @@ static FILE *fopen_and_seek(const char *filename, const char *mode, unsigned sec
|
|||
if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, fname_buffer, PATH_MAX) == 0) { return NULL; }
|
||||
if (MultiByteToWideChar(CP_ACP, 0, mode, -1, mode_buffer, MAX_MODE_LEN) == 0) { return NULL; }
|
||||
|
||||
file = _wfopen(fname_buffer, mode_buffer);
|
||||
return _wfopen(fname_buffer, mode_buffer);
|
||||
#else
|
||||
file = fopen(filename, mode);
|
||||
return fopen(filename, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
static FILE *fopen_and_seek(const char *filename, const char *mode, unsigned section)
|
||||
{
|
||||
FILE *file = fopen_utf8(filename, mode);
|
||||
|
||||
if (file == NULL) {
|
||||
return NULL;
|
||||
|
|
|
@ -820,6 +820,8 @@ extern "C" {
|
|||
|
||||
char * fmtstr(FILEFMT format);
|
||||
|
||||
FILE *fopen_utf8(const char *filename, const char *mode);
|
||||
|
||||
int fileio(int op, char * filename, FILEFMT format,
|
||||
struct avrpart * p, char * memtype, int size, unsigned section);
|
||||
|
||||
|
|
Loading…
Reference in a new issue