ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

atexit.c
Go to the documentation of this file.
00001 /* taken from wine exit.c */
00002 #include <precomp.h>
00003 
00004 _onexit_t *atexit_table = NULL;
00005 int atexit_table_size = 0;
00006 int atexit_registered = 0; /* Points to free slot */
00007 
00008 /* INTERNAL: call atexit functions */
00009 void __call_atexit(void)
00010 {
00011   /* Note: should only be called with the exit lock held */
00012   TRACE("%d atext functions to call\n", atexit_registered);
00013   /* Last registered gets executed first */
00014   while (atexit_registered > 0)
00015   {
00016     atexit_registered--;
00017     TRACE("next is %p\n",atexit_table[atexit_registered]);
00018     if (atexit_table[atexit_registered])
00019       (*atexit_table[atexit_registered])();
00020     TRACE("returned\n");
00021   }
00022 }
00023 
00024 /*********************************************************************
00025  *      __dllonexit (MSVCRT.@)
00026  */
00027 _onexit_t CDECL __dllonexit(_onexit_t func, _onexit_t **start, _onexit_t **end)
00028 {
00029    _onexit_t *tmp;
00030    size_t len;
00031 
00032   TRACE("(%p,%p,%p)\n", func, start, end);
00033 
00034   if (!start || !*start || !end || !*end)
00035   {
00036    FIXME("bad table\n");
00037    return NULL;
00038   }
00039 
00040   len = (*end - *start);
00041 
00042   TRACE("table start %p-%p, %d entries\n", *start, *end, len);
00043 
00044   if (++len <= 0)
00045     return NULL;
00046 
00047   tmp = realloc(*start, len * sizeof(tmp));
00048   if (!tmp)
00049     return NULL;
00050   *start = tmp;
00051   *end = tmp + len;
00052   tmp[len - 1] = func;
00053   TRACE("new table start %p-%p, %d entries\n", *start, *end, len);
00054   return func;
00055 }
00056 
00057 /*********************************************************************
00058  *      _onexit (MSVCRT.@)
00059  */
00060 _onexit_t CDECL _onexit(_onexit_t func)
00061 {
00062   TRACE("(%p)\n",func);
00063 
00064   if (!func)
00065     return NULL;
00066 
00067   LOCK_EXIT;
00068   if (atexit_registered > atexit_table_size - 1)
00069   {
00070     _onexit_t *newtable;
00071     TRACE("expanding table\n");
00072     newtable = calloc(sizeof(void *),atexit_table_size + 32);
00073     if (!newtable)
00074     {
00075       TRACE("failed!\n");
00076       UNLOCK_EXIT;
00077       return NULL;
00078     }
00079     memcpy (newtable, atexit_table, atexit_table_size);
00080     atexit_table_size += 32;
00081     free (atexit_table);
00082     atexit_table = newtable;
00083   }
00084   atexit_table[atexit_registered] = func;
00085   atexit_registered++;
00086   UNLOCK_EXIT;
00087   return func;
00088 }
00089 
00090 /*********************************************************************
00091  *      atexit (MSVCRT.@)
00092  */
00093 int CDECL atexit(void (*func)(void))
00094 {
00095   TRACE("(%p)\n", func);
00096   return _onexit((_onexit_t)func) == (_onexit_t)func ? 0 : -1;
00097 }
00098 

Generated on Sat May 26 2012 04:35:35 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.