UDERRMSG(3)
π NAME π
okay so bestie, meet the Unidata error-messaging package: uderrmsg, uderrmode, uderrname, uderror, udadvise, udtime_stamp πΈ
it's giving "tell the user what went wrong, but make it Unidata-standard" and honestly? iconic.
β¨ SYNOPSIS β¨
#include "uderrmsg.h"
int uderrmode(const int mode);
char* uderrname(const char *name);
void uderror(const char *fmt, ...);
void udadvise(const char *fmt, ...);
char* udtime_stamp(void);
#define UD_FATAL
#define UD_VERBOSE
π«Ά DESCRIPTION π«Ά
these routines are the whole Unidata error-messaging mechanism, and no cap, every single piece of Unidata-conforming software should be using them. it's literally the group chat everyone's supposed to be in π
uderrmode() β the vibe-setter π
uderrmode() sets the mode of the error-messaging package and hands you back the previous mode. the mode is the bitwise or of zero or more of the bit-set macro-constants below. setting a mode-bit turns the action on, and vice versa (unset it, it's off, periodt).
UD_FATALβuderror()andudadvise()will straight up abort the program after printing any error message. dramatic? yes. intentional? also yes πUD_VERBOSEβuderror()andudadvise()will print all the messages. every last one. no holding back π£οΈ
the default is UD_FATAL | UD_VERBOSE. so yeah, loud and lethal by default, main character energy fr fr.
uderrname() β who even are you π¬
uderrname() sets the program name that gets used in all the messages, and returns the previous name. you should call it once, at the beginning of each program, passing like argv[0] as the argument. (and psst β the udres(3) function udinit() already does this for you, so you don't gotta π)
uderror() β the perror(3) glow-up π
uderror() prints a system error message on stderr if, and only if, the UD_VERBOSE mode-bit is set. this one's the replacement for perror(3), and you call it when a system function returns an error status.
the error message is a whole little ensemble cast: the program name, the error message you passed as arguments to uderror(), the system error message, and the system error number. the argument syntax is exactly the same as printf(3).
if the error-messaging package has the UD_FATAL mode-bit set, this routine will abort after printing the message. like, that's it, we're done here π
and bestie, important: errno is cleared before returning. noted. don't forget it.
if stderr is not a tty, then the error message gets prefixed by a time-stamp β°
udadvise() β the gentle heads-up π¦
udadvise() prints on stderr an error message made of fmt plus any other arguments, if, and only if, the UD_VERBOSE mode-bit is set. syntax is the same as printf(3), you already know.
if the error-messaging package has the UD_FATAL mode-bit set, then this routine will abort after printing the message too. same energy, same consequences π
if stderr is not a tty, then the error message gets prefixed by a time-stamp β°
udtime_stamp() β the clock app of this package π°οΈ
udtime_stamp() returns a pointer to a static buffer containing a 0-terminated string of the current time, in the Unidata-standard format. cute, standardised, done β¨
π EXAMPLE π
so if uderrname was called with the argument foobar, then this code right here:
#include "guise.h"
#include "uderrmsg.h"
...
output()
{
static char me[] = "output"; /* This routine's name */
...
uderrmode(UD_VERBOSE);
if (!allowed) {
udadvise("%s: Writing to output file not allowed", me);
} else if (write(fd, buf, nbyte) == -1) {
uderror(me);
udadvise("%s: Couldn't write %d bytes to output file", me, nbyte);
} else {
...
will print this error message if allowed is false:
foobar: output: Writing to output file not allowed
and might print these if the write(2) fails:
foobar: output: no space left on device (errno=28)
foobar: output: Couldn't write 100000 bytes to output file
see how the program name and the routine name just show up automatically? we love a self-assembling message π
π SEE ALSO π
udres(3), udape(3).
go read those too, bestie, iykyk π«Ά
okay and for the little sign-off moment: this whole thing was printed on 20 September 1990 (that's 126.10.12 in the printed-date universe, slay), it's from the UNIDATA LIBRARY FUNCTIONS manual, and the page is UDERRMSG(3). vintage but make it useful πβ¨π
π¦ where this page comes from
- debian bookworm: libxgks-dev 2.6.1+dfsg.2-12
- debian trixie: libxgks-dev 2.6.1+dfsg.2-17
- ubuntu jammy: libxgks-dev 2.6.1+dfsg.2-12
- ubuntu noble: libxgks-dev 2.6.1+dfsg.2-15
- ubuntu questing: libxgks-dev 2.6.1+dfsg.2-19ubuntu1
- ubuntu resolute: libxgks-dev 2.6.1+dfsg.2-19ubuntu2
- ubuntu stonking: libxgks-dev 2.6.1+dfsg.2-19ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms