]> pd.if.org Git - pdclib.old/blob - man3/atexit.3
Add _cbprintf/_vcbprintf (callback based printf formatters)
[pdclib.old] / man3 / atexit.3
1 .\" This file is part of the Public Domain C Library (PDCLib).\r
2 .\" Permission is granted to use, modify, and / or redistribute at will.\r
3 .\"\r
4 .Dd\r
5 .Dt atexit 3\r
6 .Os\r
7 .\"\r
8 .Sh NAME\r
9 .Nm atexit\r
10 .Nd registration of functions to be invoked before process termination\r
11 .\"\r
12 .Sh SYNOPSIS\r
13 .In stdlib.h\r
14 .Fn "int atexit" "void (*handler)(void)"\r
15 .Fn "int at_quick_exit" "void (*handler)(void)" \r
16 (C11, C++11)\r
17 .\"\r
18 .Sh DESCRIPTION\r
19 These functions register a function to be called when the corresponding process\r
20 exit function is invoked. For\r
21 .Fn atexit \r
22 the function will be invoked when the process is terminated by calling\r
23 .Fn exit ;\r
24 for\r
25 .Fn at_quick_exit\r
26 the function will be invoked when the process is terminated by calling\r
27 .Fn quick_exit .\r
28 .\"\r
29 .Pp\r
30 These functions are used in order to permit a program to perform actions before\r
31 a process is terminated; for example, releasing an interprocess semaphore. \r
32 Special care should be taken when writing \r
33 .Fn at_quick_exit\r
34 handlers; the purpose of \r
35 .Fn quick_exit\r
36 is to support the abandonning of a process when normal process termination might\r
37 not be possible; at_quick_exit handlers should therefore be used sparingly and\r
38 only when their use is essential.\r
39 .\"\r
40 .Pp\r
41 The standard guarantees that \r
42 .Fn atexit\r
43 and\r
44 .Fn at_quick_exit\r
45 may each be called at least 32 times successfully.\r
46 .\"\r
47 .Pp\r
48 .Fn atexit \r
49 and\r
50 .Fn at_quick_exit\r
51 handlers are called in reverse order of the order they were registered in. For\r
52 precise details of their ordering, see\r
53 .Xr exit 3 .\r
54 .\"\r
55 .Pp\r
56 The result of exiting from a handler registered with\r
57 .Fn atexit\r
58 or\r
59 .Fn at_quick_exit\r
60 by use of \r
61 .Fn longjmp\r
62 is undefined. If any function or destructor invoked by\r
63 .Fn exit\r
64 or\r
65 .Fn quick_exit\r
66 should throw, \r
67 .Fn std::terminate\r
68 is invoked.\r
69 .\"\r
70 .Pp\r
71 Undefined behaviour results if an \r
72 .Fn atexit\r
73 or\r
74 .Fn at_quick_exit\r
75 handler calls\r
76 .Fn exit\r
77 or\r
78 .Fn quick_exit . \r
79 .\"\r
80 .Sh RETURN VALUES\r
81 Returns 0 to indicate success; nonzero returns indicate failure.\r
82 .\"\r
83 .Sh ERRORS\r
84 No errors are defined\r
85 .\"\r
86 .Sh SEE ALSO\r
87 .Xr abort 3\r
88 .Xr exit 3\r
89 .Xr quick_exit 3\r
90 .Xr _Exit 3\r
91 .\"\r
92 .Sh STANDARDS\r
93 .Fn atexit\r
94 is first defined in\r
95 .St -isoC-90 ;\r
96 .Fn at_quick_exit\r
97 was introduced in\r
98 .St -isoC-2011 \r
99 and\r
100 ISO/IEC 14882:2011 "C++ 2011" .