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

  1. /***
  2. *cputs.c - direct console output
  3. *
  4. *       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _cputs() - write string directly to console
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <oscalls.h>
  13. #include <internal.h>
  14. #include <mtdll.h>
  15. #include <conio.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. /*
  20.  * declaration for console handle
  21.  */
  22. extern int _confh;
  23.  
  24. /***
  25. *int _cputs(string) - put a string to the console
  26. *
  27. *Purpose:
  28. *       Writes the string directly to the console.  No newline
  29. *       is appended.
  30. *
  31. *Entry:
  32. *       char *string - string to write
  33. *
  34. *Exit:
  35. *       Good return = 0
  36. *       Error return = !0
  37. *
  38. *Exceptions:
  39. *
  40. *******************************************************************************/
  41.  
  42. int __cdecl _cputs (
  43.         const char *string
  44.         )
  45. {
  46.         ULONG num_written;
  47.         int error = 0;                   /* error occurred? */
  48.  
  49.         _mlock(_CONIO_LOCK);             /* acquire console lock */
  50.  
  51.         /*
  52.          * _confh, the handle to the console output, is created the
  53.          * first time that either _putch() or _cputs() is called.
  54.          */
  55.  
  56.         if (_confh == -2)
  57.             __initconout();
  58.  
  59.         /* write string to console file handle */
  60.  
  61.         if ( (_confh == -1) || !WriteConsole( (HANDLE)_confh,
  62.                                               (LPVOID)string,
  63.                                               strlen(string),
  64.                                               &num_written,
  65.                                               NULL )
  66.            )
  67.                 /* return error indicator */
  68.                 error = -1;
  69.  
  70.         _munlock(_CONIO_LOCK);          /* release console lock */
  71.  
  72.         return error;
  73. }
  74.