FMTMSG(3POSIX)
π FMTMSG(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so before we even start: this page lives in the POSIX Programmer's Manual. Heads up though β the Linux implementation of this interface may differ from what POSIX says (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π
β¨ NAME β¨
fmtmsg β display a message in the specified format on standard error and/or a system console
π¦ SYNOPSIS π¦
#include <fmtmsg.h>
int fmtmsg(long classification, const char *label, int severity,
const char *text, const char *action, const char *tag);
π DESCRIPTION π
So fmtmsg() is literally the glow-up of printf() β it shall display messages in a specified format instead of doing the traditional printf() thing. periodt.
Based on the message's classification component, fmtmsg() shall write a formatted message either to standard error, to the console, or to both. main character energy, it does it all. β¨
A formatted message consists of up to five components, and here they are bestie:
classificationβ okay so this one is NOT part of the message that gets displayed to the user, but it defines where the message came from and directs how the formatted message gets displayed. It contains the sum of identifying values built from the constants below. You may use any one identifier from a subclass in combination with a single identifier from a different subclass. Two or more identifiers from the same subclass should not be used together β with the exception of identifiers from the display subclass (both display subclass identifiers may be used so messages can go to both standard error and the system console at once, iconic behavior honestly).- Major Classifications β identifies the source of the condition. Identifiers are:
MM_HARD(hardware),MM_SOFT(software), andMM_FIRM(firmware). - Message Source Subclassifications β identifies the type of software in which the problem is detected. Identifiers are:
MM_APPL(application),MM_UTIL(utility), andMM_OPSYS(operating system). - Display Subclassifications β indicates where the message is to be displayed. Identifiers are:
MM_PRINTto display the message on the standard error stream, andMM_CONSOLEto display the message on the system console. One or both identifiers may be used. - Status Subclassifications β indicates whether the application can recover from the condition. Identifiers are:
MM_RECOVER(recoverable) andMM_NRECOV(non-recoverable). - One more identifier for the road:
MM_NULLMCindicates that no classification component is supplied for the message. π«Ά
- Major Classifications β identifies the source of the condition. Identifiers are:
labelβ identifies the source of the message. The format is two fields separated by a<colon>. The first field is up to 10 bytes, the second is up to 14 bytes.severityβ indicates the seriousness of the condition. The identifiers for the levels of severity are:MM_HALTβ indicates that the application has encountered a severe fault and is halting. Produces the string"HALT". πMM_ERRORβ indicates that the application has detected a fault. Produces the string"ERROR".MM_WARNINGβ indicates a condition that is out of the ordinary, that might be a problem, and should be watched. Produces the string"WARNING". πMM_INFOβ provides information about a condition that is not in error. Produces the string"INFO".MM_NOSEVβ indicates that no severity level is supplied for the message.
textβ describes the error condition that produced the message. This character string is not limited to a specific size. If the character string is empty, then the text produced is unspecified.actionβ describes the first step to be taken in the error-recovery process. Thefmtmsg()function precedes the action string with the prefix"TOFIX:". The action string is not limited to a specific size.tagβ an identifier that references on-line documentation for the message. Suggested usage is thattagincludes the label and a unique identifying number. A sample tag is"XSI:cat:146".
Now, the MSGVERB environment variable (the "VERB" stands for message verbosity, cute right?) shall determine for fmtmsg() which message components it is to select when writing messages to standard error. The value of MSGVERB shall be a <colon>-separated list of optional keywords. The valid keywords are: label, severity, text, action, and tag.
- If
MSGVERBcontains a keyword for a component and that component's value is not the component's null value,fmtmsg()shall include that component in the message when writing the message to standard error. π - If
MSGVERBdoes not include a keyword for a message component, that component shall not be included in the display of the message. - The keywords may appear in any order, no gatekeeping here.
- If
MSGVERBis not defined, if its value is the null string, if its value is not of the correct format, or if it contains keywords other than the valid ones listed above βfmtmsg()shall select all components. so basically it defaults to giving you everything.
Important: MSGVERB shall determine which components are selected for display to standard error. All message components shall be included in console messages. no skipping, the console gets the whole story. π
π RETURN VALUE π
The fmtmsg() function shall return one of the following values:
MM_OKβ the function succeeded. slay. πMM_NOTOKβ the function failed completely. πMM_NOMSGβ the function was unable to generate a message on standard error, but otherwise succeeded.MM_NOCONβ the function was unable to generate a console message, but otherwise succeeded.
πΈ ERRORS πΈ
None. literally none. iconic.
The following sections are informative.
β EXAMPLES β
- The following example of
fmtmsg():
fmtmsg(MM_PRINT, "XSI:cat", MM_ERROR, "illegal option",
"refer to cat in user's reference manual", "XSI:cat:001")
produces a complete message in the specified message format:
XSI:cat: ERROR: illegal option
TO FIX: refer to cat in user's reference manual XSI:cat:001
- When the environment variable
MSGVERBis set as follows:
MSGVERB=severity:text:action
and Example 1 is used, fmtmsg() produces:
ERROR: illegal option
TO FIX: refer to cat in user's reference manual
see how the label and tag just vanished? that's MSGVERB doing its thing bestie. π
π APPLICATION USAGE π
One or more message components may be systematically omitted from messages generated by an application by using the null value of the argument for that component. easy peasy.
π§ RATIONALE π§
None.
π¦ FUTURE DIRECTIONS π¦
None.
π SEE ALSO π
fprintf()
And from The Base Definitions volume of POSIX.1β2017: <fmtmsg.h>
π COPYRIGHT π
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 .
and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017 β mwah, go forth and format your messages, you absolute icon πβ¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms