2
0

lzio.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. ** $Id: lzio.h,v 1.6 2000/05/24 13:54:49 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. #ifndef ZBSIZE
  25. #define ZBSIZE 256 /* buffer size */
  26. #endif
  27. struct zio {
  28. size_t n; /* bytes still unread */
  29. const unsigned char* p; /* current position in buffer */
  30. int (*filbuf)(ZIO* z);
  31. void* u; /* additional data */
  32. const char *name;
  33. unsigned char buffer[ZBSIZE]; /* buffer */
  34. };
  35. #endif