GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
FILE * fd
Definition: g3dcolor.c:368
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
Definition: getl.c:52
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int G_getl(char *buf, int n, FILE *fd)
gets a line of text from a file
Definition: getl.c:17
int n
Definition: dataquad.c:291