本文介绍了将errno.h错误值转换为Win32 GetLastError()等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写 POSIX文件系统,以及使用 Dokan ,并且需要转换 errno类型的错误值(EINVALENOENT等),转换为调用 GetLastError() (例如 ERROR_INVALID_PARAMETER ).

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).

我是否可以使用现有的函数,库或引用来执行这些转换?

我通常会在这些问题上从Python来源中寻找灵感,但是Python巧妙地避免了这种需求(至少据我所知).

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).

例如,EINVAL (22)将转换为ERROR_INVALID_PARAMETER (87).

推荐答案

过去,我主要基于Microsoft DOSMAP.CPP 单元.但是,我当时取消了该项目,因为错误映射并不总是适合特定的错误代码.例如,并非每个POSIX版本都为ERROR_INVALID_ACCESS返回EINVAL,其中有些返回了EACCES.我还对POSIX.1的 errno.h系统错误号进行了比较. -2008 DOSMAP.CPP mingw.c Postgresql error.c tclWinError.c ,MySQL my_winerr.c等;有时,对于特定的错误代码,映射规则在它们之间是不同的.就个人而言,我建议您仅处理它们之间一致的错误代码映射.

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.

这篇关于将errno.h错误值转换为Win32 GetLastError()等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:44