Skip to content

_wstat doesn't behave properly on windows/wine

I'm creating this to keep track of an issue with _wstat64 when running on windows, which is one of the reasons the windows pipelines fail for !334

If seems _wstat() doesn't behave the same depending on the presence of a trailing / at the end of the path:

root@compile-medialibrary-win64:/home/chouquette/dev/medialibrary/build-win64/test-stat# cat test.c
#include <windows.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <stdio.h>

int main()
{
    struct _stat64 s;
    int res = _wstat64( TEXT("folder/" ), &s );
    fprintf(stderr, "res: %d errno: %d\n", res, errno);
    res = _wstat64( TEXT("folder" ), &s );
    fprintf(stderr, "res: %d errno: %d\n", res, errno);
    return 0;
}

root@compile-medialibrary-win64:/home/chouquette/dev/medialibrary/build-win64/test-stat# ls -l
total 8
drwxr-xr-x 2 root root 4096 May  6 09:10 folder
-rw-r--r-- 1 root root  342 May  6 09:16 test.c

root@compile-medialibrary-win64:/home/chouquette/dev/medialibrary/build-win64/test-stat# x86_64-w64-mingw32-gcc -DUNICODE=1 test.c
root@compile-medialibrary-win64:/home/chouquette/dev/medialibrary/build-win64/test-stat# wine a.exe 
res: -1 errno: 2
res: 0 errno: 2

The problem is that we heavily assume that a folder will have a trailing / and ideally we don't want to manipulate the path when browsing a directory.

This seems to be tracked upstream here: https://sourceforge.net/p/mingw-w64/bugs/643/

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information