Subversion Repositories Kolibri OS

Rev

Go to most recent revision | 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 fputs() - put string to stream.
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include "widechar.h"
  34. #include <stdio.h>
  35. #include "fileacc.h"
  36. #include "rtdata.h"
  37. #include "flush.h"
  38. #include "streamio.h"
  39.  
  40.  
  41. _WCRTLINK int __F_NAME(fputs,fputws)( const CHAR_TYPE *s, FILE *fp )
  42. {
  43.     const CHAR_TYPE     *start;
  44.     int                 c;
  45.     int                 not_buffered;
  46.     int                 rc;
  47.  
  48.     _ValidFile( fp, __F_NAME(EOF,WEOF) );
  49.     _AccessFile( fp );
  50.  
  51.     if( _FP_BASE(fp) == NULL ) {
  52.         __ioalloc( fp );                /* allocate buffer */
  53.     }
  54.     not_buffered = 0;
  55.     if( fp->_flag & _IONBF ) {
  56.         not_buffered = 1;
  57.         fp->_flag &= ~_IONBF;
  58.         fp->_flag |= _IOLBF;
  59.     }
  60.     rc = 0;
  61.     start = s;
  62.     while( c = *s ) {
  63.         s++;
  64. #ifndef __WIDECHAR__
  65.         if( (fputc)( c, fp ) == EOF ) {         /* 23-oct-91 */
  66.             rc = EOF;
  67.             break;
  68.         }
  69. #else
  70.         if( (fputwc)( c, fp ) == WEOF ) {       /* 23-oct-91 */
  71.             rc = -1;
  72.             break;
  73.         }
  74. #endif
  75.     }
  76.     if( not_buffered ) {
  77.         fp->_flag &= ~_IOLBF;
  78.         fp->_flag |= _IONBF;
  79.         if( rc == 0 ) {
  80.             rc = __flush( fp );                 /* 23-oct-91 */
  81.         }
  82.     }
  83.     if( rc == 0 ) {
  84.         /* return the number of items written */
  85.         /* this is ok by ANSI which says that success is */
  86.         /* indicated by a non-negative return value */
  87.         rc = s - start;
  88.     }
  89.     _ReleaseFile( fp );
  90.     return( rc );
  91. }
  92.