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.

65 lines
1.5 KiB

  1. /***
  2. * istrshrt.cpp - definitions for istream class operator>>(short) function(s)
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Definitions of operator>>(short) member function(s) for istream class.
  8. * [AT&T C++]
  9. *
  10. *Revision History:
  11. * 09-26-91 KRS Created. Split off from istream.cxx for granularity.
  12. * 12-30-92 KRS Fix indirection problem with **endptr.
  13. * 05-24-94 GJF Moved definition of MAXLONGSIZ to istream.h.
  14. * 06-14-95 CFW Comment cleanup.
  15. *
  16. *******************************************************************************/
  17. #include <cruntime.h>
  18. #include <internal.h>
  19. #include <stdlib.h>
  20. #include <limits.h>
  21. #include <iostream.h>
  22. #pragma hdrstop
  23. /***
  24. *istream& istream::operator>>(short& n) - extract short
  25. *
  26. *Purpose:
  27. * Extract short value from stream
  28. *
  29. *Entry:
  30. * n = value to update
  31. *
  32. *Exit:
  33. * n updated, or ios::failbit & n=SHRT_MAX/SHRT_MIN on overflow/underflow
  34. *
  35. *Exceptions:
  36. * Stream error on entry or value out of range
  37. *
  38. *******************************************************************************/
  39. istream& istream::operator>>(short& n)
  40. {
  41. _WINSTATIC char ibuffer[MAXLONGSIZ];
  42. long value;
  43. char ** endptr = (char**)NULL;
  44. if (ipfx(0))
  45. {
  46. value = strtol(ibuffer, endptr, getint(ibuffer));
  47. if (value>SHRT_MAX)
  48. {
  49. n = SHRT_MAX;
  50. state |= ios::failbit;
  51. }
  52. else if (value<SHRT_MIN)
  53. {
  54. n = SHRT_MIN;
  55. state |= ios::failbit;
  56. }
  57. else
  58. n = (short) value;
  59. isfx();
  60. }
  61. return *this;
  62. }