Source code of Windows XP (NT5)
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.

102 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. string.c
  5. Abstract:
  6. This file implements string functions for fax.
  7. Author:
  8. Wesley Witt (wesw) 23-Jan-1995
  9. Environment:
  10. User Mode
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <tchar.h>
  16. #include "faxutil.h"
  17. BOOL
  18. MapFileOpen(
  19. LPTSTR FileName,
  20. BOOL ReadOnly,
  21. DWORD ExtendBytes,
  22. PFILE_MAPPING FileMapping
  23. )
  24. {
  25. FileMapping->hFile = NULL;
  26. FileMapping->hMap = NULL;
  27. FileMapping->fPtr = NULL;
  28. FileMapping->hFile = CreateFile(
  29. FileName,
  30. ReadOnly ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
  31. ReadOnly ? FILE_SHARE_READ : 0,
  32. NULL,
  33. OPEN_EXISTING,
  34. 0,
  35. NULL
  36. );
  37. if (FileMapping->hFile == INVALID_HANDLE_VALUE) {
  38. return FALSE;
  39. }
  40. FileMapping->fSize = GetFileSize( FileMapping->hFile, NULL );
  41. FileMapping->hMap = CreateFileMapping(
  42. FileMapping->hFile,
  43. NULL,
  44. ReadOnly ? PAGE_READONLY : PAGE_READWRITE,
  45. 0,
  46. FileMapping->fSize + ExtendBytes,
  47. NULL
  48. );
  49. if (FileMapping->hMap == NULL) {
  50. CloseHandle( FileMapping->hFile );
  51. return FALSE;
  52. }
  53. FileMapping->fPtr = MapViewOfFileEx(
  54. FileMapping->hMap,
  55. ReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE,
  56. 0,
  57. 0,
  58. 0,
  59. NULL
  60. );
  61. if (FileMapping->fPtr == NULL) {
  62. CloseHandle( FileMapping->hFile );
  63. CloseHandle( FileMapping->hMap );
  64. return FALSE;
  65. }
  66. return TRUE;
  67. }
  68. VOID
  69. MapFileClose(
  70. PFILE_MAPPING FileMapping,
  71. DWORD TrimOffset
  72. )
  73. {
  74. UnmapViewOfFile( FileMapping->fPtr );
  75. CloseHandle( FileMapping->hMap );
  76. if (TrimOffset) {
  77. SetFilePointer( FileMapping->hFile, TrimOffset, NULL, FILE_BEGIN );
  78. SetEndOfFile( FileMapping->hFile );
  79. }
  80. CloseHandle( FileMapping->hFile );
  81. }