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.

95 lines
2.8 KiB

  1. /***
  2. *putw.c - put a binary int to output stream
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _putw() - puts a binary int to an output 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. * 06-15-88 JCR Near reference to _iob[] entries; improve REG variables
  16. * 08-25-88 GJF Don't use FP_OFF() macro for the 386
  17. * 08-18-89 GJF Clean up, now specific to OS/2 2.0 (i.e., 386 flat
  18. * model). Also fixed copyright and indents.
  19. * 02-15-90 GJF Fixed copyright
  20. * 03-19-90 GJF Made calling type _CALLTYPE1, added #include
  21. * <cruntime.h> and removed #include <register.h>.
  22. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  23. * 10-03-90 GJF New-style function declarators.
  24. * 01-21-91 GJF ANSI naming.
  25. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  26. * 09-06-94 CFW Replace MTHREAD with _MT.
  27. * 02-06-94 CFW assert -> _ASSERTE.
  28. * 03-07-95 GJF _[un]lock_str macros now take FILE * arg.
  29. * 03-02-98 GJF Exception-safe locking.
  30. *
  31. *******************************************************************************/
  32. #include <cruntime.h>
  33. #include <stdio.h>
  34. #include <dbgint.h>
  35. #include <file2.h>
  36. #include <internal.h>
  37. #include <mtdll.h>
  38. /***
  39. *int _putw(word, stream) - write a binary int to an output stream
  40. *
  41. *Purpose:
  42. * Writes sizeof(int) bytes to the output stream, high byte first.
  43. * This routine should be machine independent.
  44. *
  45. *Entry:
  46. * int word - integer to write
  47. * FILE *stream - stream to write to
  48. *
  49. *Exit:
  50. * returns the word put to the stream
  51. * returns EOF if error, but this is a legit int value, so should
  52. * test with feof() or ferror().
  53. *
  54. *Exceptions:
  55. *
  56. *******************************************************************************/
  57. int __cdecl _putw (
  58. int word,
  59. FILE *str
  60. )
  61. {
  62. REG1 FILE *stream;
  63. REG3 int bytecount = sizeof(int);
  64. REG2 char *byteptr = (char *)&word;
  65. int retval;
  66. _ASSERTE(str != NULL);
  67. /* Init stream pointer */
  68. stream = str;
  69. #ifdef _MT
  70. _lock_str(stream);
  71. __try {
  72. #endif
  73. while (bytecount--)
  74. {
  75. _putc_lk(*byteptr,stream);
  76. ++byteptr;
  77. }
  78. retval = (ferror(stream) ? EOF : word);
  79. #ifdef _MT
  80. }
  81. __finally {
  82. _unlock_str(stream);
  83. }
  84. #endif
  85. return(retval);
  86. }