Skip to content

SET_ERRNO macro in Windows should likely map to _set_errno #895

@jay

Description

@jay

In lib/curl_setup_once.h there is this code:

/*
 * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
 * (or equivalent) on this platform to hide platform details to code using it.
 */

#if defined(WIN32) && !defined(USE_LWIPSOCK)
#define ERRNO         ((int)GetLastError())
#define SET_ERRNO(x)  (SetLastError((DWORD)(x)))
#else
#define ERRNO         (errno)
#define SET_ERRNO(x)  (errno = (x))
#endif

Windows has a CRT that uses errno, and you can set it with _set_errno. Though it is supposedly compatible with all of Windows, early versions of SDK don't seem to have the prototype. In VC6 (earliest I have) if the static library is used the errno is a global variable and you can set it directly. Update: _set_errno is available starting in VS2005.

SetLastError is for the Windows API (which the CRT calls internally) and afaik does not match up with errno. When we do stuff like SET_ERRNO(ERANGE); then in Windows it becomes SetLastError(ERANGE) and I'm pretty sure that's not correct.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions