{"id":6917,"date":"2022-12-20T19:34:20","date_gmt":"2022-12-20T22:34:20","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/fmtmsg-man3\/"},"modified":"2022-12-20T19:34:20","modified_gmt":"2022-12-20T22:34:20","slug":"fmtmsg-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/fmtmsg-man3\/","title":{"rendered":"FMTMSG (man3)"},"content":{"rendered":"<h1 align=\"center\">FMTMSG<\/h1>\n<p> <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=\"#ENVIRONMENT\">ENVIRONMENT<\/a><br \/> <a href=\"#VERSIONS\">VERSIONS<\/a><br \/> <a href=\"#ATTRIBUTES\">ATTRIBUTES<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">fmtmsg \u2212 print formatted error messages<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <fmtmsg.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int fmtmsg(long<\/b> <i>classification<\/i><b>, const char *<\/b><i>label<\/i><b>, <br \/> int<\/b> <i>severity<\/i><b>, const char *<\/b><i>text<\/i><b>, <br \/> const char *<\/b><i>action<\/i><b>, const char *<\/b><i>tag<\/i><b>);<\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This function displays a message described by its arguments on the device(s) specified in the <i>classification<\/i> argument. For messages written to <i>stderr<\/i>, the format depends on the <b>MSGVERB<\/b> environment variable.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>label<\/i> argument identifies the source of the message. The string must consist of two colon separated parts where the first part has not more than 10 and the second part not more than 14 characters.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>text<\/i> argument describes the condition of the error.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>action<\/i> argument describes possible steps to recover from the error. If it is printed, it is prefixed by &#8220;TO FIX: &#8220;.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>tag<\/i> argument is a reference to the online documentation where more information can be found. It should contain the <i>label<\/i> value and a unique identification number.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Dummy arguments<\/b> <br \/> Each of the arguments can have a dummy value. The dummy classification value <b>MM_NULLMC<\/b> (0L) does not specify any output, so nothing is printed. The dummy severity value <b>NO_SEV<\/b> (0) says that no severity is supplied. The values <b>MM_NULLLBL<\/b>, <b>MM_NULLTXT<\/b>, <b>MM_NULLACT<\/b>, <b>MM_NULLTAG<\/b> are synonyms for <i>((char\u00a0*)\u00a00)<\/i>, the empty string, and <b>MM_NULLSEV<\/b> is a synonym for <b>NO_SEV<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>The classification argument<\/b> <br \/> The <i>classification<\/i> argument is the sum of values describing 4 types of information.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The first value defines the output channel.<\/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=\"15%\">\n<p><b>MM_PRINT<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"45%\">\n<p>Output to <i>stderr<\/i>.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"15%\">\n<p><b>MM_CONSOLE<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"45%\">\n<p>Output to the system console.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>MM_PRINT | MM_CONSOLE<\/b><\/p>\n<p style=\"margin-left:29%;\">Output to both.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The second value is the source of the error:<\/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=\"11%\">\n<p><b>MM_HARD<\/b><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"40%\">\n<p>A hardware error occurred.<\/p>\n<\/td>\n<td width=\"31%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><b>MM_FIRM<\/b><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"40%\">\n<p>A firmware error occurred.<\/p>\n<\/td>\n<td width=\"31%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><b>MM_SOFT<\/b><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"40%\">\n<p>A software error occurred.<\/p>\n<\/td>\n<td width=\"31%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The third value encodes the detector of the problem:<\/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=\"12%\">\n<p style=\"margin-top: 1em\"><b>MM_APPL<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"60%\">\n<p style=\"margin-top: 1em\">It is detected by an application.<\/p>\n<\/td>\n<td width=\"11%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><b>MM_UTIL<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"60%\">\n<p>It is detected by a utility.<\/p>\n<\/td>\n<td width=\"11%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><b>MM_OPSYS<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"60%\">\n<p>It is detected by the operating system.<\/p>\n<\/td>\n<td width=\"11%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The fourth value shows the severity of the incident:<\/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=\"15%\">\n<p style=\"margin-top: 1em\"><b>MM_RECOVER<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"45%\">\n<p style=\"margin-top: 1em\">It is a recoverable error.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"15%\">\n<p><b>MM_NRECOV<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"45%\">\n<p>It is a nonrecoverable error.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>The severity argument<\/b> <br \/> The <i>severity<\/i> argument can take one of the following values:<\/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=\"15%\">\n<p style=\"margin-top: 1em\"><b>MM_NOSEV<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"51%\">\n<p style=\"margin-top: 1em\">No severity is printed.<\/p>\n<\/td>\n<td width=\"20%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"15%\">\n<p><b>MM_HALT<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"51%\">\n<p>This value is printed as HALT.<\/p>\n<\/td>\n<td width=\"20%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"15%\">\n<p><b>MM_ERROR<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"51%\">\n<p>This value is printed as ERROR.<\/p>\n<\/td>\n<td width=\"20%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"15%\">\n<p><b>MM_WARNING<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"51%\">\n<p>This value is printed as WARNING.<\/p>\n<\/td>\n<td width=\"20%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"15%\">\n<p><b>MM_INFO<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"51%\">\n<p>This value is printed as INFO.<\/p>\n<\/td>\n<td width=\"20%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The numeric values are between 0 and 4. Using <b>addseverity<\/b>(3) or the environment variable <b>SEV_LEVEL<\/b> you can add more levels and strings to print.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The function can return 4 values:<\/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=\"12%\">\n<p style=\"margin-top: 1em\"><b>MM_OK<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"45%\">\n<p style=\"margin-top: 1em\">Everything went smooth.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><b>MM_NOTOK<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"45%\">\n<p>Complete failure.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><b>MM_NOMSG<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"45%\">\n<p>Error writing to <i>stderr<\/i>.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p><b>MM_NOCON<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"45%\">\n<p>Error writing to the console.<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>ENVIRONMENT <a name=\"ENVIRONMENT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The environment variable <b>MSGVERB<\/b> (&#8220;message verbosity&#8221;) can be used to suppress parts of the output to <i>stderr<\/i>. (It does not influence output to the console.) When this variable is defined, is non-NULL, and is a colon-separated list of valid keywords, then only the parts of the message corresponding to these keywords is printed. Valid keywords are &#8220;label&#8221;, &#8220;severity&#8221;, &#8220;text&#8221;, &#8220;action&#8221; and &#8220;tag&#8221;.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The environment variable <b>SEV_LEVEL<\/b> can be used to introduce new severity levels. By default, only the five severity levels described above are available. Any other numeric value would make <b>fmtmsg<\/b>() print nothing. If the user puts <b>SEV_LEVEL<\/b> with a format like<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">SEV_LEVEL=[description[:description[:&#8230;]]]<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">in the environment of the process before the first call to <b>fmtmsg<\/b>(), where each description is of the form<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">severity-keyword,level,printstring<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">then <b>fmtmsg<\/b>() will also accept the indicated values for the level (in addition to the standard levels 0\u20134), and use the indicated printstring when such a level occurs.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The severity-keyword part is not used by <b>fmtmsg<\/b>() but it has to be present. The level part is a string representation of a number. The numeric value must be a number greater than 4. This value must be used in the severity argument of <b>fmtmsg<\/b>() to select this class. It is not possible to overwrite any of the predefined classes. The printstring is the string printed when a message of this class is processed by <b>fmtmsg<\/b>().<\/p>\n<h2>VERSIONS <a name=\"VERSIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>fmtmsg<\/b>() is provided in glibc since version 2.1.<\/p>\n<h2>ATTRIBUTES <a name=\"ATTRIBUTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For an explanation of the terms used in this section, see <b>attributes<\/b>(7).<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-1639561.png\" alt=\"Image grohtml-1639561.png\"><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Before glibc 2.16, the <b>fmtmsg<\/b>() function uses a static variable that is not protected, so it is not thread-safe.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Since glibc 2.16, the <b>fmtmsg<\/b>() function uses a lock to protect the static variable, so it is thread-safe.<\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The functions <b>fmtmsg<\/b>() and <b>addseverity<\/b>(3), and environment variables <b>MSGVERB<\/b> and <b>SEV_LEVEL<\/b> come from System V.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The function <b>fmtmsg<\/b>() and the environment variable <b>MSGVERB<\/b> are described in POSIX.1-2001 and POSIX.1-2008.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">System V and UnixWare man pages tell us that these functions have been replaced by &#8220;pfmt() and addsev()&#8221; or by &#8220;pfmt(), vpfmt(), lfmt(), and vlfmt()&#8221;, and will be removed later.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <stdio.h> <br \/> #include <stdlib.h> <br \/> #include <fmtmsg.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <br \/> main(void) <br \/> { <br \/> long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER; <br \/> int err;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">err = fmtmsg(class, &#8220;util\u2212linux:mount&#8221;, MM_ERROR, <br \/> &#8220;unknown mount option&#8221;, &#8220;See mount(8).&#8221;, <br \/> &#8220;util\u2212linux:mount:017&#8221;); <br \/> switch (err) { <br \/> case MM_OK: <br \/> break; <br \/> case MM_NOTOK: <br \/> printf(&#8220;Nothing printedn&#8221;); <br \/> break; <br \/> case MM_NOMSG: <br \/> printf(&#8220;Nothing printed to stderrn&#8221;); <br \/> break; <br \/> case MM_NOCON: <br \/> printf(&#8220;No console outputn&#8221;); <br \/> break; <br \/> default: <br \/> printf(&#8220;Unknown error from fmtmsg()n&#8221;); <br \/> } <br \/> exit(EXIT_SUCCESS); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The output should be:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">util\u2212linux:mount: ERROR: unknown mount option <br \/> TO FIX: See mount(8). util\u2212linux:mount:017<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">and after<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">MSGVERB=text:action; export MSGVERB<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">the output becomes:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">unknown mount option <br \/> TO FIX: See mount(8).<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>addseverity<\/b>(3), <b>perror<\/b>(3)<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  fmtmsg \u2212 print formatted error messages <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,2161,3007],"class_list":["post-6917","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-fmtmsg","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6917","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=6917"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6917\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}