What does errno 22 (EINVAL) mean?

 
Could be also:
ConstantTypeOS
ERROR_BAD_COMMANDWin32 errorWindows
KERN_INVALID_HOSTKern returnMac
ippStsNoIppFunctionFoundIntel Ipp StatusAny
CID_HANDLE_CREATIONBugCheck CodeWindows
Previous Next
EISDIR ENFILE

EINVAL

A contract error whose meaning comes from the call site

EINVAL has no single universal cause. It says that the invoked interface rejected one or more arguments or their combination. With mmap(), examples include an invalid address, length, offset, or mapping-flag combination. With strtol(), an unsupported numeric base can produce EINVAL. The useful explanation is therefore the documented precondition of the exact function, not a generic “bad parameter” message.

Not every interface reports this value through errno. POSIX posix_memalign() returns EINVAL directly when its alignment is not a power of two or is not a multiple of sizeof(void *); its manual specifically says that it does not set errno. Error handling must match the API’s return convention.

Useful evidence for diagnosis

InterfaceExample condition
mmap()Invalid address, length, offset, or missing required mapping mode.
posix_memalign()Alignment is not a power of two or not a multiple of sizeof(void *).
strtol()The selected base is unsupported by the implementation.
  • Log the function name and the original numeric values of all relevant arguments, flags, lengths, offsets, and alignment values.
  • Check relationships between parameters, such as flag dependencies and alignment constraints, rather than validating each value in isolation.
  • Reject unsupported options at the boundary of the application and preserve the failing call context in diagnostics.
  • Do not retry an unchanged invocation: unlike a temporary resource condition, EINVAL normally requires different input or a different API path.

References


Looking for a different code? Search another status or error code.