zio.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * zio.h
  3. * a generic input stream interface
  4. * $Id: zio.h,v 1.4 1997/06/13 13:49:16 lhf Exp $
  5. */
  6. #ifndef zio_h
  7. #define zio_h
  8. #include <stdio.h>
  9. #define EOZ (-1) /* end of stream */
  10. typedef struct zio ZIO;
  11. int zgetc(ZIO* z); /* get next byte */
  12. int zungetc(ZIO* z); /* put back last byte read */
  13. int zread(ZIO* z, void* b, int n); /* read next n bytes */
  14. int zclose(ZIO* z); /* close stream */
  15. ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */
  16. ZIO* zfopen(ZIO* z, char* s, char* m); /* file by name */
  17. ZIO* zpopen(ZIO* z, char* s, char* m); /* pipe */
  18. ZIO* zsopen(ZIO* z, char* s); /* string */
  19. ZIO* zmopen(ZIO* z, char* b, int size); /* memory */
  20. #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
  21. #define zungetc(z) (++(z)->n,--(z)->p)
  22. #define zclose(z) (*(z)->close)(z)
  23. /* --------- Private Part ------------------ */
  24. #define ZBSIZE 256 /* buffer size */
  25. struct zio {
  26. int n; /* bytes still unread */
  27. unsigned char* p; /* current position in buffer */
  28. int (*filbuf)(ZIO* z);
  29. int (*close)(ZIO* z);
  30. void* u; /* additional data */
  31. unsigned char buffer[ZBSIZE]; /* buffer */
  32. };
  33. #endif