buffer.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 BUFFER_WRITE_VBUF 1
  29. #define BUFFER_WRITE_FD 2
  30. #define BUFFER_WRITE_NULL 3
  31. #define BUFFER_WRITE_MD5 5
  32. #define BUFFER_READ_FD 0
  33. struct buffer_data {
  34. union {
  35. void *ptr;
  36. int i;
  37. } arg;
  38. int type;
  39. };
  40. # define buffer_md5(buf, hash, limit) \
  41. buffer_hash(buf, hash, BUFFER_WRITE_MD5, limit)
  42. # define fd_md5(fd, hash, limit, ...) \
  43. buffer_copy_IntPtr(fd, BUFFER_READ_FD, hash, BUFFER_WRITE_MD5, \
  44. limit, __VA_ARGS__)
  45. # define fd_fd_copy(fd1, fd2, limit, ...) \
  46. buffer_copy_IntInt(fd1, BUFFER_READ_FD, fd2, BUFFER_WRITE_FD, \
  47. limit, __VA_ARGS__)
  48. # define fd_vbuf_copy(fd, buf, limit, ...) \
  49. buffer_copy_IntPtr(fd, BUFFER_READ_FD, buf, BUFFER_WRITE_VBUF, \
  50. limit, __VA_ARGS__)
  51. # define fd_null_copy(fd, limit, ...) \
  52. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  53. if (errno != ESPIPE) \
  54. ohshite(__VA_ARGS__); \
  55. buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
  56. NULL, BUFFER_WRITE_NULL, \
  57. limit, __VA_ARGS__); \
  58. }
  59. off_t buffer_copy_IntPtr(int i, int typeIn, void *p, int typeOut,
  60. off_t limit, const char *desc,
  61. ...) DPKG_ATTR_PRINTF(6);
  62. off_t buffer_copy_IntInt(int i1, int typeIn, int i2, int typeOut,
  63. off_t limit, const char *desc,
  64. ...) DPKG_ATTR_PRINTF(6);
  65. off_t buffer_hash(const void *buf, void *hash, int typeOut, off_t length);
  66. DPKG_END_DECLS
  67. #endif /* LIBDPKG_BUFFER_H */