diff options
author | Tim Kientzle <kientzle@gmail.com> | 2010-03-01 00:36:29 -0500 |
---|---|---|
committer | Tim Kientzle <kientzle@gmail.com> | 2010-03-01 00:36:29 -0500 |
commit | 42c1f3e1243e684bc003d857450496a274d16a31 (patch) | |
tree | 9cb18cff0a6a3f22efa65645d6f6d16f053d308e /libarchive/archive_private.h | |
parent | 061edc88add6320353d46c385829e6e16b0e4e89 (diff) | |
download | libarchive-42c1f3e1243e684bc003d857450496a274d16a31.tar.gz |
Open a door to changing the current abort-on-state-failure behavior:
* Change __archive_check_magic to return a status code.
* Change callers to use the archive_check_magic() wrapper macro,
which calls __archive_check_magic and returns immediately
if there's an ARCHIVE_FATAL status.
* Update a bunch of API calls to actually do magic state checks.
I've also changed __archive_check_magic around a little bit:
* Magic number checks still call abort().
* State failures still call abort()
* Starting with libarchive 3.0, state failures will return ARCHIVE_FATAL.
SVN-Revision: 2003
Diffstat (limited to 'libarchive/archive_private.h')
-rw-r--r-- | libarchive/archive_private.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libarchive/archive_private.h b/libarchive/archive_private.h index df83b769..862eb032 100644 --- a/libarchive/archive_private.h +++ b/libarchive/archive_private.h @@ -47,13 +47,13 @@ #define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) #define ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U) -#define ARCHIVE_STATE_ANY 0xFFFFU #define ARCHIVE_STATE_NEW 1U #define ARCHIVE_STATE_HEADER 2U #define ARCHIVE_STATE_DATA 4U #define ARCHIVE_STATE_EOF 0x10U #define ARCHIVE_STATE_CLOSED 0x20U #define ARCHIVE_STATE_FATAL 0x8000U +#define ARCHIVE_STATE_ANY (0xFFFFU & ~ARCHIVE_STATE_FATAL) struct archive_vtable { int (*archive_close)(struct archive *); @@ -102,9 +102,16 @@ struct archive { struct archive_string error_string; }; -/* Check magic value and state; exit if it isn't valid. */ -void __archive_check_magic(struct archive *, unsigned int magic, +/* Check magic value and state; return(ARCHIVE_FATAL) if it isn't valid. */ +int __archive_check_magic(struct archive *, unsigned int magic, unsigned int state, const char *func); +#define archive_check_magic(a, expected_magic, allowed_states, function_name) \ + do { \ + int magic_test = __archive_check_magic((a), (expected_magic), \ + (allowed_states), (function_name)); \ + if (magic_test == ARCHIVE_FATAL) \ + return ARCHIVE_FATAL; \ + } while (0) void __archive_errx(int retvalue, const char *msg) __LA_DEAD; |