eol.c 627 B

12345678910111213141516171819202122232425
  1. /***********************************************************
  2. * I_get_to_eol (line,len,fd)
  3. *
  4. * Reads from fd until the newline, copying the first len-1
  5. * characters into line. The newline is not copied.
  6. * len should be the length of line in bytes. This allows for
  7. * a NULL to be added at the end.
  8. ***********************************************************/
  9. #include <grass/imagery.h>
  10. #include <stdio.h>
  11. int I_get_to_eol(char *line, int len, FILE * fd)
  12. {
  13. int c;
  14. int n;
  15. n = len - 1;
  16. while ((c = fgetc(fd)) >= 0 && c != '\n')
  17. if (n-- > 0)
  18. *line++ = c;
  19. if (len > 0)
  20. *line = 0;
  21. return c == '\n';
  22. }