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.7 KiB

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