line_buffer.h 978 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef LINE_BUFFER_H
  2. #define LINE_BUFFER_H
  3. #include "strbuf.h"
  4. #define LINE_BUFFER_LEN 10000
  5. struct line_buffer {
  6. char line_buffer[LINE_BUFFER_LEN];
  7. FILE *infile;
  8. };
  9. #define LINE_BUFFER_INIT { "", NULL }
  10. int buffer_init(struct line_buffer *buf, const char *filename);
  11. int buffer_fdinit(struct line_buffer *buf, int fd);
  12. int buffer_deinit(struct line_buffer *buf);
  13. int buffer_tmpfile_init(struct line_buffer *buf);
  14. FILE *buffer_tmpfile_rewind(struct line_buffer *buf); /* prepare to write. */
  15. long buffer_tmpfile_prepare_to_read(struct line_buffer *buf);
  16. int buffer_ferror(struct line_buffer *buf);
  17. char *buffer_read_line(struct line_buffer *buf);
  18. int buffer_read_char(struct line_buffer *buf);
  19. size_t buffer_read_binary(struct line_buffer *buf, struct strbuf *sb, size_t len);
  20. /* Returns number of bytes read (not necessarily written). */
  21. off_t buffer_copy_bytes(struct line_buffer *buf, off_t len);
  22. off_t buffer_skip_bytes(struct line_buffer *buf, off_t len);
  23. #endif