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.

220 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. Module Name:
  4. file.c
  5. Abstract:
  6. This module contains function to read file
  7. Author:
  8. 24-Oct-1995 Tue 14:09:59 created
  9. [Environment:]
  10. GDI Device Driver - Plotter.
  11. [Notes:]
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #if !defined(UMODE) && !defined(USERMODE_DRIVER)
  17. HANDLE
  18. OpenPlotFile(
  19. LPWSTR pFileName
  20. )
  21. /*++
  22. Routine Description:
  23. Arguments:
  24. Return Value:
  25. Author:
  26. 24-Oct-1995 Tue 14:16:46 created
  27. Revision History:
  28. --*/
  29. {
  30. PPLOTFILE pPF;
  31. DWORD cbSize;
  32. if ((pPF = (PPLOTFILE)EngAllocMem(FL_ZERO_MEMORY,
  33. sizeof(PLOTFILE),
  34. 'tolp')) &&
  35. (pPF->hModule = EngLoadModule((LPWSTR)pFileName)) &&
  36. (pPF->pbBeg = EngMapModule(pPF->hModule, &cbSize))) {
  37. pPF->pbEnd = (pPF->pbCur = pPF->pbBeg) + cbSize;
  38. return((HANDLE)pPF);
  39. }
  40. if (pPF) {
  41. if (pPF->hModule) {
  42. EngFreeModule(pPF->hModule);
  43. }
  44. EngFreeMem((PVOID)pPF);
  45. }
  46. return((HANDLE)INVALID_HANDLE_VALUE);
  47. }
  48. BOOL
  49. ClosePlotFile(
  50. HANDLE hPlotFile
  51. )
  52. /*++
  53. Routine Description:
  54. Arguments:
  55. Return Value:
  56. Author:
  57. 24-Oct-1995 Tue 14:31:55 created
  58. Revision History:
  59. --*/
  60. {
  61. PPLOTFILE pPF;
  62. if (pPF = (PPLOTFILE)hPlotFile) {
  63. EngFreeModule(pPF->hModule);
  64. EngFreeMem((PVOID)pPF);
  65. return(TRUE);
  66. }
  67. return(FALSE);
  68. }
  69. BOOL
  70. ReadPlotFile(
  71. HANDLE hPlotFile,
  72. LPVOID pBuf,
  73. DWORD cToRead,
  74. LPDWORD pcRead
  75. )
  76. /*++
  77. Routine Description:
  78. Arguments:
  79. Return Value:
  80. Author:
  81. 24-Oct-1995 Tue 14:21:51 created
  82. Revision History:
  83. --*/
  84. {
  85. PPLOTFILE pPF;
  86. if ((pPF = (PPLOTFILE)hPlotFile) && (pBuf)) {
  87. DWORD cData;
  88. if ((cData = pPF->pbEnd - pPF->pbCur) < cToRead) {
  89. cToRead = cData;
  90. }
  91. if (cToRead) {
  92. CopyMemory((LPBYTE)pBuf, pPF->pbCur, cToRead);
  93. pPF->pbCur += cToRead;
  94. if (pcRead) {
  95. *pcRead = cToRead;
  96. }
  97. return(TRUE);
  98. }
  99. }
  100. return(FALSE);
  101. }
  102. #endif // not UMODE