aboutsummaryrefslogtreecommitdiff
path: root/man/mlib_progname.3
blob: 98d6c872d6965a93d7be5d476996e027e322fb7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
.Dd 27 April 2024
.Dt MLIB_PROGNAME 3
.Os
.Sh NAME
.Nm mlib_progname ,
.Nm mlib_setprogname
.Nd get and set the program name
.Sh LIBRARY
.Lb mlib
.Sh SYNOPSIS
.In errors.h
.Ft "const char *"
.Fn mlib_progname void
.Ft void
.Fn mlib_setprogname "const char *s"
.Sh DESCRIPTION
The
.Fn mlib_progname
and
.Fn mlib_setprogname
functions can be used to get- and set the program name respectively.
The program name is a global c-string used by various diagnostic
functions such as
.Fn err
and
.Fn warn
in their generated diagnostic messages.
.Pp
The
.Fn mlib_progname
function returns a pointer to the global program name.
.Pp
The
.Fn mlib_setprogname
function sets the global program name to the null-terminated string
.Fa s .
This function is not thread-safe.
.Sh RETURN VALUES
The
.Fn mlib_progname
function returns a pointer to the global program name or
.Dv nullptr
if it hasn’t been set yet.
.Sh EXAMPLES
The following calls to
.Fn mlib_progname
and
.Fn mlib_setprogname
set the program name at the beginning of execution as is customary,
and then prints a usage error if no command-line arguments are specified.
.Bd -literal -offset indent
#include <stdio.h>
#include <stdlib.h>

#include <errors.h>

int
main(int argc, char **argv)
{
	mlib_setprogname(argv[0]);

	if (argc < 2) {
		fprintf(stderr, \(dqUsage: %s file ...\en\(dq, mlib_progname());
		exit(EXIT_FAILURE);
	}

	/* … */

	return EXIT_SUCCESS;
}
.Ed
.Sh SEE ALSO
.Xr err 3mlib ,
.Xr usage 3
.Sh AUTHORS
.An Thomas Voss Aq Mt mail@thomasvoss.com