branch update for HEAD-2003091401
[reactos.git] / lib / msvcrt / stdio / fgetws.c
1 /* $Id$
2  *
3  *  ReactOS msvcrt library
4  *
5  *  fgets.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 <msvcrt/stdio.h>
29 #include <msvcrt/internal/file.h>
30
31
32 //#include <msvcrt/ctype.h>
33 #ifndef WEOF
34 #define WEOF    (wchar_t)(0xFFFF)
35 #endif
36
37 wchar_t* fgetws(wchar_t* s, int n, FILE* f)
38 {
39   wchar_t c = 0;
40   wchar_t* cs;
41
42   cs = s;
43   //while (--n > 0 && (c = getwc(f)) != WEOF) {
44   while (n > 0) {
45     c = getwc(f);
46     if (c == WEOF)
47       break;
48     n--;
49     *cs++ = c;
50     if (c == L'\n')
51       break;
52   }
53   if (c == WEOF && cs == s) {
54     return NULL;
55   }
56   *cs++ = L'\0';
57   return s;
58 }