[FFmpeg-devel] [PATCH v2 1/2] avutil/wchar_filename, file_open: Support long file names on Windows
nil-admirari at mailo.com
nil-admirari at mailo.com
Tue May 17 18:06:52 EEST 2022
> stat wasn't already defined as win32_stat.
> win32_stat was already defined but not mapped. That's what my change
> does.
There are two defines in os_support.h:
# ifdef stat
# undef stat
# endif
# define stat _stati64
and
DEF_FS_FUNCTION2(stat, _wstati64, _stati64, struct stat*)
which defines win32_stat (not stat). This function takes struct stat*, which due to previous define
expands into struct _stati64*.
_stati64 and _wstati64 both take struct _stati64*, which is named identically to the first function.
struct _stati64 expands into different structs depending on the value of _USE_32BIT_TIME_T,
which your explicit structure definition does not capture, see:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=msvc-170.
If someone defines_USE_32BIT_TIME_T, your code will fail to compile.
C allows functions and structs to have identical names, preprocessor does not;
therefore win32_stat must be used explicitly where stat is required as in file.c:160
struct stat st; // expands into struct _stati64 on Windows.
# ifndef _WIN32
ret = stat(filename, &st);
# else
ret = win32_stat(filename, &st);
# endif
However, no everyone follows: img2dec.c:504 and ipfsgateway.c:104 use plain stat.
if (stat(filename, &img_stat)) {
stat_ret = stat(ipfs_full_data_folder, &st);
In these files, on Windows, both the struct and the function call expand into _stati64,
and this time the function call bypasses the UTF-8 to wchar conversion.
Apparently yet another macro is necessary:
#ifdef _WIN32
#define ff_stat win32_stat
#else
#define ff_stat stat
#endif
More information about the ffmpeg-devel
mailing list