Convert errno.h error values to Win32 GetLastError() equivalents

别来无恙 提交于 2019-11-29 18:14:03

问题


I'm writing a layer between a POSIX filesystem, and Windows using Dokan, and need to convert error values of the errno kind (EINVAL, ENOENT, etc.), to the Win32 equivalents you'd receive when calling GetLastError() (such as ERROR_INVALID_PARAMETER).

Is there an existing function, library, or reference I can use to perform these conversions?

I typically poke through the Python source for inspiration on these matters, but Python neatly avoids this need (at least as far as I can tell).

As an example, EINVAL (22) would convert to ERROR_INVALID_PARAMETER (87).


回答1:


I had done an experiment about this subject in the past, mostly based on Microsoft DOSMAP.CPP unit. However, I cancelled the project at that time because the error mapping was not always right for particular error codes. For Example, not every POSIX version return EINVAL for ERROR_INVALID_ACCESS, some of them return EACCES instead. I also had made a comparison between errno.h system error numbers of POSIX.1-2008 and DOSMAP.CPP, mingw.c, Postgresql error.c, tclWinError.c, MySQL my_winerr.c and many more; sometimes, the mapping rule differ among them for particular error codes. Personally, I suggest you to deal with only the consistent error-code mapping among them.




回答2:


For each errno there are in general many possible GetLastError values, so what you're thinking may not necessarily be feasible.

Anyway, I just googled "errno to getlasterror", and the first google hit provided this correspondence list from the Cygwin sources.

It is the wrong way, GetLastError to errno, but perhaps helpful?

Cheers & hth.



来源:https://stackoverflow.com/questions/3952342/convert-errno-h-error-values-to-win32-getlasterror-equivalents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!