zio.h 972 B

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