ArticleslgStudy

science

Errno.h

Errno.h is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Errno.h rather than just read about it. In short: <errno.h> is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions using the symbol errno (short form for "error number"). errno acts like an integer variable.

Key takeaways

  • Errno.h belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Errno.h to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Errno.h from memory before moving on to harder problems.

Reference excerpt

<errno.h> is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions using the symbol errno (short form for "error number"). errno acts like an integer variable. A value (the error number) is stored in errno by certain library functions when they detect errors. At program startup, the value stored is zero. Library functions store only values greater than zero. Any library function can alter the value stored before return, whether or not they detect errors. Most functions indicate that they detected an error by returning a special value, typically NULL for functions that return pointers, and -1 for functions that return integers. A few functions require the caller to preset errno to 0 and test it afterwards to see if an error was detected. The errno macro expands to an lvalue with type int, sometimes with the extern and/or volatile type specifiers depending upon the platform. Originally this was a static memory location, but macros are almost always used today to allow for multi-threading, so that each thread will see its own thread-local error number. The header file also defines macros that expand to integer constants that represent the error codes. The C standard library only requires three to be defined:

POSIX compliant operating systems like AIX, Linux or Solaris include many other error values, many of which are used much more often than the above ones, such as EACCES for when a file cannot be opened for reading. C++11 additionally defines many of the same values found within the POSIX specification. Traditionally, the first page of Unix system manuals, named intro(2), lists all errno.h macros, but this is not the case with Linux, where these macros are instead listed in the errno(3). An errno can be translated to a descriptive string using strerror (defined in <string.h>) or a BSD extension called sys_errlist. The translation can be printed directly to the standard error stream using perror (defined in <stdio.h>). As strerror in many Unix-like systems is not thread-safe, a thread-safe version strerror_r is used, but conflicting definitions from POSIX and GNU makes it even less portable than the sys_errlist table.

POSIX errors The GNU C library (GLIBC) provides the additional POSIX error values macros in the header file <errno.h>. These are the descriptions of the macros provided by strerror.

The macro names and meanings for error codes are defined in the POSIX Standards definition however the numeric values are NOT, though by convention the values appear to be the same across different versions of Unix. Programs should not rely on specific numeric values and should test code using the macro names specified in the ERRORS section of the man page of the associated function. For source code readability and portability the use of the standard macro names in code is highly recommended.

See also perror strerror

References

Bibliography Stevens, W. Richard; Rago, Stephen A. (May 24, 2013). Advanced Programming in the UNIX Environment (Third ed.). Addison-Wesley Professional. ISBN 978-0321637734. Retrieved 27 February 2015.

External links intro(2) – FreeBSD System Calls Manual errno(3) – Linux Programmer's Manual – Library Functions from Manned.org GNU C library manual: Error codes Lists of errno values on Linux, both numeric and symbolic

Worked examples

Example 1 — a first encounter with Errno.h

Start with the simplest possible case. Write down what Errno.h claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Errno.h before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Errno.h ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Errno.h

In research
Errno.h appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Errno.h in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Errno.h is common in secondary-school and first-year university syllabi. It links to neighbouring topics C standard library headers, POSIX error codes, so understanding it makes those chapters shorter.
In everyday life
Look for Errno.h outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Errno.h” →

How to study Errno.h in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Errno.h means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Errno.h out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Errno.h in simple terms?

<errno.h> is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions using the symbol errno (short form for "error number"). errno acts like an integer variable.

Why does Errno.h matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Errno.h?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Errno.h.

Tags

  • C standard library headers
  • POSIX error codes

Keep exploring