e3d14ba373cd414919a681fdee4e1e45470272af
[reactos.git] / lib / msvcrt / stdio / fputs.c
1 /* $Id$
2  *
3  *  ReactOS msvcrt library
4  *
5  *  fputs.c
6  *
7  *  Copyright (C) 2002  Robert Dickenson <robd@reactos.org>
8  *
9  *  Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
10  *                         28/12/1998: Appropriated for Reactos
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25  */
26 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
27
28 #include <windows.h>
29 #include <msvcrt/stdio.h>
30 #include <msvcrt/internal/file.h>
31 #include <msvcrt/string.h>
32
33 int
34 fputs(const char *s, FILE *f)
35 {
36   int r = 0;
37   int c;
38   int unbuffered;
39   char localbuf[BUFSIZ];
40
41   unbuffered = f->_flag & _IONBF;
42   if (unbuffered)
43   {
44     f->_flag &= ~_IONBF;
45     f->_ptr = f->_base = localbuf;
46     f->_bufsiz = BUFSIZ;
47   }
48
49   while ((c = *s++))
50     r = putc(c, f);
51
52   if (unbuffered)
53   {
54     fflush(f);
55     f->_flag |= _IONBF;
56     f->_base = NULL;
57     f->_bufsiz = 0;
58     f->_cnt = 0;
59   }
60
61   return(r);
62 }
63
64 int
65 fputws(const wchar_t* s, FILE* f)
66 {
67   int r = 0;
68   int unbuffered;
69   wchar_t c;
70   wchar_t localbuf[BUFSIZ];
71
72   unbuffered = f->_flag & _IONBF;
73   if (unbuffered)
74   {
75     f->_flag &= ~_IONBF;
76     f->_ptr = f->_base = localbuf;
77     f->_bufsiz = BUFSIZ;
78   }
79
80   while ((c = *s++))
81     r = putwc(c, f);
82
83   if (unbuffered)
84   {
85     fflush(f);
86     f->_flag |= _IONBF;
87     f->_base = NULL;
88     f->_bufsiz = 0;
89     f->_cnt = 0;
90   }
91   return(r);
92 }