W dniu 05.01.2019 o 15:32, Liu Hao pisze:
> 在 2019/1/5 21:14, Johannes Pfau 写道:
>> Liu Hao:
>>> There are a few resolution to this at different levels. The most ideal
>>> solution would be providing an `access()` function that behaves
>>> expectedly in gnulib or libiberty, so this recipe can be ported
>>> elsewhere. Modifying GCC source should be considered the least preferred
>>> and last option.
>>
>> OK, that's what I thought. I've attached a new patch for libiberty,
>> could you please have a quick look at it before I submit it to GCC?
>>
>> It currently only handles F_OK which is the only case which really
>> seems to matter for GCC. I do not know how to check if a file is effectively
>> readable/writeable/executable in the windows api. And it seems
>> reimplementing R_OK and all the other flags would mean effectively
>> rewriting the complete access function. What do you think?
>>
> 
> A complete version looks basically like this:
> 
> ```c
>   DWORD attr = GetFileAttributesA(pathname);
>   if (attr == INVALID_FILE_ATTRIBUTES)
>     {
>       // Set `errno` accordingly.
>       switch (GetLastError())
>         {
>         case ERROR_FILE_NOT_FOUND:
>         case ERROR_PATH_NOT_FOUND:
>           errno = ENOENT;
>           break;
>         case ERROR_ACCESS_DENIED:
>           errno = EACCES;
>           break;
>         default:
>           errno = EINVAL;
>         }
>       return -1;
>     }
>   switch (mode)
>     {
>     case F_OK:
>     case R_OK:
>       // It is always existent and readable.
>       return 0;
>     case W_OK:
>       // Directories are always writeable.
>       if (attr & FILE_ATTRIBUTE_DIRECTORY)
>         return 0;
>       // Read-only files are not writeable.
>       if (attr & FILE_ATTRIBUTE_READONLY)
>         {
>           errno = EACCES;
>           return -1;
>         }
>       return 0;
>     case X_OK:
>       // On Windows all files are presumed to be executable.
>       // They can be opened in a command prompt without any arguments.
>       return 0;
>     default:
>       errno = EINVAL;
>       return -1;
>     }
> ```

ucrtbase.dll is affected too (msvcr100 works OK), so maybe it is better to add 
your access() function to msvcr110/120 and ucrtbase (as a replacement) instead 
of patching GCC.

Regards,
Mateusz



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to