Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  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:  Platform independent __allocfp() implementation.
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include <stdio.h>
  34. #include "liballoc.h"
  35. #include "fileacc.h"
  36. #include "rtdata.h"
  37. #include "streamio.h"
  38.  
  39. #ifdef DLHEAP
  40.  
  41. void  _cdecl dlfree(void*);
  42. void _cdecl mf_init();
  43.  
  44. #define malloc dlmalloc
  45. #define free dlfree
  46. #define realloc dlrealloc
  47.  
  48. #define lib_free dlfree
  49. #endif
  50.  
  51. /*
  52.     NOTE: This routine does not actually free the link/FILE structures.
  53.     That is because code assumes that it can fclose the file and then
  54.     freopen is a short time later. The __purgefp routine can be called
  55.     to actually release the storage.
  56. */
  57.  
  58. void __freefp( FILE * fp )
  59. {
  60.     __stream_link       **owner;
  61.     __stream_link       *link;
  62.  
  63.     _AccessIOB();
  64.     owner = &_RWD_ostream;
  65.     for( ;; ) {
  66.         link = *owner;
  67.         if( link == NULL )
  68.             return;
  69.         if( link->stream == fp )
  70.             break;
  71.         owner = &link->next;
  72.     }
  73.     fp->_flag |= _READ | _WRITE;
  74.     (*owner) = link->next;
  75.     link->next = _RWD_cstream;
  76.     _RWD_cstream = link;
  77.     _ReleaseIOB();
  78. }
  79.  
  80.  
  81. void __purgefp( void )
  82. {
  83.     __stream_link       *next;
  84.  
  85.     _AccessIOB();
  86.     while( _RWD_cstream != NULL ) {
  87.         next = _RWD_cstream->next;
  88.         lib_free( _RWD_cstream );
  89.         _RWD_cstream = next;
  90.     }
  91.     _ReleaseIOB();
  92. }
  93.