ar.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #define DPKG_AR_FMAG "`\n"
  34. /**
  35. * An on-disk archive header.
  36. */
  37. struct dpkg_ar_hdr {
  38. char ar_name[16]; /* Member file name, sometimes / terminated. */
  39. char ar_date[12]; /* File date, decimal seconds since Epoch. */
  40. char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */
  41. char ar_mode[8]; /* File mode, in ASCII octal. */
  42. char ar_size[10]; /* File size, in ASCII decimal. */
  43. char ar_fmag[2];
  44. };
  45. /**
  46. * An archive (Unix ar) file.
  47. */
  48. struct dpkg_ar {
  49. const char *name;
  50. mode_t mode;
  51. time_t time;
  52. off_t size;
  53. int fd;
  54. };
  55. /**
  56. * In-memory archive member information.
  57. */
  58. struct dpkg_ar_member {
  59. struct dpkg_ar_member *next;
  60. const char *name;
  61. off_t offset;
  62. off_t size;
  63. time_t time;
  64. mode_t mode;
  65. uid_t uid;
  66. gid_t gid;
  67. };
  68. struct dpkg_ar *
  69. dpkg_ar_fdopen(const char *filename, int fd);
  70. struct dpkg_ar *dpkg_ar_open(const char *filename);
  71. struct dpkg_ar *dpkg_ar_create(const char *filename, mode_t mode);
  72. void dpkg_ar_set_mtime(struct dpkg_ar *ar, time_t mtime);
  73. void dpkg_ar_close(struct dpkg_ar *ar);
  74. void dpkg_ar_normalize_name(struct dpkg_ar_hdr *arh);
  75. bool dpkg_ar_member_is_illegal(struct dpkg_ar_hdr *arh);
  76. void dpkg_ar_put_magic(struct dpkg_ar *ar);
  77. void dpkg_ar_member_put_header(struct dpkg_ar *ar,
  78. struct dpkg_ar_member *member);
  79. void dpkg_ar_member_put_file(struct dpkg_ar *ar, const char *name,
  80. int fd, off_t size);
  81. void dpkg_ar_member_put_mem(struct dpkg_ar *ar, const char *name,
  82. const void *data, size_t size);
  83. off_t dpkg_ar_member_get_size(struct dpkg_ar *ar, struct dpkg_ar_hdr *arh);
  84. /** @} */
  85. DPKG_END_DECLS
  86. #endif /* LIBDPKG_AR_H */