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.

124 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. FileIo.c
  6. Abstract:
  7. Routines to do File IO for the migration of Win95 printing to NT
  8. Author:
  9. Muhunthan Sivapragasam (MuhuntS) 24-Aug-1998
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. CHAR
  15. My_fgetc(
  16. HANDLE hFile
  17. )
  18. /*++
  19. Routine Description:
  20. Gets a character from the file
  21. Arguments:
  22. Return Value:
  23. --*/
  24. {
  25. CHAR c;
  26. DWORD cbRead;
  27. if ( ReadFile(hFile, (LPBYTE)&c, sizeof(c), &cbRead, NULL) &&
  28. cbRead == sizeof(c) )
  29. return c;
  30. else
  31. return (CHAR) EOF;
  32. }
  33. LPSTR
  34. My_fgets(
  35. LPSTR pszBuf,
  36. DWORD dwSize,
  37. HANDLE hFile
  38. )
  39. /*++
  40. Routine Description:
  41. Gets a line, or at most n characters from the file
  42. Arguments:
  43. Return Value:
  44. --*/
  45. {
  46. CHAR c;
  47. DWORD dwRead;
  48. LPSTR ptr;
  49. ptr = pszBuf;
  50. while ( --dwSize > 0 && (c = My_fgetc(hFile)) != EOF )
  51. if ( (*ptr++ = c) == '\n' )
  52. break;
  53. *ptr = '\0';
  54. return ( c == EOF && ptr == pszBuf ) ? NULL : pszBuf;
  55. }
  56. DWORD
  57. My_fread(
  58. LPBYTE pBuf,
  59. DWORD dwSize,
  60. HANDLE hFile
  61. )
  62. /*++
  63. Routine Description:
  64. Read at most dwSize bytes to buffer
  65. Arguments:
  66. Return Value:
  67. Number of bytes read
  68. --*/
  69. {
  70. DWORD cbRead;
  71. return ReadFile(hFile, pBuf, dwSize, &cbRead, NULL) ? cbRead : 0;
  72. }
  73. BOOL
  74. My_ungetc(
  75. HANDLE hFile
  76. )
  77. /*++
  78. Routine Description:
  79. Unread one character
  80. Arguments:
  81. Return Value:
  82. --*/
  83. {
  84. return SetFilePointer(hFile, -1, NULL, FILE_CURRENT) != 0xFFFFFFFF;
  85. }