blob: 01127d4e0cf7a2a6657cd60d54c39f212a5b20e5 (
plain)
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
|
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include "_stdlib.h"
/** register a function to run at quick exit **/
int at_quick_exit(void (*func)(void))
{
__C_MIN(201112L);
if (__stdlib.nat_quick_exit >= ATEXIT_MAX) {
return 1;
}
if (__stdlib.at_quick_exit == NULL) {
__stdlib.at_quick_exit = calloc(1,
sizeof(*__stdlib.at_quick_exit));
if (__stdlib.at_quick_exit == NULL) {
errno = ENOMEM;
return 1;
}
__stdlib.at_quick_exit->fn = func;
__stdlib.nat_quick_exit = 1;
return 0;
}
__stdlib.at_quick_exit->next = calloc(1,
sizeof(*__stdlib.at_quick_exit->next));
if (__stdlib.at_quick_exit->next == NULL) {
errno = ENOMEM;
return 1;
}
__stdlib.at_quick_exit->next->fn = func;
__stdlib.at_quick_exit->next->prev = __stdlib.at_quick_exit;
__stdlib.at_quick_exit = __stdlib.at_quick_exit->next;
__stdlib.nat_quick_exit++;
return 0;
}
/***
The fn(at_quick_exit) registers the function arg(func) to be called when the
program exits via fn(quick_exit). The function must take no parameters.
***/
/* UNSPECIFIED: - */
/* UNDEFINED: - */
/* IMPLEMENTATION: the number of registrations allowed (at least 32) */
/* LOCALE: - */
/* RETURN(0): success */
/* RETURN(NZ): failure */
/*
STDC(201112)
*/
|