buffer.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <https://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. #include <dpkg/error.h>
  28. DPKG_BEGIN_DECLS
  29. /**
  30. * @defgroup buffer Buffer I/O
  31. * @ingroup dpkg-internal
  32. * @{
  33. */
  34. #define DPKG_BUFFER_SIZE 4096
  35. #define BUFFER_WRITE_VBUF 1
  36. #define BUFFER_WRITE_FD 2
  37. #define BUFFER_WRITE_NULL 3
  38. #define BUFFER_FILTER_NULL 4
  39. #define BUFFER_FILTER_MD5 5
  40. #define BUFFER_READ_FD 0
  41. struct buffer_data {
  42. union {
  43. void *ptr;
  44. int i;
  45. } arg;
  46. int type;
  47. };
  48. # define buffer_md5(buf, hash, limit) \
  49. buffer_filter(buf, hash, BUFFER_FILTER_MD5, limit)
  50. # define fd_md5(fd, hash, limit, err) \
  51. buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
  52. hash, BUFFER_FILTER_MD5, \
  53. NULL, BUFFER_WRITE_NULL, \
  54. limit, err)
  55. # define fd_fd_copy(fd1, fd2, limit, err) \
  56. buffer_copy_IntInt(fd1, BUFFER_READ_FD, \
  57. NULL, BUFFER_FILTER_NULL, \
  58. fd2, BUFFER_WRITE_FD, \
  59. limit, err)
  60. # define fd_fd_copy_and_md5(fd1, fd2, hash, limit, err) \
  61. buffer_copy_IntInt(fd1, BUFFER_READ_FD, \
  62. hash, BUFFER_FILTER_MD5, \
  63. fd2, BUFFER_WRITE_FD, \
  64. limit, err)
  65. # define fd_vbuf_copy(fd, buf, limit, err) \
  66. buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
  67. NULL, BUFFER_FILTER_NULL, \
  68. buf, BUFFER_WRITE_VBUF, \
  69. limit, err)
  70. # define fd_skip(fd, limit, err) \
  71. buffer_skip_Int(fd, BUFFER_READ_FD, limit, err)
  72. off_t buffer_copy_IntPtr(int i, int typeIn,
  73. void *f, int typeFilter,
  74. void *p, int typeOut,
  75. off_t limit, struct dpkg_error *err)
  76. DPKG_ATTR_REQRET;
  77. off_t buffer_copy_IntInt(int i1, int typeIn,
  78. void *f, int typeFilter,
  79. int i2, int typeOut,
  80. off_t limit, struct dpkg_error *err)
  81. DPKG_ATTR_REQRET;
  82. off_t buffer_skip_Int(int I, int T, off_t limit, struct dpkg_error *err)
  83. DPKG_ATTR_REQRET;
  84. off_t buffer_filter(const void *buf, void *hash, int typeFilter, off_t length);
  85. /** @} */
  86. DPKG_END_DECLS
  87. #endif /* LIBDPKG_BUFFER_H */