2
0

lzio.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. ** $Id: lzio.h,v 1.7 2000/10/20 16:36:32 roberto Exp roberto $
  3. ** Buffered streams
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lzio_h
  7. #define lzio_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, const char *name); /* open FILEs */
  17. ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */
  18. ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name); /* memory */
  19. size_t zread (ZIO* z, void* b, size_t n); /* read next n bytes */
  20. #define zgetc(z) (((z)->n--)>0 ? ((int)*(z)->p++): (z)->filbuf(z))
  21. #define zname(z) ((z)->name)
  22. /* --------- Private Part ------------------ */
  23. #ifndef ZBSIZE
  24. #define ZBSIZE 256 /* buffer size */
  25. #endif
  26. struct zio {
  27. size_t n; /* bytes still unread */
  28. const unsigned char* p; /* current position in buffer */
  29. int (*filbuf)(ZIO* z);
  30. void* u; /* additional data */
  31. const char *name;
  32. unsigned char buffer[ZBSIZE]; /* buffer */
  33. };
  34. #endif