I’m creating my own C library and I came across a dilemma.
What value should library function return?
Should I have my own errno variable, and then functions return 0 for success and -1 for failure and set errno to the specific error? (like most of libc functions do).
Or should I have an enum containing all the error codes and then every function returns the specific error number?
On the one hand I see the first method (errno) being used in lots of libraries, on the other hand I don’t see why a function returning int should waste its entire 4 bytes of return code for just 0 and -1 and use another global variable to specify the error? Why not return the error number directly?
I would like to get a better sense of why libraries use errno? I might be missing something here.
Thanks in advance :)