X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fxheader.c;h=023c0bb262930dd38e4d08f0ddd79ba5079dae37;hb=4ef056729e5dc97952d04590afe33422ff6bb938;hp=d880bd5600a5ef9f3873b07632a3cab23b5f684b;hpb=9590e781c0ed2ea8a792327fc17d6bb122a92b04;p=chaz%2Ftar diff --git a/src/xheader.c b/src/xheader.c index d880bd5..023c0bb 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -1,6 +1,6 @@ /* POSIX extended headers for tar. - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -157,7 +157,7 @@ xheader_list_destroy (struct keyword_list **root) static void xheader_set_single_keyword (char *kw) { - USAGE_ERROR ((0, 0, _("Keyword %s is unknown or not yet imlemented"), kw)); + USAGE_ERROR ((0, 0, _("Keyword %s is unknown or not yet implemented"), kw)); } static void @@ -374,17 +374,6 @@ xheader_write (char type, char *name, struct xheader *xhdr) size_t size; char *p; - if (multi_volume_option) - { - /* Estimate the total size of the extended header and, in case - if XHDTYPE, the ustar header following it, and make sure that - these fit into the current volume */ - size_t hblocks = 1 + (extended_header.size + BLOCKSIZE - 1) / BLOCKSIZE; - if (type == XHDTYPE) - hblocks++; - multi_volume_fixup (hblocks); - } - size = xhdr->size; header = start_private_header (name, size); header->header.typeflag = type; @@ -415,44 +404,6 @@ xheader_write (char type, char *name, struct xheader *xhdr) global_header_count++; } -/* SIZE is guaranteed to be divisible by BLOCKSIZE */ -void -xheader_eof (size_t size) -{ - union block *header; - char *name; - int first_block = 1; - int nl = 0; - - size -= BLOCKSIZE; - name = xheader_ghdr_name (); - header = start_private_header (name, size); - header->header.typeflag = XGLTYPE; - free (name); - simple_finish_header (header); - if (size) - nl = 1; - while (size > 0) - { - size_t len; - - header = find_next_block (); - len = BLOCKSIZE; - if (len > size) - len = size; - memset (header->buffer, 0, len); - if (first_block) - { - first_block = 0; - sprintf (header->buffer, "%d GNU.volume.eof=", size); - } - size -= len; - set_next_block_after (header); - } - if (nl) - header->buffer[BLOCKSIZE-1] = '\n'; -} - void xheader_write_global (void) { @@ -668,20 +619,6 @@ extended_header_init (void) } } -void -xheader_save (struct xheader *xhdr) -{ - *xhdr = extended_header; - memset (&extended_header, 0, sizeof extended_header); -} - -void -xheader_restore (struct xheader *xhdr) -{ - xheader_destroy (&extended_header); - extended_header = *xhdr; -} - void xheader_store (char const *keyword, struct tar_stat_info const *st, void const *data) @@ -899,8 +836,15 @@ code_time (struct timespec t, char const *keyword, struct xheader *xhdr) xheader_print (xhdr, keyword, code_timespec (t, buf)); } -static bool -decode_time (struct timespec *ts, char const *arg, char const *keyword) +enum decode_time_status + { + decode_time_success, + decode_time_range, + decode_time_bad_header + }; + +static enum decode_time_status +_decode_time (struct timespec *ts, char const *arg, char const *keyword) { time_t s; unsigned long int ns = 0; @@ -916,21 +860,21 @@ decode_time (struct timespec *ts, char const *arg, char const *keyword) { intmax_t i = strtoimax (arg, &arg_lim, 10); if (TYPE_SIGNED (time_t) ? i < TYPE_MINIMUM (time_t) : i < 0) - goto out_of_range; + return decode_time_range; s = i; } else { uintmax_t i = strtoumax (arg, &arg_lim, 10); if (TYPE_MAXIMUM (time_t) < i) - goto out_of_range; + return decode_time_range; s = i; } p = arg_lim; if (errno == ERANGE) - goto out_of_range; + return decode_time_range; if (*p == '.') { @@ -958,7 +902,7 @@ decode_time (struct timespec *ts, char const *arg, char const *keyword) if (ns != 0) { if (s == TYPE_MINIMUM (time_t)) - goto out_of_range; + return decode_time_range; s--; ns = BILLION - ns; } @@ -969,20 +913,34 @@ decode_time (struct timespec *ts, char const *arg, char const *keyword) { ts->tv_sec = s; ts->tv_nsec = ns; - return true; + return decode_time_success; } } - ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"), - keyword, arg)); - return false; + return decode_time_bad_header; +} - out_of_range: - out_of_range_header (keyword, arg, - (uintmax_t) TYPE_MINIMUM (time_t), - TYPE_MAXIMUM (time_t)); - return false; +static bool +decode_time (struct timespec *ts, char const *arg, char const *keyword) +{ + switch (_decode_time (ts, arg, keyword)) + { + case decode_time_success: + return true; + case decode_time_bad_header: + ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"), + keyword, arg)); + return false; + case decode_time_range: + out_of_range_header (keyword, arg, - (uintmax_t) TYPE_MINIMUM (time_t), + TYPE_MAXIMUM (time_t)); + return false; + } + return true; } + + static void code_num (uintmax_t value, char const *keyword, struct xheader *xhdr) { @@ -1312,7 +1270,7 @@ sparse_map_decoder (struct tar_stat_info *st, char const *arg, else { ERROR ((0, 0, _("Malformed extended header: excess %s=%s"), - "GNU.sparse.numbytes", arg)); + keyword, arg)); return; } }