OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [atexit.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/*
2
 * Copyright (c) 1990 Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * %sccs.include.redist.c%
6
 */
7
 
8
/*
9
FUNCTION
10
<<atexit>>---request execution of functions at program exit
11
 
12
INDEX
13
        atexit
14
 
15
ANSI_SYNOPSIS
16
        #include <stdlib.h>
17 56 joel
        int atexit (void (*<[function]>)(void));
18 39 lampret
 
19
TRAD_SYNOPSIS
20
        #include <stdlib.h>
21 56 joel
        int atexit ((<[function]>)
22
          void (*<[function]>)();
23 39 lampret
 
24
DESCRIPTION
25
You can use <<atexit>> to enroll functions in a list of functions that
26
will be called when your program terminates normally.  The argument is
27
a pointer to a user-defined function (which must not require arguments and
28
must not return a result).
29
 
30
The functions are kept in a LIFO stack; that is, the last function
31
enrolled by <<atexit>> will be the first to execute when your program
32
exits.
33
 
34
There is no built-in limit to the number of functions you can enroll
35
in this list; however, after every group of 32 functions is enrolled,
36
<<atexit>> will call <<malloc>> to get space for the next part of the
37
list.   The initial list of 32 functions is statically allocated, so
38
you can always count on at least that many slots available.
39
 
40
RETURNS
41
<<atexit>> returns <<0>> if it succeeds in enrolling your function,
42
<<-1>> if it fails (possible only if no space was available for
43
<<malloc>> to extend the list of functions).
44
 
45
PORTABILITY
46
<<atexit>> is required by the ANSI standard, which also specifies that
47
implementations must support enrolling at least 32 functions.
48
 
49
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
50
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
51
*/
52
 
53
#include <stddef.h>
54
#include <stdlib.h>
55
#include <reent.h>
56
 
57
/*
58
 * Register a function to be performed at exit.
59
 */
60
 
61
int
62
_DEFUN (atexit,
63
        (fn),
64
        _VOID _EXFUN ((*fn), (_VOID)))
65
{
66
  register struct _atexit *p;
67
 
68
  if ((p = _REENT->_atexit) == NULL)
69
    _REENT->_atexit = p = &_REENT->_atexit0;
70
  if (p->_ind >= _ATEXIT_SIZE)
71
    {
72
      if ((p = (struct _atexit *) malloc (sizeof *p)) == NULL)
73
        return -1;
74
      p->_ind = 0;
75
      p->_next = _REENT->_atexit;
76
      _REENT->_atexit = p;
77
    }
78
  p->_fns[p->_ind++] = fn;
79
  return 0;
80
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.