Mercurial > ecos
annotate packages/language/c/libc/current/src/stdlib/atexit.cxx @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | 443894e2e912 |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 0 | 1 //======================================================================== |
| 2 // | |
| 3 // atexit.cxx | |
| 4 // | |
| 5 // Implementation of the atexit() function | |
| 6 // | |
| 7 //======================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
14 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
16 // Software distributed under the License is distributed on an |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //======================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): jlarmour | |
| 2 | 35 // Contributors: jlarmour |
| 0 | 36 // Date: 1998-08-31 |
| 37 // Purpose: | |
| 38 // Description: | |
| 39 // Usage: | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 43 //======================================================================== | |
| 44 | |
| 45 // CONFIGURATION | |
| 46 | |
| 47 #include <pkgconf/libc.h> // Configuration header | |
| 48 | |
| 2 | 49 // Include atexit() ? |
| 50 #ifdef CYGFUN_LIBC_ATEXIT | |
| 0 | 51 |
| 52 // INCLUDES | |
| 53 | |
| 54 #include <cyg/infra/cyg_type.h> // Common type definitions and support | |
| 55 #include <cyg/infra/cyg_trac.h> // Common tracing support | |
| 56 #include <cyg/infra/cyg_ass.h> // Common assertion support | |
| 57 #include <stdlib.h> // Header for all stdlib functions | |
| 58 // (like this one) | |
| 59 #include "clibincl/stdlibsupp.hxx" // Support for stdlib functions | |
| 60 | |
| 61 // SYMBOLS | |
| 62 | |
| 63 externC int | |
| 2 | 64 atexit( Cyg_libc_atexit_fn_t ) CYGBLD_ATTRIB_WEAK_ALIAS(_atexit); |
| 0 | 65 |
| 66 | |
| 67 // STATICS | |
| 68 | |
| 69 // cyg_libc_atexit_handlers contains the functions to call. | |
| 70 // cyg_libc_atexit_handlers_count contains the number of valid handlers | |
| 71 // or you can consider the next free handler slot in | |
| 72 // cyg_libc_atexit_handlers. | |
| 73 | |
| 2 | 74 static Cyg_libc_atexit_fn_t |
| 0 | 75 cyg_libc_atexit_handlers[ CYGNUM_LIBC_ATEXIT_HANDLERS ]; |
| 76 | |
| 77 static cyg_ucount32 cyg_libc_atexit_handlers_count; | |
| 78 | |
| 79 | |
| 80 // FUNCTIONS | |
| 81 | |
| 82 externC void | |
| 83 cyg_libc_invoke_atexit_handlers( void ) | |
| 84 { | |
| 2 | 85 CYG_REPORT_FUNCNAME( "cyg_libc_invoke_atexit_handlers"); |
| 0 | 86 CYG_REPORT_FUNCARGVOID(); |
| 87 | |
| 88 cyg_ucount32 i; | |
| 89 | |
| 90 for (i=cyg_libc_atexit_handlers_count; i>0; --i) { | |
| 91 | |
| 92 CYG_TRACE1( true, | |
| 93 "Calling function registered with atexit at addr %08x", | |
| 94 cyg_libc_atexit_handlers[i-1] ); | |
| 95 CYG_CHECK_FUNC_PTR( cyg_libc_atexit_handlers[i-1], | |
| 96 "Function to call in atexit handler list " | |
| 97 "isn't valid! Even though it was when " | |
| 98 "entered!" ); | |
| 99 | |
| 100 (*cyg_libc_atexit_handlers[i-1])(); | |
| 101 | |
| 102 } // for | |
| 103 | |
| 104 CYG_REPORT_RETURN(); | |
| 105 } // cyg_libc_invoke_atexit_handlers() | |
| 106 | |
| 107 | |
| 108 externC int | |
| 2 | 109 _atexit( Cyg_libc_atexit_fn_t func_to_register ) |
| 0 | 110 { |
| 111 CYG_REPORT_FUNCNAMETYPE( "_atexit", "returning %d" ); | |
| 112 CYG_REPORT_FUNCARG1XV( func_to_register ); | |
| 113 | |
| 114 CYG_CHECK_FUNC_PTR( func_to_register, | |
| 115 "_atexit() not passed a valid function argument!" ); | |
| 116 | |
| 117 // have we any slots left? | |
| 118 if (cyg_libc_atexit_handlers_count >= | |
| 2 | 119 sizeof(cyg_libc_atexit_handlers)/sizeof(Cyg_libc_atexit_fn_t) ) { |
| 0 | 120 |
| 121 CYG_REPORT_RETVAL( 1 ); | |
| 122 return 1; // failure | |
| 123 } // if | |
| 124 | |
| 125 cyg_libc_atexit_handlers[cyg_libc_atexit_handlers_count++] = | |
| 126 func_to_register; | |
| 127 | |
| 128 CYG_REPORT_RETVAL(0); | |
| 129 return 0; | |
| 130 } // _atexit() | |
| 131 | |
| 132 | |
| 2 | 133 #endif // ifdef CYGFUN_LIBC_ATEXIT |
| 0 | 134 |
| 135 // EOF atexit.cxx |
