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.

65 lines
1.5 KiB

  1. /***
  2. * istrint.cpp - definitions for istream class operaotor>>(int) member functions
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Definitions of operator>>(int) member function(s) for istream class.
  8. * [AT&T C++]
  9. *
  10. *Revision History:
  11. * 09-26-91 KRS Created. Split out 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>>(int& n) - extract int
  25. *
  26. *Purpose:
  27. * Extract int value from stream
  28. *
  29. *Entry:
  30. * n = value to update
  31. *
  32. *Exit:
  33. * n updated, or ios::failbit & n=INT_MAX/INT_MIN on overflow/underflow
  34. *
  35. *Exceptions:
  36. * Stream error on entry or value out of range
  37. *
  38. *******************************************************************************/
  39. istream& istream::operator>>(int& 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>INT_MAX)
  48. {
  49. n = INT_MAX;
  50. state |= ios::failbit;
  51. }
  52. else if (value<INT_MIN)
  53. {
  54. n = INT_MIN;
  55. state |= ios::failbit;
  56. }
  57. else
  58. n = (int) value;
  59. isfx();
  60. }
  61. return *this;
  62. }