Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  Implementation of printf() - formatted output.
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include "widechar.h"
  34. #include <stdio.h>
  35. #include <stdarg.h>
  36. #include "rtdata.h"
  37. #include "fileacc.h"
  38. #include "printf.h"
  39. #include "fprtf.h"
  40. #include "orient.h"
  41. #include "flush.h"
  42. #include "streamio.h"
  43.  
  44.  
  45. /*
  46.  * file_putc -- write a character to a file
  47.  */
  48. static slib_callback_t file_putc; // setup calling convention
  49. static void __SLIB_CALLBACK file_putc( SPECS __SLIB *specs, int op_char )
  50. {
  51.     __F_NAME(fputc,fputwc)( op_char, (FILE *)specs->_dest );
  52.     specs->_output_count++;
  53. }
  54.  
  55.  
  56. int __F_NAME(__fprtf,__fwprtf)( FILE *fp, const CHAR_TYPE *format, va_list arg )
  57. {
  58.     int             not_buffered;
  59.     int             amount_written;
  60.     unsigned        oflag;
  61.     slib_callback_t *tmp;
  62.  
  63.     _ValidFile( fp, 0 );
  64.     _AccessFile( fp );
  65.  
  66.     /*** Deal with stream orientation ***/
  67.     ORIENT_STREAM(fp,0);
  68.  
  69.     oflag = fp->_flag & (_SFERR | _EOF);                  /* 06-sep-91 */
  70.     fp->_flag &= ~(_SFERR | _EOF);
  71.  
  72.     if( _FP_BASE(fp) == NULL ) {
  73.         __ioalloc( fp );        /* allocate buffer */
  74.     }
  75.     not_buffered = 0;
  76.     if( fp->_flag & _IONBF ) {
  77.         not_buffered = 1;
  78.         fp->_flag &= ~_IONBF;
  79.         fp->_flag |= _IOFBF;
  80.     }
  81. #if defined( __386__ ) && defined( __QNX__ )
  82.     /* avoid some segment relocations for 32-bit QNX */
  83.     tmp = (void (*)())file_putc;
  84. #else
  85.     tmp = file_putc;
  86. #endif
  87.     amount_written = __F_NAME(__prtf,__wprtf)( fp, format, arg, tmp );
  88.     if( not_buffered ) {
  89.         fp->_flag &= ~_IOFBF;
  90.         fp->_flag |= _IONBF;
  91.         __flush( fp );
  92.     }
  93.     if( ferror( fp ) )
  94.         amount_written = -1;             /* 06-sep-91 */
  95.     fp->_flag |= oflag;
  96.  
  97.     _ReleaseFile( fp );
  98.     return( amount_written );
  99. }
  100.