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.

130 lines
1.8 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 dwSize-1 characters from the file. Always NULL terminates if
  42. dwSize is greater than 0.
  43. Arguments:
  44. Return Value:
  45. --*/
  46. {
  47. CHAR c;
  48. DWORD dwRead;
  49. LPSTR ptr;
  50. if(dwSize == 0)
  51. {
  52. return NULL;
  53. }
  54. ptr = pszBuf;
  55. while ( --dwSize > 0 && (c = My_fgetc(hFile)) != EOF )
  56. if ( (*ptr++ = c) == '\n' )
  57. break;
  58. *ptr = '\0';
  59. return ( c == EOF && ptr == pszBuf ) ? NULL : pszBuf;
  60. }
  61. DWORD
  62. My_fread(
  63. LPBYTE pBuf,
  64. DWORD dwSize,
  65. HANDLE hFile
  66. )
  67. /*++
  68. Routine Description:
  69. Read at most dwSize bytes to buffer
  70. Arguments:
  71. Return Value:
  72. Number of bytes read
  73. --*/
  74. {
  75. DWORD cbRead;
  76. return ReadFile(hFile, pBuf, dwSize, &cbRead, NULL) ? cbRead : 0;
  77. }
  78. BOOL
  79. My_ungetc(
  80. HANDLE hFile
  81. )
  82. /*++
  83. Routine Description:
  84. Unread one character
  85. Arguments:
  86. Return Value:
  87. --*/
  88. {
  89. return SetFilePointer(hFile, -1, NULL, FILE_CURRENT) != INVALID_SET_FILE_POINTER;
  90. }