3 ms·
Well... Yeah, there's some merit to errno: it lets you handle errors. Otherwise it's a horrible piece of crap: - It's a global (sorry, thread-local) variable,
by tzahola 9y ago
Well... Yeah, there's some merit to errno: it lets you handle errors.
Otherwise it's a horrible piece of crap:
- It's a global (sorry, thread-local) variable, updated behind the scenes.
- You can't tell whether a function will update errno or not by its signature. You have to consult the documentation.
- You can't tell the range of possible errno values unless it's explicitly documented (and the documentation is kept in sync with the implementation).
- Errno only communicates error metadata; the success/error bit has to be communicated in-band via the return value (e.g. printf returning < 0).
- Except for some functions which return void (or like readdir, which returns NULL when reaching the end of the directory, or on error) and set errno on error.
- In which case you better set errno to 0 before calling the function, because while these functions set errno on failure, they not necessarily set it to 0 on success...