Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
615 serge 1
/****************************************************************************
2
*
3
*                            Open Watcom Project
4
*
5
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
6
*
7
*  ========================================================================
8
*
9
*    This file contains Original Code and/or Modifications of Original
10
*    Code as defined in and that are subject to the Sybase Open Watcom
11
*    Public License version 1.0 (the 'License'). You may not use this file
12
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
13
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
14
*    provided with the Original Code and Modifications, and is also
15
*    available at www.sybase.com/developer/opensource.
16
*
17
*    The Original Code and all software distributed under the License are
18
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
20
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
21
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
22
*    NON-INFRINGEMENT. Please see the License for the specific language
23
*    governing rights and limitations under the License.
24
*
25
*  ========================================================================
26
*
27
* Description:  Module for adding functions to the atexit() list, as well
28
*               invoking the functions on library shutdown.
29
*
30
****************************************************************************/
31
 
32
 
33
#include "variety.h"
34
#include 
35
#include 
36
#include "rtdata.h"
37
#include "extfunc.h"
38
#include "rtinit.h"
39
 
40
#define EXIT_LIMIT      32
41
 
42
static  void    (* _HUGEDATA _ExitList[EXIT_LIMIT])( void );
43
static  int     _ExitCount;
44
 
45
int atexit( void (*func)( void ) )
46
{
47
    if( _ExitCount < EXIT_LIMIT ) {
48
        _ExitList[ _ExitCount++ ] = func;
49
        return( 0 );                /* indicate added successfully */
50
    }
51
    return( -1 );                   /* indicate no room */
52
}
53
 
54
typedef void exit_fn( void );
55
#if defined(_M_IX86)
56
    #pragma aux (__outside_CLIB) exit_fn;
57
#endif
58
 
59
static void _Full_at_exit_rtn( void )
60
{
61
    int         count;
62
    exit_fn     *func;
63
 
64
    count = _ExitCount;
65
    if( count == ( EXIT_LIMIT + 1 ) ) {
66
        return;                     /* already done once */
67
    }
68
    _ExitCount = EXIT_LIMIT + 1;    /* prevent others being registered */
69
    /* call functions in reverse order of their registration */
70
    while( count != 0 ) {
71
        --count;
72
        func = _ExitList[ count ];
73
        (*func)();                 /* invoke user exit routine */
74
    }
75
}
76
 
77
AYI( _Full_at_exit_rtn, INIT_PRIORITY_PROGRAM + 32 );