GRASS Programmer's Manual
6.4.3(2013)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Macros
Pages
getl.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <grass/gis.h>
3
17
int
G_getl
(
char
*buf,
int
n, FILE * fd)
18
{
19
if
(!fgets(buf, n, fd))
20
return
0;
21
22
for
(; *buf && *buf !=
'\n'
; buf++) ;
23
*buf = 0;
24
25
return
1;
26
}
27
28
29
52
int
G_getl2
(
char
*buf,
int
n, FILE * fd)
53
{
54
int
i = 0;
55
int
c;
56
int
ret = 1;
57
58
while
(i < n - 1) {
59
c = fgetc(fd);
60
61
if
(c == EOF) {
62
if
(i == 0) {
/* Read correctly (return 1) last line in file without '\n' */
63
ret = 0;
64
}
65
break
;
66
}
67
68
if
(c ==
'\n'
)
69
break
;
/* UNIX */
70
71
if
(c ==
'\r'
) {
/* DOS or MacOS9 */
72
if
((c = fgetc(fd)) != EOF) {
73
if
(c !=
'\n'
) {
/* MacOS9 - we have to return the char to stream */
74
ungetc(c, fd);
75
}
76
}
77
break
;
78
}
79
80
buf[i] = c;
81
82
i++;
83
}
84
buf[i] =
'\0'
;
85
86
return
ret;
87
}
lib
gis
getl.c
Generated on Sat Oct 5 2013 12:11:07 for GRASS Programmer's Manual by
1.8.4