- Cleanup the /lib directory, by putting more 3rd-party libs in /3rdparty, and by...
[reactos.git] / reactos / lib / sdk / crt / stdio / fgets.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 #include <precomp.h>
28
29 char* fgets(char* s, int n, FILE* f)
30 {
31 int c = 0;
32 char* cs;
33
34 cs = s;
35 while (--n>0 && (c = getc(f)) != EOF) {
36 *cs++ = c;
37 if (c == '\n')
38 break;
39 }
40 if (c == EOF && cs == s)
41 return NULL;
42 *cs++ = '\0';
43 return s;
44 }