ERRNO(3P)

โœจ ERRNO(3P) โœจ

okay bestie so this is the POSIX Programmer's Manual page for errno, and literally the first thing you need to know is that this page is part of the POSIX Programmer's Manual. that's the whole vibe. but heads up ๐Ÿซถ โ€” the Linux implementation of this interface may differ (so go consult the corresponding Linux manual page for the details of Linux behavior), or honestly the interface may not be implemented on Linux at all. not me being dramatic, that's just what it says ๐Ÿ’€


๐Ÿ’– PROLOG ๐Ÿ’–

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.


๐ŸŒธ NAME ๐ŸŒธ

errno โ€” error return value. that's it. that's the whole name section. iconic behavior tbh ๐Ÿ‘‘


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

#include <errno.h>

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so the lvalue errno is used by many functions to return error values. like, it's the group chat where every function drops its bad news ๐Ÿ“ฌ

Many functions provide an error number in errno, which has type int and is defined in <errno.h>. got it? int. not a long, not a size_t, int. periodt ๐Ÿ’…

now the rules, and bestie you HAVE to follow these:

  • The value of errno shall be defined only after a call to a function for which it is explicitly stated to be set, and it stays defined until it is changed by the next function call โ€” or until the application assigns it a value.
  • The value of errno should only be examined when it is indicated to be valid by a function's return value. no peeking when it's not invited ๐Ÿ™ˆ
  • Applications shall obtain the definition of errno by the inclusion of <errno.h>.
  • No function in this volume of POSIX.1โ€2017 shall set errno to 0. like, zero is just not on the menu.
  • The setting of errno after a successful call to a function is unspecified unless the description of that function specifies that errno shall not be modified. so don't be out here reading it after a win and assuming it means something, that's a whole vibe check fail ๐Ÿ˜ญ

okay and this next part is the spicy one ๐ŸŒถ๏ธ

It is unspecified whether errno is a macro or an identifier declared with external linkage. If a macro definition is suppressed in order to access an actual object, or a program defines an identifier with the name errno, the behavior is undefined. undefined. undefinED. don't do it, bestie, I'm begging ๐Ÿซถ

The symbolic values stored in errno are documented in the ERRORS sections on all relevant pages. so if you want the tea on what a specific number means, that's where it lives ๐Ÿ”


๐ŸŒˆ RETURN VALUE ๐ŸŒˆ

None. absolutely nothing. it's giving void energy โญ


๐Ÿ’œ ERRORS ๐Ÿ’œ

None.

The following sections are informative. (translation: the rest of this page is the commentary track, not the rules ๐ŸŽง)


๐Ÿ“ EXAMPLES ๐Ÿ“

None. no examples, no demo, no tutorial arc, we simply do not have one today ๐Ÿ™ˆ


๐Ÿงš APPLICATION USAGE ๐Ÿงš

history lesson time โœจ Previously both POSIX and X/Open documents were more restrictive than the ISO C standard in that they required errno to be defined as an external variable, whereas the ISO C standard required only that errno be defined as a modifiable lvalue with type int. so the ISO C girlies were out here being chill and POSIX/X-Open were out here being strict. the way that standards evolve ๐Ÿ˜Œ

and here's the actual practical tip, write it down ๐Ÿ“ โ€” an application that needs to examine the value of errno to determine the error should set it to 0 before a function call, then inspect it before a subsequent function call.

like literally:

errno = 0;
some_function_call();
/* inspect errno now, before calling anything else */

because remember, the next function call can just wipe it. it's giving "you snooze you lose" ๐Ÿ’…


๐Ÿ‘‘ RATIONALE ๐Ÿ‘‘

None. the reasoning is a mystery, the reasoning is a secret, the reasoning said "no thoughts head empty" ๐Ÿ’€


โญ FUTURE DIRECTIONS โญ

None. the future is unspecified but it is definitely not doing anything here ๐Ÿ”ฎ


๐Ÿ’ซ SEE ALSO ๐Ÿ’ซ

  • Section 2.3, Error Numbers
  • The Base Definitions volume of POSIX.1โ€2017, <errno.h>

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay bestie that's the whole page, we did it, we read the entire thing ๐ŸŽ‰ this one's brought to you by IEEE/The Open Group, 2017 โ€” that's the source and the date, and honestly? slay. now go set your errno to 0 and check it before the next call, I'm so serious ๐Ÿซถ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from