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.

66 lines
1.6 KiB

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