GRASS GIS 7 Programmer's Manual  7.0.3(2016)-r00000
getl.c
Go to the documentation of this file.
1 
14 #include <stdio.h>
15 #include <grass/gis.h>
16 
31 int G_getl(char *buf, int n, FILE * fd)
32 {
33  if (!fgets(buf, n, fd))
34  return 0;
35 
36  for (; *buf && *buf != '\n'; buf++) ;
37  *buf = 0;
38 
39  return 1;
40 }
41 
64 int G_getl2(char *buf, int n, FILE * fd)
65 {
66  int i = 0;
67  int c;
68  int ret = 1;
69 
70  while (i < n - 1) {
71  c = fgetc(fd);
72 
73  if (c == EOF) {
74  if (i == 0) { /* Read correctly (return 1) last line in file without '\n' */
75  ret = 0;
76  }
77  break;
78  }
79 
80  if (c == '\n')
81  break; /* UNIX */
82 
83  if (c == '\r') { /* DOS or MacOS9 */
84  if ((c = fgetc(fd)) != EOF) {
85  if (c != '\n') { /* MacOS9 - we have to return the char to stream */
86  ungetc(c, fd);
87  }
88  }
89  break;
90  }
91 
92  buf[i] = c;
93 
94  i++;
95  }
96  buf[i] = '\0';
97 
98  return ret;
99 }
int G_getl2(char *buf, int n, FILE *fd)
Gets a line of text from a file of any pedigree.
Definition: getl.c:64
int G_getl(char *buf, int n, FILE *fd)
Gets a line of text from a file.
Definition: getl.c:31