{"id":5317,"date":"2022-12-20T18:37:18","date_gmt":"2022-12-20T21:37:18","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/strerror-man3p\/"},"modified":"2022-12-20T18:37:18","modified_gmt":"2022-12-20T21:37:18","slug":"strerror-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/strerror-man3p\/","title":{"rendered":"STRERROR (man3p)"},"content":{"rendered":"<h1 align=\"center\">STRERROR<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s 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.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">strerror, strerror_l, strerror_r \u2014 get error message string<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <string.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">char *strerror(int <i>errnum<\/i>); <br \/> char *strerror_l(int <i>errnum<\/i>, locale_t <i>locale<\/i>); <br \/> int strerror_r(int <i>errnum<\/i>, char *<i>strerrbuf<\/i>, size_t <i>buflen<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For <i>strerror<\/i>(): The functionality described on this reference page is aligned with the ISO\u00a0C standard. Any conflict between the requirements described here and the ISO\u00a0C standard is unintentional. This volume of POSIX.1-2017 defers to the ISO\u00a0C standard.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>strerror<\/i>() function shall map the error number in <i>errnum<\/i> to a locale-dependent error message string and shall return a pointer to it. Typically, the values for <i>errnum<\/i> come from <i>errno<\/i>, but <i>strerror<\/i>() shall map any value of type <b>int<\/b> to a message.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The application shall not modify the string returned. The returned string pointer might be invalidated or the string content might be overwritten by a subsequent call to <i>strerror<\/i>(), or by a subsequent call to <i>strerror_l<\/i>() in the same thread. The returned pointer and the string content might also be invalidated if the calling thread is terminated.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The string may be overwritten by a subsequent call to <i>strerror_l<\/i>() in the same thread.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The contents of the error message strings returned by <i>strerror<\/i>() should be determined by the setting of the <i>LC_MESSAGES<\/i> category in the current locale.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The implementation shall behave as if no function defined in this volume of POSIX.1-2017 calls <i>strerror<\/i>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>strerror<\/i>() and <i>strerror_l<\/i>() functions shall not change the setting of <i>errno<\/i> if successful.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Since no return value is reserved to indicate an error of <i>strerror<\/i>(), an application wishing to check for error situations should set <i>errno<\/i> to 0, then call <i>strerror<\/i>(), then check <i>errno<\/i>. Similarly, since <i>strerror_l<\/i>() is required to return a string for some errors, an application wishing to check for all error situations should set <i>errno<\/i> to 0, then call <i>strerror_l<\/i>(), then check <i>errno<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>strerror<\/i>() function need not be thread-safe.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>strerror_l<\/i>() function shall map the error number in <i>errnum<\/i> to a locale-dependent error message string in the locale represented by <i>locale<\/i> and shall return a pointer to it.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>strerror_r<\/i>() function shall map the error number in <i>errnum<\/i> to a locale-dependent error message string and shall return the string in the buffer pointed to by <i>strerrbuf<\/i>, with length <i>buflen<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the value of <i>errnum<\/i> is a valid error number, the message string shall indicate what error occurred; if the value of <i>errnum<\/i> is zero, the message string shall either be an empty string or indicate that no error occurred; otherwise, if these functions complete successfully, the message string shall indicate that an unknown error occurred.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The behavior is undefined if the <i>locale<\/i> argument to <i>strerror_l<\/i>() is the special locale object LC_GLOBAL_LOCALE or is not a valid locale object handle.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon completion, whether successful or not, <i>strerror<\/i>() shall return a pointer to the generated message string. On error <i>errno<\/i> may be set, but no return value is reserved to indicate an error.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>strerror_l<\/i>() shall return a pointer to the generated message string. If <i>errnum<\/i> is not a valid error number, <i>errno<\/i> may be set to <b>[EINVAL]<\/b>, but a pointer to a message string shall still be returned. If any other error occurs, <i>errno<\/i> shall be set to indicate the error and a null pointer shall be returned.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>strerror_r<\/i>() shall return 0. Otherwise, an error number shall be returned to indicate the error.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">These functions may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The value of <i>errnum<\/i> is neither a valid error number nor zero.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>strerror_r<\/i>() function may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p style=\"margin-top: 1em\"><b>ERANGE<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">Insufficient storage was supplied via <i>strerrbuf<\/i> and <i>buflen<\/i> to contain the generated message string.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Historically in some implementations, calls to <i>perror<\/i>() would overwrite the string that the pointer returned by <i>strerror<\/i>() points to. Such implementations did not conform to the ISO\u00a0C standard; however, application developers should be aware of this behavior if they wish their applications to be portable to such implementations.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>strerror_l<\/i>() function is required to be thread-safe, thereby eliminating the need for an equivalent to the <i>strerror_r<\/i>() function.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Earlier versions of this standard did not explicitly require that the error message strings returned by <i>strerror<\/i>() and <i>strerror_r<\/i>() provide any information about the error. This version of the standard requires a meaningful message for any successful completion.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Since no return value is reserved to indicate a <i>strerror<\/i>() error, but all calls (whether successful or not) must return a pointer to a message string, on error <i>strerror<\/i>() can return a pointer to an empty string or a pointer to a meaningful string that can be printed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that the <b>[EINVAL]<\/b> error condition is a may fail error. If an invalid error number is supplied as the value of <i>errnum<\/i>, applications should be prepared to handle any of the following:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\">1.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p style=\"margin-top: 1em\">Error (with no meaningful message): <i>errno<\/i> is set to <b>[EINVAL]<\/b>, the return value is a pointer to an empty string.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>2.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>Successful completion: <i>errno<\/i> is unchanged and the return value points to a string like <b>&#8220;unknown<\/b>error&#8221; or <b>&#8220;error<\/b>number<b>xxx&#8221;<\/b> (where <i>xxx<\/i> is the value of <i>errnum<\/i>).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p>3.<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"83%\">\n<p>Combination of #1 and #2: <i>errno<\/i> is set to <b>[EINVAL]<\/b> and the return value points to a string like <b>&#8220;unknown<\/b>error&#8221; or <b>&#8220;error<\/b>number<b>xxx&#8221;<\/b> (where <i>xxx<\/i> is the value of <i>errnum<\/i>). Since applications frequently use the return value of <i>strerror<\/i>() as an argument to functions like <i>fprintf<\/i>() (without checking the return value) and since applications have no way to parse an error message string to determine whether <i>errnum<\/i> represents a valid error number, implementations are encouraged to implement #3. Similarly, implementations are encouraged to have <i>strerror_r<\/i>() return <b>[EINVAL]<\/b> and put a string like <b>&#8220;unknown<\/b>error&#8221; or <b>&#8220;error<\/b>number<b>xxx&#8221;<\/b> in the buffer pointed to by <i>strerrbuf<\/i> when the value of <i>errnum<\/i> is not a valid error number.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">Some applications rely on being able to set <i>errno<\/i> to 0 before calling a function with no reserved value to indicate an error, then call <i>strerror<\/i>(<i>errno<\/i>) afterwards to detect whether an error occurred (because <i>errno<\/i> changed) or to indicate success (because <i>errno<\/i> remained zero). This usage pattern requires that <i>strerror<\/i>(0) succeed with useful results. Previous versions of the standard did not specify the behavior when <i>errnum<\/i> is zero.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>perror<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><string.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; 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 .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  strerror, strerror_l, strerror_r \u2014 get error message string <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[1594,2207],"class_list":["post-5317","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-man3p","tag-strerror"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5317"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5317\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}