xref: /original-bsd/lib/libc/stdlib/atexit.3 (revision cba8738a)
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\" %sccs.include.redist.man%
7.\"
8.\"     @(#)atexit.3	5.2 (Berkeley) 04/19/91
9.\"
10.Dd
11.Dt ATEXIT 3
12.Os
13.Sh NAME
14.Nm atexit
15.Nd register a function to be called on exit
16.Sh SYNOPSIS
17.Fd #include <stdlib.h>
18.Ft int
19.Fn atexit "void (*function)(void)"
20.Sh DESCRIPTION
21The
22.Fn atexit
23function
24registers the given
25.Ar function
26to be called at program exit, whether via
27.Xr exit 3
28or via return from the program's
29.Em main .
30Functions so registered are called in reverse order;
31no arguments are passed.
32At least 32 functions can always be registered,
33and more are allowed as long as sufficient memory can be allocated.
34.Sh RETURN VALUES
35.Rv -std atexit
36.Sh ERRORS
37.Bl -tag -width [ENOMEM]
38.It Bq Er ENOMEM
39No memory was available to add the function to the list.
40The existing list of functions is unmodified.
41.El
42.Sh SEE ALSO
43.Xr exit 3
44.Sh STANDARDS
45The
46.Fn atexit
47function
48conforms to
49.St -ansiC .
50