Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

get_progname(3pub) [debian man page]

ERRORMSG(3pub)															    ERRORMSG(3pub)

errormsg, set_progname, get_progname - printing error messages SYNOPSIS
#include <errormsg.h> void errormsg(int exitp, int eno, const char *fmt, ...); void set_progname(const char *argv0, const char *def); const char *get_progname(void); DESCRIPTION
The errormsg function is used for printing error messages. It is a like a combination of fprintf(3) and perror(3), in that it makes it easy to add arbitrary, printf-like formatted text to the output, and makes it easy to include the system's error message (the error string corresponding to the eno parameter). Unlike perror, this function does not get the error code directly from errno, thus making it easier to do something else that might set it before printing out the error message. errormsg also adds the name of the program to the output, if known. The first argument to errormsg should be 0 (don't exit program), 1 (exit program with exit(EXIT_FAILURE)) or 2 (with abort()). The second one should be 0 (don't print system error message), positive (print error message corresponding to the error code), or -1 (print the error message corresponding to errno). The set_progname function sets the program name. You need to call this function with at least one non-NULL parameter to get the program names included in the output. If either argument is non-NULL, it should point at strings that have static duration, i.e. they exist until the program terminates (or at least until the last error message has been printed); this is so that it is not necessary to create a copy of the name. (Either or both arguments can also be NULL.) If the first argument is non-NULL, that is used as the name, otherwise the seconds argument is used. If both are NULL, no program name is included in the output. The reason for having two arguments is so that the caller doesn't have to do the test, and can just call set_progname(argv[0], "default_name"); (it is valid for argv[0] to be NULL, under ISO C). The get_progname function returns a pointer to the current name of the program, as set by set_progname. If get_progname returns NULL, then no name has been set and none is included in the output. This function is included for completeness, it is not really expected to be use- ful. SEE ALSO
publib(3) AUTHOR
Lars Wirzenius ( ERRORMSG(3pub)

Check Out this Related Man Page

XMALLOC(3pub)						       C Programmer's Manual						     XMALLOC(3pub)

xmalloc, xrealloc, xfree, xstrdup, xmemdup, memdup - memory allocation functions for Publib SYNOPSIS
#include <publib.h> void *xmalloc(size_t bytes); void *xrealloc(void *ptr, size_t bytes); void xfree(void *ptr); char *xstrdup(const char *string); void *memdup(const void *mem, size_t bytes); void *xmemdup(const void *mem, size_t bytes); DESCRIPTION
These functions are utility functions for memory allocation from the publib library. xmalloc, xrealloc, and xfree are error checking ver- sions of the standard library routines malloc, realloc, and free, respectively. They are guaranteed to never return unless there was no problem: if, for example, xmalloc is unable to allocate the requested amount of memory, it prints an error message and terminates the pro- gram. Hence, the caller does not need to check for a NULL return value, and the code that calls these functions is simpler due to the lack of error checks. Similarly, xstrdup is an error checking version of the common (though not standard) strdup routine, which creates a duplicate of a string by allocating memory for the copy with malloc. (For systems that lack strdup, publib provides one in its portability module; it is always declared in <publib.h>.) memdup is similar to strdup, it creates a copy of an arbitrary memory area (the arguments are a pointer to the beginning of the area, and its size) by allocating memory for the copy with malloc. xmemdup is its error checking version. NOTE
xmalloc and xrealloc treat a request to allocate a block of 0 bytes as an error. xrealloc will allow its first argument to be NULL. SEE ALSO
publib(3), malloc(3), strdup(3) AUTHOR
Lars Wirzenius ( Publib C Programmer's Manual XMALLOC(3pub)
Man Page

Featured Tech Videos