lzio.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. ** $Id: lzio.h,v 1.5 1999/08/16 20:52:00 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 zungetc(z) (++(z)->n,--(z)->p)
  22. #define zname(z) ((z)->name)
  23. /* --------- Private Part ------------------ */
  24. #define ZBSIZE 256 /* buffer size */
  25. struct zio {
  26. size_t n; /* bytes still unread */
  27. const unsigned char* p; /* current position in buffer */
  28. int (*filbuf)(ZIO* z);
  29. void* u; /* additional data */
  30. const char *name;
  31. unsigned char buffer[ZBSIZE]; /* buffer */
  32. };
  33. #endif