<!DOCTYPE html>
<html class="client-js"><head>
  <meta charset="UTF-8">
  <title>errno.h</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script>
    function importScript() { return 1 } // this is to avoid the error from site.js
  </script>
  <script>let articleId = 'Errno.h'</script>
  <link rel="canonical" href="https://en.wikipedia.org/wiki/Errno.h">
  <link href="../-/mw/ext.cite.ux-enhancements.css" rel="stylesheet" type="text/css">
<link href="../-/mw/ext.scribunto.logs.css" rel="stylesheet" type="text/css">
<link href="../-/mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="../-/mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="../-/mw/skins.minerva.base.reset|skins.minerva.content.styles|ext.cite.style|site.styles|mobile.app.pagestyles.android|mediawiki.page.gallery.styles|mediawiki.skinning.content.parsoid.css" rel="stylesheet" type="text/css">
  <link href="../-/style.css" rel="stylesheet" type="text/css"><link href="../-/content.parsoid.css" rel="stylesheet" type="text/css"><link href="../-/inserted_style.css" rel="stylesheet" type="text/css">
  <script src="../-/script.js"></script><script src="../-/masonry.min.js"></script><script src="../-/article_list_home.js"></script><script src="../-/images_loaded.min.js"></script><script src="../-/node_module/details-element-polyfill/dist/details-element-polyfill.js"></script>
</head>

<body class="mediawiki mw-hide-empty-elt ns-0 ns-subject stable skin-minerva action-view animations">
  <div id="mw-mf-viewport" class="feature-header-v2">
    <div id="mw-mf-page-center">
      <div id="content" class="mw-body">
        <a id="top"></a>
        <div id="bodyContent" class="content mw-parser-output">
          
          <div id="mw-content-text" style="direction: ltr;"><h1 class="section-heading" tabindex="0" aria-haspopup="true" data-section-id="0">
  <span class="mw-headline" id="title_0">errno.h</span>
</h1>
<div id="mf-section-0" class="mf-section-0" aria-pressed="true" aria-expanded="true">
  <p><span>
</span><meta property="mw:PageProp/displaytitle" content="errno.h">
<b>errno.h</b> is a <a href="Header_file" title="Header file" class="mw-redirect">header file</a> in the <a href="C_standard_library" title="C standard library">standard library</a> of the <a href="C_(programming_language)" title="C (programming language)">C programming language</a>. It defines <a href="Macro_(computer_science)" title="Macro (computer science)">macros</a> for reporting and retrieving error conditions using the symbol <code>errno</code> (short for "error number").<span class="mw-ref reference" id="cite_ref-C11_1-0"><a href="#cite_note-C11-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></span></p>

<style data-mw-deduplicate="TemplateStyles:r1003042402">.mw-parser-output .sidebar{width:22em;float:right;clear:right;margin:0.5em 0 1em 1em;background:#f8f9fa;border:1px solid #aaa;padding:0.2em;border-spacing:0.4em 0;text-align:center;line-height:1.4em;font-size:88%}.mw-parser-output .sidebar a{white-space:nowrap}.mw-parser-output .sidebar-wraplinks a{white-space:normal}.mw-parser-output .sidebar-subgroup{width:100%;margin:0;border-spacing:0}.mw-parser-output .sidebar-left{float:left;clear:left;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-none{float:none;clear:both;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-outer-title{padding-bottom:0.2em;font-size:125%;line-height:1.2em;font-weight:bold}.mw-parser-output .sidebar-top-image{padding:0.4em 0}.mw-parser-output .sidebar-top-caption,.mw-parser-output .sidebar-pretitle-with-top-image,.mw-parser-output .sidebar-caption{padding-top:0.2em;line-height:1.2em}.mw-parser-output .sidebar-pretitle{padding-top:0.4em;line-height:1.2em}.mw-parser-output .sidebar-title,.mw-parser-output .sidebar-title-with-pretitle{padding:0.2em 0.4em;font-size:145%;line-height:1.2em}.mw-parser-output .sidebar-title-with-pretitle{padding-top:0}.mw-parser-output .sidebar-image{padding:0.2em 0 0.4em}.mw-parser-output .sidebar-heading{padding:0.1em}.mw-parser-output .sidebar-content{padding:0 0.1em 0.4em}.mw-parser-output .sidebar-content-with-subgroup{padding:0.1em 0 0.2em}.mw-parser-output .sidebar-above,.mw-parser-output .sidebar-below{padding:0.3em 0.4em;font-weight:bold}.mw-parser-output .sidebar-collapse .sidebar-above,.mw-parser-output .sidebar-collapse .sidebar-below{border-top:1px solid #aaa;border-bottom:1px solid #aaa}.mw-parser-output .sidebar-navbar{text-align:right;font-size:115%}.mw-parser-output .sidebar-collapse .sidebar-navbar{padding-top:0.6em}.mw-parser-output .sidebar-collapse .mw-collapsible-toggle{margin-top:0.2em}.mw-parser-output .sidebar-list-title{text-align:left;font-weight:bold;line-height:1.6em;font-size:105%}@media(max-width:720px){body.mediawiki .mw-parser-output .sidebar{width:100%!important;clear:both;float:none;margin-left:0!important;margin-right:0!important}}</style><table class="sidebar vertical-navbox nomobile"><tbody><tr><th class="sidebar-title"><a href="C_standard_library" title="C standard library">C standard library</a></th></tr><tr><th class="sidebar-heading">
General topics</th></tr><tr><td class="sidebar-content" style="text-align: left">
<ul><li><a href="C_data_types" title="C data types">Data types</a></li>
<li><a href="C_character_classification" title="C character classification">Character classification</a></li>
<li><a href="C_string_handling" title="C string handling">Strings</a></li>
<li><a href="C_mathematical_functions" title="C mathematical functions">Mathematics</a></li>
<li><a href="C_file_input/output" title="C file input/output">File input/output</a></li>
<li><a href="C_date_and_time_functions" title="C date and time functions">Date/time</a></li>
<li><a href="C_localization_functions" title="C localization functions">Localization</a></li>
<li><a href="C_dynamic_memory_allocation" title="C dynamic memory allocation">Memory allocation</a></li>
<li><a href="C_process_control" title="C process control">Process control</a></li>
<li><a href="C_signal_handling" title="C signal handling">Signals</a></li>
<li><a href="C_alternative_tokens" title="C alternative tokens">Alternative tokens</a></li></ul></td>
</tr><tr><th class="sidebar-heading">
Miscellaneous headers</th></tr><tr><td class="sidebar-content" style="text-align: left">
<ul><li><style data-mw-deduplicate="TemplateStyles:r886049734">.mw-parser-output .monospaced{font-family:monospace,monospace}</style><span class="monospaced">&lt;<a href="Assert.h" title="Assert.h">assert.h</a>&gt;</span></li>
<li><span class="monospaced">&lt;<a href="Errno.h" title="Errno.h">errno.h</a>&gt;</span></li>
<li><span class="monospaced">&lt;<a href="Setjmp.h" title="Setjmp.h">setjmp.h</a>&gt;</span></li>
<li><span class="monospaced">&lt;<a href="Stdarg.h" title="Stdarg.h">stdarg.h</a>&gt;</span></li></ul></td>
</tr><tr><td class="sidebar-navbar"><style data-mw-deduplicate="TemplateStyles:r992953826">.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}.mw-parser-output .infobox .navbar{font-size:100%}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}</style></td></tr></tbody></table>
<p><code>errno</code> acts like an integer variable. A value (the error number) is stored in <code>errno</code> by certain <a href="Library_function" title="Library function" class="mw-redirect">library functions</a> 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.<span class="mw-ref reference" id="cite_ref-C99_2-0"><a href="#cite_note-C99-2" style="counter-reset: mw-Ref 2;"><span class="mw-reflink-text">[2]</span></a></span> Most functions indicate that they detected an error by returning a special value, typically <a href="Null_pointer" title="Null pointer">NULL</a> for functions that return <a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointers</a>, and -1 for functions that return integers. A few functions require the caller to preset <code>errno</code> to zero and test it afterwards to see if an error was detected.</p>

<p>The <code>errno</code> macro expands to an <a href="Value_(computer_science)" title="Value (computer science)">lvalue</a> with type <code>int</code>, sometimes with the <code>extern</code> and/or <code>volatile</code> type specifiers depending upon the platform.<span class="mw-ref reference" id="cite_ref-3"><a href="#cite_note-3" style="counter-reset: mw-Ref 3;"><span class="mw-reflink-text">[3]</span></a></span> Originally this was a static memory location, but macros are almost always used today to allow for <a href="Multithreading_(software)" title="Multithreading (software)" class="mw-redirect">multi-threading</a>, so that each thread will see its own <a href="Thread-local_storage" title="Thread-local storage">thread-local</a> error number.</p>

<p>The header file also defines macros that expand to integer constants that represent the error codes. The <a href="C_standard_library" title="C standard library">C standard library</a> only requires three to be defined:<span class="mw-ref reference" id="cite_ref-C99_2-1"><a href="#cite_note-C99-2" style="counter-reset: mw-Ref 2;"><span class="mw-reflink-text">[2]</span></a></span></p>

<p><b>EDOM</b></p>
<dl><dd>Results from a parameter outside a function's domain, e.g. <code>sqrt(-1)</code></dd></dl>

<p><b>ERANGE</b></p>
<dl><dd>Results from a result outside a function's range, e.g. <code>strtol("0xfffffffff",NULL,0)</code> on systems with a 32-bit wide <code>long</code></dd></dl>

<p><b>EILSEQ</b> <small>(Required since 1994 Amendment 1 to C89 standard)</small><span class="mw-ref reference" id="cite_ref-4"><a href="#cite_note-4" style="counter-reset: mw-Ref 4;"><span class="mw-reflink-text">[4]</span></a></span></p>
<dl><dd>Results from an illegal byte sequence, e.g. <code>mbstowcs(buf,"\xff", 1)</code> on systems that use <a href="UTF-8" title="UTF-8">UTF-8</a>.</dd></dl>

<p><a href="POSIX" title="POSIX">POSIX</a> compliant <a href="Operating_system" title="Operating system">operating systems</a> like <a href="AIX" title="AIX" class="mw-redirect">AIX</a>, <a href="Linux" title="Linux">Linux</a> or <a href="Solaris_(operating_system)" title="Solaris (operating system)">Solaris</a> include many other error values, many of which are used much more often than the above ones, such as <b>EACCES</b> for when a file cannot be opened for reading.<span class="mw-ref reference" id="cite_ref-5"><a href="#cite_note-5" style="counter-reset: mw-Ref 5;"><span class="mw-reflink-text">[5]</span></a></span> <a href="C%2B%2B11" title="C++11">C++11</a> additionally defines many of the same values found within the POSIX specification.<span class="mw-ref reference" id="cite_ref-6"><a href="#cite_note-6" style="counter-reset: mw-Ref 6;"><span class="mw-reflink-text">[6]</span></a></span></p>

<p>Traditionally, the first page of <a href="Man_page" title="Man page">Unix system manuals</a>, named intro(2), lists all errno.h macros, but this is not the case with <a href="Linux" title="Linux">Linux</a>, where these macros are instead listed in the errno(3).<span class="mw-ref reference" id="cite_ref-FOOTNOTEStevensRago201314_7-0"><a href="#cite_note-FOOTNOTEStevensRago201314-7" style="counter-reset: mw-Ref 7;"><span class="mw-reflink-text">[7]</span></a></span></p>

<p>An <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">errno</code> can be translated to a descriptive string using <a href="Strerror" title="Strerror" class="mw-redirect">strerror</a> (defined in <a href="String.h" title="String.h" class="mw-redirect">string.h</a>) or a BSD extension called <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">sys_errlist</code>. The translation can be printed directly to the <a href="Standard_error_stream" title="Standard error stream" class="mw-redirect">standard error stream</a> using <a href="Perror" title="Perror" class="mw-redirect">perror</a> (defined in <a href="Stdio.h" title="Stdio.h" class="mw-redirect">stdio.h</a>). As <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">strerror</code> in many Unix-like systems are not thread-safe, a thread-safe version <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">strerror_r</code> is used, but conflicting definitions from POSIX and GNU makes it even less portable than the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">sys_errlist</code> table.<span class="mw-ref reference" id="cite_ref-8"><a href="#cite_note-8" style="counter-reset: mw-Ref 8;"><span class="mw-reflink-text">[8]</span></a></span></p>


</div><details data-level="2" open="">
    <summary class="section-heading"><h2 id="See_also">See also</h2></summary>
    
<ul><li><a href="Perror" title="Perror" class="mw-redirect">perror</a></li>
<li><a href="Strerror" title="Strerror" class="mw-redirect">strerror</a></li></ul>


    
</details><details data-level="2" open="">
    <summary class="section-heading"><h2 id="References">References</h2></summary>
    
<div class="reflist " style=" list-style-type: decimal;">
<div class="mw-references-wrap"><ol class="mw-references references"><li id="cite_note-C11-1"> <span id="mw-reference-text-cite_note-C11-1" class="mw-reference-text">International Standard for Programming Language C (C11), ISO/IEC 9899:2011, p. 205</span></li><li id="cite_note-C99-2"> <span id="mw-reference-text-cite_note-C99-2" class="mw-reference-text">International Standard for Programming Language C (C99), ISO/IEC 9899:1999, p. 186</span></li><li id="cite_note-3"> <span id="mw-reference-text-cite_note-3" class="mw-reference-text"><cite class="citation web cs1"><a href="https://www.gnu.org/software/libc/manual/html_node/Checking-for-Errors.html" class="external text external">"Checking for Errors"</a>. <i>The GNU C Library (glibc)</i>. GNU Project. 2014-02-08<span class="reference-accessdate">. Retrieved <span class="nowrap">2014-06-25</span></span>.</cite></span></li><li id="cite_note-4"> <span id="mw-reference-text-cite_note-4" class="mw-reference-text"><cite class="citation web cs1"><a href="http://www.lysator.liu.se/c/na1.html" class="external text external">"A brief description of Normative Addendum 1"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2013-09-12</span></span>.</cite></span></li><li id="cite_note-5"> <span id="mw-reference-text-cite_note-5" class="mw-reference-text"><span class="neverexpand"><code><a href="https://www.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html" class="external text external">errno.h</a></code></span><span>:</span><span>&nbsp;</span><span>system error numbers</span><span>&nbsp;</span><span>–</span><span>&nbsp;</span><span>Base Definitions Reference, </span><a href="Single_Unix_Specification" title="Single Unix Specification" class="mw-redirect">The Single UNIX Specification</a><span>, Issue 7 from </span><a href="The_Open_Group" title="The Open Group">The Open Group</a></span></li><li id="cite_note-6"> <span id="mw-reference-text-cite_note-6" class="mw-reference-text"><cite class="citation web cs1"><a href="http://en.cppreference.com/w/cpp/error/errno_macros" class="external text external">"Error numbers - cppreference.com"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2015-05-08</span></span>.</cite></span></li><li id="cite_note-FOOTNOTEStevensRago201314-7"> <span id="mw-reference-text-cite_note-FOOTNOTEStevensRago201314-7" class="mw-reference-text"><a href="#CITEREFStevensRago2013">Stevens <span>&amp;</span> Rago 2013</a>, p.<span>&nbsp;</span>14.</span></li><li id="cite_note-8"> <span id="mw-reference-text-cite_note-8" class="mw-reference-text"><cite id="CITEREFMcCabe" class="citation web cs1">McCabe, Colin. <a href="http://www.club.cc.cmu.edu/~cmccabe/blog_strerror.html" class="external text external">"The problem with strerror"</a>. <i>www.club.cc.cmu.edu</i>.</cite></span></li></ol></div></div>


    
</details><details data-level="2" open="">
    <summary class="section-heading"><h2 id="Bibliography">Bibliography</h2></summary>
    
<ul><li><cite id="CITEREFStevensRago2013" class="citation book cs1">Stevens, W. Richard; Rago, Stephen A. (May 24, 2013). <a href="http://www.kohala.com/start/apue.html" class="external text external"><i>Advanced Programming in the UNIX Environment</i></a> (Third<span>&nbsp;</span>ed.). <a href="Addison-Wesley_Professional" title="Addison-Wesley Professional" class="mw-redirect">Addison-Wesley Professional</a>. <a href="ISBN_(identifier)" title="ISBN (identifier)" class="mw-redirect">ISBN</a><span>&nbsp;</span><bdi>978-0321637734</bdi><span class="reference-accessdate">. Retrieved <span class="nowrap">27 February</span> 2015</span>.</cite></li></ul>


    
</details><details data-level="2" open="">
    <summary class="section-heading"><h2 id="External_links">External links</h2></summary>
    
<ul><li><span class="neverexpand"><code><a href="https://www.freebsd.org/cgi/man.cgi?query=intro&amp;sektion=2" class="external text external">intro(2)</a></code></span><span>&nbsp;</span><span>–</span><span>&nbsp;</span><a href="FreeBSD" title="FreeBSD">FreeBSD</a><span> System Calls </span><a href="Man_page" title="Man page">Manual</a></li>
<li><span class="neverexpand"><code><a href="http://man7.org/linux/man-pages/man3/errno.3.html" class="external text external">errno(3)</a></code></span><span>&nbsp;</span><span>–</span><span>&nbsp;</span><a href="Linux" title="Linux">Linux</a><span> Programmer's </span><a href="Man_page" title="Man page">Manual</a><span> – Library Functions</span></li>
<li><a href="https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html#index-ENOBUFS-117" class="external text external">GNU C library manual: Error codes</a></li>
<li><a href="https://nuetzlich.net/errno.html" class="external text external">Lists of errno values on Linux, both numeric and symbolic</a></li></ul>


<style data-mw-deduplicate="TemplateStyles:r999302996">.mw-parser-output cite.citation{font-style:inherit}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .id-lock-free a,.mw-parser-output .citation .cs1-lock-free a{background:linear-gradient(transparent,transparent),url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited a,.mw-parser-output .id-lock-registration a,.mw-parser-output .citation .cs1-lock-limited a,.mw-parser-output .citation .cs1-lock-registration a{background:linear-gradient(transparent,transparent),url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription a,.mw-parser-output .citation .cs1-lock-subscription a{background:linear-gradient(transparent,transparent),url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration{color:#555}.mw-parser-output .cs1-subscription span,.mw-parser-output .cs1-registration span{border-bottom:1px dotted;cursor:help}.mw-parser-output .cs1-ws-icon a{background:linear-gradient(transparent,transparent),url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}.mw-parser-output code.cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;font-size:100%}.mw-parser-output .cs1-visible-error{font-size:100%}.mw-parser-output .cs1-maint{display:none;color:#33aa33;margin-left:0.3em}.mw-parser-output .cs1-format{font-size:95%}.mw-parser-output .cs1-kern-left,.mw-parser-output .cs1-kern-wl-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right,.mw-parser-output .cs1-kern-wl-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}</style>
    
</details><!--htdig_noindex--><div><div style="clear:both; background-image:linear-gradient(180deg, #E8E8E8, white); border-top: dashed 2px #AAAAAA; padding: 0.5em 0.5em 0.5em 0.5em; margin-top: 1em; direction: ltr;">
    This article is issued from <a class="external text" title="Last edited on 2021-01-28" href="https://en.wikipedia.org/wiki/?title=Errno.h&amp;oldid=1003387888">Wikipedia</a>. The text is licensed under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons - Attribution - Sharealike</a>. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
        </div>
      </div>
    </div>
  </div>
  <script src="../-/mw/jsConfigVars.js"></script>
  <script src="../-/mw/startup.js"></script>
<script src="../-/mw/jquery.js"></script>
<script src="../-/mw/mediawiki.js"></script>
<script src="../-/mw/site.js"></script>
<script src="../-/mw/ext.cite.ux-enhancements.js"></script>
<script src="../-/mw/ext.scribunto.logs.js"></script>



</body></html>