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.

94 lines
2.8 KiB

  1. /***
  2. *getw.c - read a binary word from a stream
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _getw() - gets a binary integer from a stream
  8. *
  9. *Revision History:
  10. * 09-02-83 RN initial version
  11. * 11-09-87 JCR Multi-thread support
  12. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  13. * 01-13-88 JCR Removed unnecessary calls to mthread fileno/feof/ferror
  14. * 05-27-88 PHG Merged DLL and normal versions
  15. * Fixed bug if EOF occurs in middle of word being read
  16. * 06-15-88 JCR Near reference to _iob[] entries; improve REG variables
  17. * 08-24-88 GJF Don't use FP_OFF() macro for the 386
  18. * 08-18-89 GJF Clean up, now specific to OS/2 2.0 (i.e., 386 flat
  19. * model). Also fixed copyright and indents.
  20. * 02-15-90 GJF Fixed copyright
  21. * 03-19-90 GJF Made calling type _CALLTYPE1, added #include
  22. * <cruntime.h> and removed #include <register.h>.
  23. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  24. * 08-13-90 SBM Compiles cleanly with -W3
  25. * 10-02-90 GJF New-style function declarator.
  26. * 01-21-91 GJF ANSI naming.
  27. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  28. * 09-06-94 CFW Replace MTHREAD with _MT.
  29. * 02-06-94 CFW assert -> _ASSERTE.
  30. * 03-07-95 GJF _[un]lock_str macros now take FILE * arg.
  31. * 03-02-98 GJF Exception-safe locking.
  32. *
  33. *******************************************************************************/
  34. #include <cruntime.h>
  35. #include <stdio.h>
  36. #include <dbgint.h>
  37. #include <file2.h>
  38. #include <internal.h>
  39. #include <mtdll.h>
  40. /***
  41. *int _getw(stream) - read an int from a stream
  42. *
  43. *Purpose:
  44. * get n bytes (n=sizeof(int)); OR them together in proper order; high
  45. * byte first. check for EOF between getc's.
  46. * this routine should be machine independent.
  47. *
  48. *Entry:
  49. * FILE *stream - stream to read integer from
  50. *
  51. *Exit:
  52. * returns the int read from the stream
  53. * returns EOF if fails (but this is a legit int value, so
  54. * should test feof() or ferror().
  55. *
  56. *Exceptions:
  57. *
  58. *******************************************************************************/
  59. int __cdecl _getw (
  60. FILE *str
  61. )
  62. {
  63. REG1 FILE *stream;
  64. REG2 int bytecount = sizeof(int);
  65. int word;
  66. char *byteptr = (char *)&word;
  67. int retval;
  68. _ASSERTE(str != NULL);
  69. /* Init stream pointer */
  70. stream = str;
  71. #ifdef _MT
  72. _lock_str(stream);
  73. __try {
  74. #endif
  75. while (bytecount--)
  76. *byteptr++ = (char)_getc_lk(stream);
  77. retval = ((feof(stream) || ferror(stream)) ? EOF : word);
  78. #ifdef _MT
  79. }
  80. __finally {
  81. _unlock_str(stream);
  82. }
  83. #endif
  84. return(retval);
  85. }