ar.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * ar.c - primitives for ar handling
  4. *
  5. * Copyright © 2010 Guillem Jover <guillem@debian.org>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. #ifndef LIBDPKG_AR_H
  21. #define LIBDPKG_AR_H
  22. #include <sys/types.h>
  23. #include <stdbool.h>
  24. #include <ar.h>
  25. #include <dpkg/macros.h>
  26. DPKG_BEGIN_DECLS
  27. /**
  28. * @defgroup ar Ar archive handling
  29. * @ingroup dpkg-public
  30. * @{
  31. */
  32. #define DPKG_AR_MAGIC "!<arch>\n"
  33. /**
  34. * An archive (Unix ar) file.
  35. */
  36. struct dpkg_ar {
  37. const char *name;
  38. mode_t mode;
  39. time_t time;
  40. off_t size;
  41. int fd;
  42. };
  43. /**
  44. * In-memory archive member information.
  45. */
  46. struct dpkg_ar_member {
  47. struct dpkg_ar_member *next;
  48. const char *name;
  49. off_t offset;
  50. off_t size;
  51. time_t time;
  52. mode_t mode;
  53. uid_t uid;
  54. gid_t gid;
  55. };
  56. struct dpkg_ar *
  57. dpkg_ar_fdopen(const char *filename, int fd);
  58. struct dpkg_ar *dpkg_ar_open(const char *filename);
  59. struct dpkg_ar *dpkg_ar_create(const char *filename, mode_t mode);
  60. void dpkg_ar_set_mtime(struct dpkg_ar *ar, time_t mtime);
  61. void dpkg_ar_close(struct dpkg_ar *ar);
  62. void dpkg_ar_normalize_name(struct ar_hdr *arh);
  63. bool dpkg_ar_member_is_illegal(struct ar_hdr *arh);
  64. void dpkg_ar_put_magic(struct dpkg_ar *ar);
  65. void dpkg_ar_member_put_header(struct dpkg_ar *ar,
  66. struct dpkg_ar_member *member);
  67. void dpkg_ar_member_put_file(struct dpkg_ar *ar, const char *name,
  68. int fd, off_t size);
  69. void dpkg_ar_member_put_mem(struct dpkg_ar *ar, const char *name,
  70. const void *data, size_t size);
  71. off_t dpkg_ar_member_get_size(struct dpkg_ar *ar, struct ar_hdr *arh);
  72. /** @} */
  73. DPKG_END_DECLS
  74. #endif /* LIBDPKG_AR_H */