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