On Sat, Oct 10, 2020 at 2:24 PM Michael Paquier <mich...@paquier.xyz> wrote:

>
> -               _dosmaperr(GetLastError());
> +               DWORD           err = GetLastError();
> +
> +               /* report when not ERROR_SUCCESS */
> +               if (err == ERROR_FILE_NOT_FOUND || err ==
> ERROR_PATH_NOT_FOUND)
> +                       errno = ENOENT;
> +               else
> +                       _dosmaperr(err);
> Why are you changing that?  The original coding is fine, as
> _dosmaperr() already maps ERROR_FILE_NOT_FOUND and
> ERROR_PATH_NOT_FOUND to ENOENT.
>

If the file does not exist there is no need to call _dosmaperr() and log
the error.

>
> -      _dosmaperr(GetLastError());
> +      DWORD           err = GetLastError();
> +
>        CloseHandle(hFile);
> +      _dosmaperr(err);
> These parts are indeed incorrect.  CloseHandle() could overwrite
> errno.
>

The meaningful error should come from the previous call, and an error from
CloseHandle() could mask it. Not sure it makes a difference anyhow.

Regards,

Juan José Santamaría Flecha

Reply via email to