diff --git a/src/avrdude/config.c b/src/avrdude/config.c index 08193cfc5..558700547 100644 --- a/src/avrdude/config.c +++ b/src/avrdude/config.c @@ -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)); diff --git a/src/avrdude/fileio.c b/src/avrdude/fileio.c index 708159295..dcd0d6a66 100644 --- a/src/avrdude/fileio.c +++ b/src/avrdude/fileio.c @@ -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; diff --git a/src/avrdude/libavrdude.h b/src/avrdude/libavrdude.h index aef792476..69c17ea7b 100644 --- a/src/avrdude/libavrdude.h +++ b/src/avrdude/libavrdude.h @@ -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);