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.

155 lines
2.5 KiB

  1. /* stream.c - OLE stream I/O routines.
  2. *
  3. * Created by Microsoft Corporation.
  4. */
  5. #include "packager.h"
  6. static LPSTR *glplpstr;
  7. static STREAMOP gsop;
  8. /* SetFile() - Set the file to be written.
  9. */
  10. VOID
  11. SetFile(
  12. STREAMOP sop,
  13. INT fh,
  14. LPSTR *lplpstr
  15. )
  16. {
  17. switch (gsop = sop)
  18. {
  19. case SOP_FILE:
  20. glpStream->fh = fh;
  21. break;
  22. case SOP_MEMORY:
  23. gcbObject = 0L;
  24. glplpstr = lplpstr;
  25. break;
  26. }
  27. }
  28. /* ReadStream() - Read bytes from memory, from a file, or just count them.
  29. */
  30. DWORD
  31. ReadStream(
  32. LPAPPSTREAM lpStream,
  33. LPSTR lpstr,
  34. DWORD cb
  35. )
  36. {
  37. switch (gsop)
  38. {
  39. case SOP_FILE:
  40. return _lread(lpStream->fh, lpstr, cb);
  41. break;
  42. case SOP_MEMORY:
  43. gcbObject += cb;
  44. if (glplpstr)
  45. MemRead(glplpstr, lpstr, cb);
  46. break;
  47. }
  48. return cb;
  49. }
  50. /* PosStream() - Reset the position of the file pointer.
  51. *
  52. * Note: This is never used; luckily, or it would mess up the count.
  53. */
  54. DWORD
  55. PosStream(
  56. LPAPPSTREAM lpStream,
  57. LONG pos,
  58. INT iorigin)
  59. {
  60. return _llseek(lpStream->fh, pos, iorigin);
  61. }
  62. /* WriteStream() - Write bytes to memory, to a file, or just count them.
  63. */
  64. DWORD
  65. WriteStream(
  66. LPAPPSTREAM lpStream,
  67. LPSTR lpstr,
  68. DWORD cb
  69. )
  70. {
  71. switch (gsop)
  72. {
  73. case SOP_FILE:
  74. return _lwrite(lpStream->fh, lpstr, cb);
  75. case SOP_MEMORY:
  76. gcbObject += cb;
  77. if (glplpstr)
  78. MemWrite(glplpstr, lpstr, cb);
  79. break;
  80. }
  81. return cb;
  82. }
  83. /********************* Memory read/write functions ********************/
  84. /* MemRead() - Read bytes from the memory (stream).
  85. */
  86. DWORD
  87. MemRead(
  88. LPSTR *lplpStream,
  89. LPSTR lpItem,
  90. DWORD dwSize
  91. )
  92. {
  93. DWORD cb;
  94. CHAR *hpDest = lpItem;
  95. CHAR *hpSrc = *lplpStream;
  96. for (cb = dwSize; cb; cb--)
  97. *hpDest++ = *hpSrc++;
  98. *lplpStream = hpSrc;
  99. return dwSize;
  100. }
  101. /* MemWrite() - Write bytes to the memory (stream).
  102. */
  103. DWORD
  104. MemWrite(
  105. LPSTR *lplpStream,
  106. LPSTR lpItem,
  107. DWORD dwSize
  108. )
  109. {
  110. DWORD cb;
  111. CHAR *hpDest = *lplpStream;
  112. CHAR *hpSrc = lpItem;
  113. for (cb = dwSize; cb; cb--)
  114. *hpDest++ = *hpSrc++;
  115. *lplpStream = hpDest;
  116. return dwSize;
  117. }