Linux/Unix defines plenty of relatively similar error codes. Are there any commonly followed conventions suggesting what types of errors should be bound to which error codes?
Let's say my function has some arbitrary container with fixed size (and can't be resized for arbitrary reasons not related to actual RAM usage). If code tries to push too many objects into containers should I rather return ENOMEM or ENOSPC? Is ENOSPC solely dedicated to persistent storage devices space or something like that?
Error codes are not returned by programs, but by functions. See syscalls(2) and errno(3) with intro(3)
Correct programs are using somehow exit(3) (implicitly called by crt0 code when
main
isreturn
ing an exit code) but see also signal(7) and execve(2). UseEXIT_SUCCESS
andEXIT_FAILURE
, but do also look inside/usr/include/sysexits.h
Read also Advanced Linux Programming and
man
pages.Study for inspiration the source code of existing open source software, including GNU libc, GNU coreutils, GNU make.
For kernel modules, see also code from kernel.org and kernelnewbies.org