GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 /*********************************************************** 00003 * I_get_to_eol (line,len,fd) 00004 * 00005 * Reads from fd until the newline, copying the first len-1 00006 * characters into line. The newline is not copied. 00007 * len should be the length of line in bytes. This allows for 00008 * a NULL to be added at the end. 00009 ***********************************************************/ 00010 #include <grass/imagery.h> 00011 #include <stdio.h> 00012 int I_get_to_eol(char *line, int len, FILE * fd) 00013 { 00014 int c; 00015 int n; 00016 00017 n = len - 1; 00018 while ((c = fgetc(fd)) >= 0 && c != '\n') 00019 if (n-- > 0) 00020 *line++ = c; 00021 if (len > 0) 00022 *line = 0; 00023 return c == '\n'; 00024 }