buffer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_WRITE_MD5 5
  33. #define BUFFER_READ_FD 0
  34. struct buffer_data {
  35. union {
  36. void *ptr;
  37. int i;
  38. } arg;
  39. int type;
  40. };
  41. # define buffer_md5(buf, hash, limit) \
  42. buffer_hash(buf, hash, BUFFER_WRITE_MD5, limit)
  43. # define fd_md5(fd, hash, limit, ...) \
  44. buffer_copy_IntPtr(fd, BUFFER_READ_FD, hash, BUFFER_WRITE_MD5, \
  45. limit, __VA_ARGS__)
  46. # define fd_fd_copy(fd1, fd2, limit, ...) \
  47. buffer_copy_IntInt(fd1, BUFFER_READ_FD, fd2, BUFFER_WRITE_FD, \
  48. limit, __VA_ARGS__)
  49. # define fd_vbuf_copy(fd, buf, limit, ...) \
  50. buffer_copy_IntPtr(fd, BUFFER_READ_FD, buf, BUFFER_WRITE_VBUF, \
  51. limit, __VA_ARGS__)
  52. # define fd_null_copy(fd, limit, ...) \
  53. buffer_skip_Int(fd, BUFFER_READ_FD, limit, __VA_ARGS__)
  54. off_t buffer_copy_IntPtr(int i, int typeIn, void *p, int typeOut,
  55. off_t limit, const char *desc,
  56. ...) DPKG_ATTR_PRINTF(6);
  57. off_t buffer_copy_IntInt(int i1, int typeIn, int i2, int typeOut,
  58. off_t limit, const char *desc,
  59. ...) DPKG_ATTR_PRINTF(6);
  60. off_t buffer_skip_Int(int I, int T, off_t limit, const char *desc_fmt, ...)
  61. DPKG_ATTR_PRINTF(4);
  62. off_t buffer_hash(const void *buf, void *hash, int typeOut, off_t length);
  63. DPKG_END_DECLS
  64. #endif /* LIBDPKG_BUFFER_H */