home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / puts.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  79 lines

  1. /***
  2. *puts.c - put a string to stdout
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines puts() and _putws() - put a string to stdout
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <stdio.h>
  13. #include <dbgint.h>
  14. #include <file2.h>
  15. #include <string.h>
  16. #include <internal.h>
  17. #include <mtdll.h>
  18. #include <tchar.h>
  19.  
  20. /***
  21. *int puts(string) - put a string to stdout with newline
  22. *
  23. *Purpose:
  24. *       Write a string to stdout; don't include '\0' but append '\n'.  Uses
  25. *       temporary buffering for efficiency on stdout if unbuffered.
  26. *
  27. *Entry:
  28. *       char *string - string to output
  29. *
  30. *Exit:
  31. *       Good return = 0
  32. *       Error return = EOF
  33. *
  34. *Exceptions:
  35. *
  36. *******************************************************************************/
  37.  
  38. int __cdecl _putts (
  39.         const _TCHAR *string
  40.         )
  41. {
  42.         int buffing;
  43. #ifndef _UNICODE
  44.         unsigned int length;
  45.         unsigned int ndone;
  46. #endif  /* _UNICODE */
  47.         int retval = _TEOF; /* error */
  48.  
  49.         _ASSERTE(string != NULL);
  50.  
  51.         _lock_str2(1, stdout);
  52.         buffing = _stbuf(stdout);
  53.  
  54. #ifdef _UNICODE
  55.         while (*string) {
  56.             if (_putwchar_lk(*string++) == WEOF)
  57.                 goto done;
  58.         }
  59.         if (_putwchar_lk(L'\n') != WEOF)
  60.             retval = 0; /* success */
  61. #else  /* _UNICODE */
  62.         length = strlen(string);
  63.         ndone = _fwrite_lk(string,1,length,stdout);
  64.  
  65.         if (ndone == length) {
  66.                 _putc_lk('\n',stdout);
  67.                 retval = 0;     /* success */
  68.         }
  69. #endif  /* _UNICODE */
  70.  
  71. #ifdef _UNICODE
  72. done:
  73. #endif  /* _UNICODE */
  74.         _ftbuf(buffing, stdout);
  75.         _unlock_str2(1, stdout);
  76.  
  77.         return retval;
  78. }
  79.