/usr.bin/ar/ar.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 125 lines · 67 code · 12 blank · 46 comment · 2 complexity · e318e6bc088eea5149b243908fac4d06 MD5 · raw file

  1. /*-
  2. * Copyright (c) 2007 Kai Wang
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer
  10. * in this position and unchanged.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. * $FreeBSD$
  27. */
  28. #define BSDAR_VERSION "1.1.0"
  29. /*
  30. * ar(1) options.
  31. */
  32. #define AR_A 0x0001 /* position-after */
  33. #define AR_B 0x0002 /* position-before */
  34. #define AR_C 0x0004 /* creating new archive */
  35. #define AR_CC 0x0008 /* do not overwrite when extracting */
  36. #define AR_J 0x0010 /* bzip2 compression */
  37. #define AR_O 0x0020 /* preserve original mtime when extracting */
  38. #define AR_S 0x0040 /* write archive symbol table */
  39. #define AR_SS 0x0080 /* do not write archive symbol table */
  40. #define AR_TR 0x0100 /* only keep first 15 chars for member name */
  41. #define AR_U 0x0200 /* only extract or update newer members.*/
  42. #define AR_V 0x0400 /* verbose mode */
  43. #define AR_Z 0x0800 /* gzip compression */
  44. #define AR_D 0x1000 /* insert dummy mode, mtime, uid and gid */
  45. #define DEF_BLKSZ 10240 /* default block size */
  46. /*
  47. * Convenient wrapper for general libarchive error handling.
  48. */
  49. #define AC(CALL) do { \
  50. if ((CALL)) \
  51. bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s", \
  52. archive_error_string(a)); \
  53. } while (0)
  54. /*
  55. * In-memory representation of archive member(object).
  56. */
  57. struct ar_obj {
  58. char *name; /* member name */
  59. void *maddr; /* mmap start address */
  60. uid_t uid; /* user id */
  61. gid_t gid; /* group id */
  62. mode_t md; /* octal file permissions */
  63. size_t size; /* member size */
  64. time_t mtime; /* modification time */
  65. int fd; /* file descriptor */
  66. dev_t dev; /* inode's device */
  67. ino_t ino; /* inode's number */
  68. TAILQ_ENTRY(ar_obj) objs;
  69. };
  70. /*
  71. * Structure encapsulates the "global" data for "ar" program.
  72. */
  73. struct bsdar {
  74. const char *filename; /* archive name. */
  75. const char *addlib; /* target of ADDLIB. */
  76. const char *posarg; /* position arg for modifiers -a, -b. */
  77. char mode; /* program mode */
  78. int options; /* command line options */
  79. const char *progname; /* program name */
  80. int argc;
  81. char **argv;
  82. /*
  83. * Fields for the archive string table.
  84. */
  85. char *as; /* buffer for archive string table. */
  86. size_t as_sz; /* current size of as table. */
  87. size_t as_cap; /* capacity of as table buffer. */
  88. /*
  89. * Fields for the archive symbol table.
  90. */
  91. uint32_t s_cnt; /* current number of symbols. */
  92. uint32_t *s_so; /* symbol offset table. */
  93. size_t s_so_cap; /* capacity of so table buffer. */
  94. char *s_sn; /* symbol name table */
  95. size_t s_sn_cap; /* capacity of sn table buffer. */
  96. size_t s_sn_sz; /* current size of sn table. */
  97. /* Current member's offset (relative to the end of pseudo members.) */
  98. off_t rela_off;
  99. TAILQ_HEAD(, ar_obj) v_obj; /* object(member) list */
  100. };
  101. void bsdar_errc(struct bsdar *, int _eval, int _code,
  102. const char *fmt, ...);
  103. void bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...);
  104. void ar_mode_d(struct bsdar *bsdar);
  105. void ar_mode_m(struct bsdar *bsdar);
  106. void ar_mode_p(struct bsdar *bsdar);
  107. void ar_mode_q(struct bsdar *bsdar);
  108. void ar_mode_r(struct bsdar *bsdar);
  109. void ar_mode_s(struct bsdar *bsdar);
  110. void ar_mode_t(struct bsdar *bsdar);
  111. void ar_mode_x(struct bsdar *bsdar);
  112. void ar_mode_A(struct bsdar *bsdar);
  113. void ar_mode_script(struct bsdar *ar);