archive_private.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*-
  2. * Copyright (c) 2003-2007 Tim Kientzle
  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. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * $FreeBSD: src/lib/libarchive/archive_private.h,v 1.32 2008/12/06 06:23:37 kientzle Exp $
  26. */
  27. #ifndef ARCHIVE_PRIVATE_H_INCLUDED
  28. #define ARCHIVE_PRIVATE_H_INCLUDED
  29. #include "archive.h"
  30. #include "archive_string.h"
  31. #if defined(__GNUC__) && (__GNUC__ > 2 || \
  32. (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
  33. #define __LA_DEAD __attribute__((__noreturn__))
  34. #else
  35. #define __LA_DEAD
  36. #endif
  37. #define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU)
  38. #define ARCHIVE_READ_MAGIC (0xdeb0c5U)
  39. #define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U)
  40. #define ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U)
  41. #define ARCHIVE_STATE_ANY 0xFFFFU
  42. #define ARCHIVE_STATE_NEW 1U
  43. #define ARCHIVE_STATE_HEADER 2U
  44. #define ARCHIVE_STATE_DATA 4U
  45. #define ARCHIVE_STATE_DATA_END 8U
  46. #define ARCHIVE_STATE_EOF 0x10U
  47. #define ARCHIVE_STATE_CLOSED 0x20U
  48. #define ARCHIVE_STATE_FATAL 0x8000U
  49. struct archive_vtable {
  50. int (*archive_close)(struct archive *);
  51. int (*archive_finish)(struct archive *);
  52. int (*archive_write_header)(struct archive *,
  53. struct archive_entry *);
  54. int (*archive_write_finish_entry)(struct archive *);
  55. ssize_t (*archive_write_data)(struct archive *,
  56. const void *, size_t);
  57. ssize_t (*archive_write_data_block)(struct archive *,
  58. const void *, size_t, off_t);
  59. };
  60. struct archive {
  61. /*
  62. * The magic/state values are used to sanity-check the
  63. * client's usage. If an API function is called at a
  64. * ridiculous time, or the client passes us an invalid
  65. * pointer, these values allow me to catch that.
  66. */
  67. unsigned int magic;
  68. unsigned int state;
  69. /*
  70. * Some public API functions depend on the "real" type of the
  71. * archive object.
  72. */
  73. struct archive_vtable *vtable;
  74. int archive_format;
  75. const char *archive_format_name;
  76. int compression_code; /* Currently active compression. */
  77. const char *compression_name;
  78. /* Position in UNCOMPRESSED data stream. */
  79. off_t file_position;
  80. /* Position in COMPRESSED data stream. */
  81. off_t raw_position;
  82. /* Number of file entries processed. */
  83. int file_count;
  84. int archive_error_number;
  85. const char *error;
  86. struct archive_string error_string;
  87. };
  88. /* Check magic value and state; exit if it isn't valid. */
  89. void __archive_check_magic(struct archive *, unsigned int magic,
  90. unsigned int state, const char *func);
  91. void __archive_errx(int retvalue, const char *msg) __LA_DEAD;
  92. int __archive_parse_options(const char *p, const char *fn,
  93. int keysize, char *key, int valsize, char *val);
  94. #define err_combine(a,b) ((a) < (b) ? (a) : (b))
  95. #endif