1617
|
1 /* This program is free software; you can redistribute it and/or modify
|
|
2 * it under the terms of the GNU General Public License as published by
|
|
3 * the Free Software Foundation; either version 2 of the License, or
|
|
4 * (at your option) any later version.
|
|
5 *
|
|
6 * This program is distributed in the hope that it will be useful,
|
|
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
9 * GNU General Public License for more details.
|
|
10 *
|
|
11 * You should have received a copy of the GNU General Public License
|
|
12 * along with this program; if not, write to the Free Software Foundation,
|
|
13 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
14 */
|
|
15
|
|
16 #include "vfs.h"
|
|
17
|
|
18 /* FIXME low performance vfs_getc */
|
|
19 gint vfs_getc(VFSFile *stream)
|
|
20 {
|
|
21 guchar uc;
|
|
22 if (vfs_fread(&uc, 1, 1, stream))
|
|
23 return uc;
|
|
24 return EOF;
|
|
25 }
|
|
26
|
|
27
|
|
28 gchar *vfs_fgets(gchar *s, gint n, VFSFile *stream)
|
|
29 {
|
|
30 gint c;
|
|
31 register gchar *p;
|
|
32
|
|
33 if(n<=0) return NULL;
|
|
34
|
|
35 p = s;
|
|
36
|
|
37 while (--n) {
|
|
38 if ((c = vfs_getc(stream))== EOF) {
|
|
39 break;
|
|
40 }
|
|
41 if ((*p++ = c) == '\n') {
|
|
42 break;
|
|
43 }
|
|
44 }
|
|
45 if (p > s) {
|
|
46 *p = 0;
|
|
47 return s;
|
|
48 }
|
|
49
|
|
50 return NULL;
|
|
51 }
|