atexit.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 1k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. //  File:       atexit.cxx
  7. //
  8. //  Contents:   Provides our own implementation of the atexit function
  9. //
  10. //----------------------------------------------------------------------------
  11. #define _CRTBLD 1
  12. #include "windows.h"
  13. typedef void (__cdecl *_PVFV)(void);
  14. extern int      _cpvfv = 0;
  15. extern _PVFV *  _apvfv = NULL;
  16. int __cdecl atexit(_PVFV pfunc)
  17. {
  18.     int rc = 1;
  19.     if ((_cpvfv % 8) == 0)
  20.     {
  21.         if (_apvfv)
  22.         {
  23.             _PVFV * p = (_PVFV *) LocalReAlloc(_apvfv, (_cpvfv + 8) * sizeof(_PVFV), LMEM_MOVEABLE);
  24.             if (_apvfv == NULL)
  25.                 goto Error;
  26.             _apvfv = p;
  27.         }
  28.         else
  29.         {
  30.             _apvfv = (_PVFV *) LocalAlloc(LPTR, (_cpvfv + 8) * sizeof(_PVFV));
  31.             if (_apvfv == NULL)
  32.                 goto Error;
  33.         }
  34.     }
  35.     _apvfv[_cpvfv++] = pfunc;
  36. Cleanup:
  37.     return rc;
  38. Error:
  39.     rc = 0;
  40.     _cpvfv = 0;
  41.     goto Cleanup;
  42. }