Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

  1. #ifndef __MMFILE_HXX__
  2. #define __MMFILE_HXX__
  3. #define MMF_EOF (-1)
  4. //
  5. // the file grows a "chunk" at a time. This is the default chunk size.
  6. //
  7. #define MMF_PAGE 4096
  8. #define MMF_CHUNK (MMF_PAGE * 4)
  9. class CMMFile
  10. {
  11. public:
  12. CMMFile(WCHAR const *szFile,BOOL fWrite);
  13. ~CMMFile(void);
  14. inline BOOL Ok() { return 0 != _hfFile; }
  15. inline BOOL isWritable() { return _fWrite; }
  16. inline ULONG FileSize() { return _ulFileSize; }
  17. inline void UnGetChar(int x) { if ((_pcCurrent>(char *)_pvView) && ((ULONG)(_pcCurrent-(char *)_pvView)<_ulFileSize)) _pcCurrent--; }
  18. inline int GetChar() { return ((ULONG)(_pcCurrent-(char *)_pvView)<_ulFileSize) ? (int) *_pcCurrent++ : MMF_EOF; }
  19. inline BOOL isEOF() { return ((ULONG)(_pcCurrent-(char *)_pvView)<_ulFileSize) ? FALSE : TRUE; }
  20. int GetS(char *szBuf,int iMaxLen);
  21. inline ULONG Tell() { return (ULONG) (_pcCurrent - (char *) _pvView); }
  22. inline ULONG Seek(ULONG ul) { _pcCurrent = (char *) _pvView + ul; return ul; }
  23. inline int PutChar(int c) { Grow(Tell() + 1); *_pcCurrent++ = (char) c; return c; }
  24. inline int PutS(char *szBuf) { return (PutJustS(szBuf) + PutJustS("\r\n")); }
  25. int PutJustS(char *szBuf);
  26. inline LPVOID GetMapping() { return _pvView; }
  27. ULONG Grow(ULONG ulNewSize);
  28. inline ULONG GetChunkSize(void) { return _ulChunk; }
  29. inline ULONG SetChunkSize(ULONG ulChunk) { _ulChunk = ulChunk; return ulChunk; }
  30. inline int Flush() { return FlushViewOfFile(_pvView,_ulFileSize); }
  31. private:
  32. inline ULONG _RoundUpToChunk(ULONG x) { return ((x) % _ulChunk) ? ((((x) / _ulChunk) + 1) * _ulChunk) : (x); }
  33. BOOL _fWrite;
  34. HANDLE _hfFile;
  35. HANDLE _hMapping;
  36. LPVOID _pvView;
  37. ULONG _ulFileSize;
  38. ULONG _ulChunk;
  39. char *_pcCurrent;
  40. };
  41. #endif