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.

64 lines
1.6 KiB

  1. //
  2. // fsteam.h
  3. // Implements a file stream
  4. // for reading text files line by line with UNICODE
  5. // support (the standard C streams, only support
  6. // unicode as binary streams which are a pain to work
  7. // with)
  8. //
  9. // Copyright(C) Microsoft Corporation 2000
  10. // Author: Nadim Abdo (nadima)
  11. //
  12. #ifndef _fstream_h_
  13. #define _fstream_h_
  14. #define LINEBUF_SIZE 2048
  15. #define READ_BUF_SIZE 8192
  16. #define UNICODE_BOM 0xFEFF
  17. #define ERR_SUCCESS 1
  18. #define ERR_UNKNOWN -1
  19. #define ERR_OUT_OF_MEM -2
  20. #define ERR_CREATEFILE -3
  21. #define ERR_BUFTOOSMALL -4
  22. #define ERR_EOF -5
  23. #define ERR_NOTOPENFORREAD -6
  24. #define ERR_NOTOPENFORWRITE -7
  25. #define ERR_FILEOP -8
  26. class CTscFileStream
  27. {
  28. public:
  29. CTscFileStream();
  30. ~CTscFileStream();
  31. INT OpenForRead(LPTSTR szFileName);
  32. INT OpenForWrite(LPTSTR szFileName, BOOL fWriteUnicode=TRUE);
  33. INT Write(LPWSTR szLine);
  34. INT ReadNextLine(LPTSTR szLine, INT lineSize);
  35. INT Close();
  36. BOOL IsOpenForWrite() {return _fOpenForWrite;}
  37. BOOL IsOpenForRead() {return _fOpenForRead;}
  38. private:
  39. inline void CheckFirstBufMarkedUnicode();
  40. inline void EatCRLF(LPWSTR szLine, INT nChars);
  41. private:
  42. HANDLE _hFile;
  43. PBYTE _pBuffer;
  44. PBYTE _pAnsiLineBuf;
  45. INT _cbAnsiBufSize;
  46. BOOL _fOpenForRead;
  47. BOOL _fOpenForWrite;
  48. BOOL _fReadToEOF;
  49. INT _curBytePtr;
  50. INT _curBufSize;
  51. TCHAR _szFileName[MAX_PATH+1];
  52. BOOL _fFileIsUnicode;
  53. BOOL _fAtStartOfFile;
  54. };
  55. #endif //_fstream_h_