buffer.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * buffer.h - buffer I/O handling routines
  4. *
  5. * Copyright © 1999, 2000 Wichert Akkerman <wakkerma@debian.org>
  6. * Copyright © 2000-2003 Adam Heath <doogie@debian.org>
  7. * Copyright © 2005 Scott James Remnant
  8. * Copyright © 2008-2011 Guillem Jover <guillem@debian.org>
  9. *
  10. * This is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #ifndef LIBDPKG_BUFFER_H
  24. #define LIBDPKG_BUFFER_H
  25. #include <sys/types.h>
  26. #include <dpkg/macros.h>
  27. DPKG_BEGIN_DECLS
  28. #define DPKG_BUFFER_SIZE 4096
  29. #define BUFFER_WRITE_VBUF 1
  30. #define BUFFER_WRITE_FD 2
  31. #define BUFFER_WRITE_NULL 3
  32. #define BUFFER_FILTER_NULL 4
  33. #define BUFFER_FILTER_MD5 5
  34. #define BUFFER_READ_FD 0
  35. struct buffer_data {
  36. union {
  37. void *ptr;
  38. int i;
  39. } arg;
  40. int type;
  41. };
  42. # define buffer_md5(buf, hash, limit) \
  43. buffer_filter(buf, hash, BUFFER_FILTER_MD5, limit)
  44. # define fd_md5(fd, hash, limit, ...) \
  45. buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
  46. hash, BUFFER_FILTER_MD5, \
  47. NULL, BUFFER_WRITE_NULL, \
  48. limit, __VA_ARGS__)
  49. # define fd_fd_copy(fd1, fd2, limit, ...) \
  50. buffer_copy_IntInt(fd1, BUFFER_READ_FD, \
  51. NULL, BUFFER_FILTER_NULL, \
  52. fd2, BUFFER_WRITE_FD, \
  53. limit, __VA_ARGS__)
  54. # define fd_vbuf_copy(fd, buf, limit, ...) \
  55. buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
  56. NULL, BUFFER_FILTER_NULL, \
  57. buf, BUFFER_WRITE_VBUF, \
  58. limit, __VA_ARGS__)
  59. # define fd_skip(fd, limit, ...) \
  60. buffer_skip_Int(fd, BUFFER_READ_FD, limit, __VA_ARGS__)
  61. off_t buffer_copy_IntPtr(int i, int typeIn,
  62. void *f, int typeFilter,
  63. void *p, int typeOut,
  64. off_t limit, const char *desc,
  65. ...) DPKG_ATTR_PRINTF(8);
  66. off_t buffer_copy_IntInt(int i1, int typeIn,
  67. void *f, int typeFilter,
  68. int i2, int typeOut,
  69. off_t limit, const char *desc,
  70. ...) DPKG_ATTR_PRINTF(8);
  71. off_t buffer_skip_Int(int I, int T, off_t limit, const char *desc_fmt, ...)
  72. DPKG_ATTR_PRINTF(4);
  73. off_t buffer_filter(const void *buf, void *hash, int typeFilter, off_t length);
  74. DPKG_END_DECLS
  75. #endif /* LIBDPKG_BUFFER_H */