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.

92 lines
2.7 KiB

  1. /***
  2. *scanf.c - read formatted data from stdin
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines scanf() - reads formatted data from stdin
  8. *
  9. *Revision History:
  10. * 09-02-83 RN initial version
  11. * 04-13-87 JCR added const to declaration
  12. * 06-24-87 JCR (1) Made declaration conform to ANSI prototype and use
  13. * the va_ macros; (2) removed SS_NE_DS conditionals.
  14. * 11-04-87 JCR Multi-thread support
  15. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  16. * 05-27-88 PHG Merged DLL and normal versions
  17. * 06-15-88 JCR Near reference to _iob[] entries; improve REG variables
  18. * 08-17-89 GJF Clean up, now specific to OS/2 2.0 (i.e., 386 flat
  19. * model). Also fixed copyright and indents.
  20. * 02-15-90 GJF Fixed copyright
  21. * 03-19-90 GJF Made calling type _CALLTYPE2, added #include
  22. * <cruntime.h> and removed #include <register.h>.
  23. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  24. * 10-03-90 GJF New-style function declarator.
  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 Use _[un]lock_str2 instead of _[un]lock_str. Also,
  29. * removed useless local and macro.
  30. * 03-02-98 GJF Exception-safe locking.
  31. *
  32. *******************************************************************************/
  33. #include <cruntime.h>
  34. #include <stdio.h>
  35. #include <dbgint.h>
  36. #include <stdarg.h>
  37. #include <file2.h>
  38. #include <internal.h>
  39. #include <mtdll.h>
  40. /***
  41. *int scanf(format, ...) - read formatted data from stdin
  42. *
  43. *Purpose:
  44. * Reads formatted data from stdin into arguments. _input does the real
  45. * work here.
  46. *
  47. *Entry:
  48. * char *format - format string
  49. * followed by list of pointers to storage for the data read. The number
  50. * and type are controlled by the format string.
  51. *
  52. *Exit:
  53. * returns number of fields read and assigned
  54. *
  55. *Exceptions:
  56. *
  57. *******************************************************************************/
  58. int __cdecl scanf (
  59. const char *format,
  60. ...
  61. )
  62. /*
  63. * stdin 'SCAN', 'F'ormatted
  64. */
  65. {
  66. int retval;
  67. va_list arglist;
  68. va_start(arglist, format);
  69. _ASSERTE(format != NULL);
  70. #ifdef _MT
  71. _lock_str2(0, stdin);
  72. __try {
  73. #endif
  74. retval = (_input(stdin,format,arglist));
  75. #ifdef _MT
  76. }
  77. __finally {
  78. _unlock_str2(0, stdin);
  79. }
  80. #endif
  81. return(retval);
  82. }