123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- //----------------------------------------------------------------------------
- // Global Fast File Code.
- //
- #include "heap.h"
- #include "fastfile.h"
- #include <ctype.h>
- long ffLastError = 0;
- #define NO_ERR 0
- //-----------------------------------------------------------------------------------
- bool FastFileInit (char *fname)
- {
- if (numFastFiles == maxFastFiles)
- {
- ffLastError = -1;
- return FALSE;
- }
- //-----------------------------------------------------------------------------
- //-- Open this fast file, add it to the list O pointers and return TRUE if OK!
- fastFiles[numFastFiles] = new FastFile;
- long result = fastFiles[numFastFiles]->open(fname);
- if (result == FASTFILE_VERSION)
- {
- ffLastError = result;
- return FALSE;
- }
- numFastFiles++;
- return TRUE;
- }
- //-----------------------------------------------------------------------------------
- void FastFileFini (void)
- {
- if (fastFiles)
- {
- long currentFastFile = 0;
- while (currentFastFile < maxFastFiles)
- {
- if (fastFiles[currentFastFile])
- {
- fastFiles[currentFastFile]->close();
-
- delete fastFiles[currentFastFile];
- fastFiles[currentFastFile] = NULL;
- }
-
- currentFastFile++;
- }
- }
- free(fastFiles);
- fastFiles = NULL;
- numFastFiles= 0;
- }
- //-----------------------------------------------------------------------------------
- FastFile *FastFileFind (char *fname, long &fastFileHandle)
- {
- if (fastFiles)
- {
- DWORD thisHash = elfHash(fname);
- long currentFastFile = 0;
- long tempHandle = -1;
- while (currentFastFile < numFastFiles)
- {
- tempHandle = fastFiles[currentFastFile]->openFast(thisHash,fname);
- if (tempHandle != -1)
- {
- fastFileHandle = tempHandle;
- return fastFiles[currentFastFile];
- }
- currentFastFile++;
- }
- }
- return NULL;
- }
- //------------------------------------------------------------------
- DWORD elfHash (char *name)
- {
- unsigned long h = 0, g;
- while ( *name )
- {
- h = ( h << 4 ) + *name++;
- if ( g = h & 0xF0000000 )
- h ^= g >> 24;
- h &= ~g;
- }
- return h;
- }
- //-----------------------------------------------------------------------------------
|