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.

134 lines
3.0 KiB

  1. /*==============================================================================
  2. This C++ object provides a generic layer over various stream types.
  3. #define Stream
  4. WINFILE Windows file
  5. SECFILE IFAX secure file
  6. OLEFILE OLE2 IStream
  7. 01-Nov-93 RajeevD Created.
  8. 03-Mar-94 RajeevD Added IStream support.
  9. ==============================================================================*/
  10. #ifndef _INC_GENFILE
  11. #define _INC_GENFILE
  12. #include <ifaxos.h>
  13. #ifdef SECFILE
  14. #include <awfile.h>
  15. #endif
  16. #ifdef OLEFILE
  17. #ifdef WIN32
  18. #include <objerror.h>
  19. #endif
  20. #include <memory.h>
  21. #include <objbase.h>
  22. #endif
  23. // seek origins
  24. #define SEEK_BEG 0
  25. #define SEEK_CUR 1
  26. #define SEEK_END 2
  27. typedef struct FAR GENFILE
  28. {
  29. GENFILE (void) {fOpen = FALSE;}
  30. #ifdef WINFILE
  31. HFILE hf;
  32. BOOL Open (LPVOID lpFilePath, WORD wMode)
  33. { return (fOpen = (hf = _lopen ((LPSTR) lpFilePath, wMode)) != HFILE_ERROR); }
  34. BOOL Read (LPVOID lpRead, UINT cbRead)
  35. { return _lread (hf, (char FAR*) lpRead, cbRead) == cbRead; }
  36. BOOL Write (LPVOID lpWrite, UINT cbWrite)
  37. { return _lwrite (hf, (char FAR*) lpWrite, cbWrite) == cbWrite; }
  38. BOOL Seek (long lOffset, WORD wOrigin = 0)
  39. { return _llseek (hf, lOffset, wOrigin) != -1L; }
  40. DWORD Tell (void)
  41. { return _llseek (hf, 0, SEEK_CUR); }
  42. ~GENFILE ()
  43. { if (fOpen) _lclose (hf); }
  44. #endif // WINFILE
  45. #ifdef SECFILE
  46. hOpenSecureFile hosf;
  47. BOOL Open (LPVOID lpFilePath, WORD wMode)
  48. { return (fOpen = !SecOpenFile ((LPhSecureFile) lpFilePath, &hosf, wMode)); }
  49. BOOL Read (LPVOID lpRead, UINT cbRead)
  50. { return SecReadFile (&hosf, lpRead, cbRead) == cbRead; }
  51. BOOL Write (LPVOID lpWrite, UINT cbWrite)
  52. { return SecWriteFile (&hosf, lpWrite, cbWrite) == cbWrite; }
  53. BOOL Seek (long lOffset, WORD wOrigin = 0)
  54. { return SecSeekFile (&hosf, lOffset, wOrigin) != -1L; }
  55. DWORD Tell (void)
  56. { return SecSeekFile (&hosf, 0, SEEK_CUR);}
  57. ~GENFILE ()
  58. { if (fOpen) SecCloseFile (&hosf); }
  59. #endif // SECFILE
  60. #ifdef OLEFILE
  61. LPSTREAM lpStream;
  62. BOOL Open (LPVOID lpFilePath, WORD wMode)
  63. {
  64. lpStream = (LPSTREAM) lpFilePath;
  65. Seek (0, STREAM_SEEK_SET); // BKD: changed to STREAM_SEEK_SET
  66. return TRUE;
  67. }
  68. BOOL Read (LPVOID lpRead, UINT cbRead)
  69. {
  70. DWORD cbActual;
  71. lpStream->Read (lpRead, cbRead, &cbActual);
  72. return (cbRead == cbActual);
  73. }
  74. BOOL Write (LPVOID lpWrite, UINT cbWrite)
  75. { return (lpStream->Write (lpWrite, cbWrite, NULL) == S_OK); }
  76. BOOL Seek (long lOffset, WORD wOrigin = 0)
  77. {
  78. LARGE_INTEGER dlOffset;
  79. ULARGE_INTEGER dlNewOffset;
  80. LISet32 (dlOffset, lOffset);
  81. return (lpStream->Seek (dlOffset, wOrigin, &dlNewOffset) == S_OK);
  82. }
  83. DWORD Tell (void)
  84. {
  85. LARGE_INTEGER dlOffset;
  86. ULARGE_INTEGER dlNewOffset;
  87. LISet32 (dlOffset, 0);
  88. lpStream->Seek (dlOffset, SEEK_CUR, &dlNewOffset);
  89. return dlNewOffset.LowPart;
  90. }
  91. ~GENFILE () { }
  92. #endif // OLEFILE
  93. BOOL fOpen;
  94. }
  95. FAR *LPGENFILE;
  96. #endif // _INC_GENFILE