getenv: Remove check for non-standard endianness.
[glibc.git] / stdlib / exit.c
blobe9a2139f4eef6c33f55fe8c4a53ddccba99e0403
1 /* Copyright (C) 1991-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <sysdep.h>
22 #include "exit.h"
24 #include "set-hooks.h"
25 DEFINE_HOOK (__libc_atexit, (void))
28 /* Call all functions registered with `atexit' and `on_exit',
29 in the reverse of the order in which they were registered
30 perform stdio cleanup, and terminate program execution with STATUS. */
31 void
32 attribute_hidden
33 __run_exit_handlers (int status, struct exit_function_list **listp,
34 bool run_list_atexit)
36 /* We do it this way to handle recursive calls to exit () made by
37 the functions registered with `atexit' and `on_exit'. We call
38 everyone on the list and use the status value in the last
39 exit (). */
40 while (*listp != NULL)
42 struct exit_function_list *cur = *listp;
44 while (cur->idx > 0)
46 const struct exit_function *const f =
47 &cur->fns[--cur->idx];
48 switch (f->flavor)
50 void (*atfct) (void);
51 void (*onfct) (int status, void *arg);
52 void (*cxafct) (void *arg, int status);
54 case ef_free:
55 case ef_us:
56 break;
57 case ef_on:
58 onfct = f->func.on.fn;
59 #ifdef PTR_DEMANGLE
60 PTR_DEMANGLE (onfct);
61 #endif
62 onfct (status, f->func.on.arg);
63 break;
64 case ef_at:
65 atfct = f->func.at;
66 #ifdef PTR_DEMANGLE
67 PTR_DEMANGLE (atfct);
68 #endif
69 atfct ();
70 break;
71 case ef_cxa:
72 cxafct = f->func.cxa.fn;
73 #ifdef PTR_DEMANGLE
74 PTR_DEMANGLE (cxafct);
75 #endif
76 cxafct (f->func.cxa.arg, status);
77 break;
81 *listp = cur->next;
82 if (*listp != NULL)
83 /* Don't free the last element in the chain, this is the statically
84 allocate element. */
85 free (cur);
88 if (run_list_atexit)
89 RUN_HOOK (__libc_atexit, ());
91 _exit (status);
95 void
96 exit (int status)
98 __run_exit_handlers (status, &__exit_funcs, true);
100 libc_hidden_def (exit)