11c1e99dbe456da750c11d944380ffc0204d84c2
[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 /*
65  * @implemented
66  */
67 int
68 fputws(const wchar_t* s, FILE* f)
69 {
70   int r = 0;
71   int unbuffered;
72   wchar_t c;
73   wchar_t localbuf[BUFSIZ];
74
75   unbuffered = f->_flag & _IONBF;
76   if (unbuffered)
77   {
78     f->_flag &= ~_IONBF;
79     f->_ptr = f->_base = (unsigned char*)localbuf;
80     f->_bufsiz = BUFSIZ;
81   }
82
83   while ((c = *s++))
84     r = putwc(c, f);
85
86   if (unbuffered)
87   {
88     fflush(f);
89     f->_flag |= _IONBF;
90     f->_base = NULL;
91     f->_bufsiz = 0;
92     f->_cnt = 0;
93   }
94   return(r);
95 }