]> git.ipfire.org Git - thirdparty/tar.git/log
thirdparty/tar.git
8 months agoImprove common.h comment
Paul Eggert [Sat, 2 Nov 2024 16:54:26 +0000 (09:54 -0700)] 
Improve common.h comment

8 months agoCount short read slop when seeking
Paul Eggert [Sat, 2 Nov 2024 16:54:10 +0000 (09:54 -0700)] 
Count short read slop when seeking

* src/buffer.c (short_read_slop): New static var.
(get_archive_status): Treat anything other than fifos and sockets
as potentially seekable; they’ll tell us if they aren’t, whereas
fifos and sockets cannot be seekable.  Check named files for
initial offset too, to deal with names like /dev/stdin.
Do not worry about start_offset’s value if !seekable_archive,
as it won’t be used.  Use short_read_slop.
(short_read, try_new_volume, simple_flush_read, _gnu_flush_read):
Set short_read_slop.

8 months agoPrefer other types to int in xattrs.c
Paul Eggert [Sat, 2 Nov 2024 06:40:15 +0000 (23:40 -0700)] 
Prefer other types to int in xattrs.c

* src/xattrs.c (xattrs__acls_set) [HAVE_POSIX_ACLS]:
Prefer acl_type_t to int for ACL types.
(acls_get_text, xattrs_acls_get, xattrs_acls_set)
(xattrs_xattrs_get, xattrs_selinux_get, xattrs_selinux_set)
(xattrs_xattrs_set): Prefer bool for booleans.

8 months agoPrever other types to int in warning.c
Paul Eggert [Sat, 2 Nov 2024 06:26:53 +0000 (23:26 -0700)] 
Prever other types to int in warning.c

* src/warning.c (set_warning_option): Prefer bool for boolean.

8 months agoPrefer other types to int in transform.c
Paul Eggert [Sat, 2 Nov 2024 06:24:46 +0000 (23:24 -0700)] 
Prefer other types to int in transform.c

* src/transform.c (add_char_segment, parse_xform_flags)
(parse_transform_expr): Prefer char for char.
(parse_transform_expr): Don’t assume strlen (expr) <= INT_MAX.

8 months agoAvoid unlikely verbose_option overflow
Paul Eggert [Sat, 2 Nov 2024 06:18:30 +0000 (23:18 -0700)] 
Avoid unlikely verbose_option overflow

* src/tar.c (parse_opt, decode_options):
Avoid undefined behavior if verbose_option overflows.

8 months agoPrefer other types to int in system.c
Paul Eggert [Sat, 2 Nov 2024 03:03:53 +0000 (20:03 -0700)] 
Prefer other types to int in system.c

* src/system.c (is_regular_file, sys_exec_setmtime_script):
Prefer bool for boolean.
(sys_exec_command): Prefer char for char.

8 months agoPrefer other types to int in sparse.c
Paul Eggert [Sat, 2 Nov 2024 02:52:50 +0000 (19:52 -0700)] 
Prefer other types to int in sparse.c

* src/sparse.c (oldgnu_get_sparse_info, star_get_sparse_info):
Prefer char for char.

8 months agoPrefer other types to int in names.c
Paul Eggert [Sat, 2 Nov 2024 02:49:02 +0000 (19:49 -0700)] 
Prefer other types to int in names.c

* src/names.c (uname_to_uid, gname_to_gid, handle_option)
(make_file_name): Prefer bool for boolean.
(struct name_elt, read_name_from_file): Prefer char for char.
(handle_option): Invert sense of return value, for clarity.
All uses changed.
(merge_sort_sll, merge_sort, collect_and_sort_names):
Don’t assume list length fits in int.  Use intptr_t not idx_t,
since the bound is the size of all memory rather than one array.

8 months agoPrefer other types to int in misc.c
Paul Eggert [Sat, 2 Nov 2024 02:09:44 +0000 (19:09 -0700)] 
Prefer other types to int in misc.c

* src/misc.c (quote_copy_string, tar_savedir):
Use bool for booleans.  All uses changed.
(quote_copy_string): Use char for chars.
(unquote_string): Return void, since nobody uses return value.
(unquote_string): Check for overflow in escapes like \777.
(wdcache): Now array of idx_t not int, since in theory it
might contain values greater than INT_MAX.  All uses changed.

8 months agoPrefer other types to int in map.c
Paul Eggert [Sat, 2 Nov 2024 01:51:05 +0000 (18:51 -0700)] 
Prefer other types to int in map.c

* src/map.c (map_read): Prefer bool for booleans.
(owner_map_translate, group_map_translate):
Return void, not int, as nobody uses the return value.

8 months agoFix some uses of int in list.c
Paul Eggert [Sat, 2 Nov 2024 01:45:00 +0000 (18:45 -0700)] 
Fix some uses of int in list.c

* src/list.c (decode_xform): Last arg is now int, not a void *
pointer to that int.  All uses changed.
(enforce_one_top_level): Don’t assume string length fits in int.
(transform_stat_info): Prefer char to int for typeflag.
All uses changed.
(decode_header): Prefer bool for booleans.  All uses changed.
(ugswidth): Now idx_t, not int, since in theory it could
exceed INT_MAX.  All uses changed.
(simple_print_header, print_for_mkdir): Don’t assume printf length
fits in int, and similarly for length of user or group name.
* src/transform.c (transform_name_fp): Last arg is now int, not void *.
All uses changed.

8 months agoPrefer other types to int in incremen.c
Paul Eggert [Fri, 1 Nov 2024 21:27:21 +0000 (14:27 -0700)] 
Prefer other types to int in incremen.c

* src/incremen.c (struct dumpdir_iter, dumpdir_first)
(read_incr_db_01, dumpdir_ok, list_dumpdir):
Prefer bool to int for booleans.  All uses changed.
(read_incr_db_01): Don’t assume getline returns <= INT_MAX.
(dumpdir_ok): Prefer char to int for chars.

8 months agoPrefer other types to int in extract.c
Paul Eggert [Fri, 1 Nov 2024 21:15:09 +0000 (14:15 -0700)] 
Prefer other types to int in extract.c

* src/extract.c (fd_chmod, extract_chdir, open_output_file)
(extract_file, extract_link, extract_symlink, extract_node)
(extract_fifo, tar_extractor_t, pepare_to_extract): Prefer char to
int for typeflag, since it’s a char.  All uses changed.
(fd_chmod): Use clearer code for errno.
(extract_dir, extract_file, create_placeholder_file, extract_link)
(extract_symlink, extract_node, extract_fifo, tar_extractor_t):
Return bool true for success, false for failure.  All uses changed.
(open_output_file): Prefer bool for boolean.
(prepare_to_extract): Simplify by returning the extractor a null
pointer, rather than storing through a pointer to an extractor.

8 months agoPrefer other types to int in delete.c
Paul Eggert [Fri, 1 Nov 2024 20:48:53 +0000 (13:48 -0700)] 
Prefer other types to int in delete.c

* src/delete.c (write_record): Arg is bool, not int.
All callers changed.

8 months agoBe a bit more consistent about comparing to zero
Paul Eggert [Fri, 1 Nov 2024 20:44:33 +0000 (13:44 -0700)] 
Be a bit more consistent about comparing to zero

* src/buffer.c (xclose, archive_is_dev, close_archive)
(write_fatal_details, init_volume_number)
(closeout_volume_number, new_volume, try_new_volume):
* src/checkpoint.c (format_checkpoint_string):
* src/compare.c (process_rawdata, diff_file, diff_dumpdir):
* src/create.c (create_archive, restore_parent_fd, dump_file0):
* src/delete.c (delete_archive_members):
* src/exclist.c (cvs_addfn):
* src/extract.c (set_mode, mark_after_links, delay_set_stat)
(repair_delayed_set_stat, make_directories, file_newer_p)
(maybe_recoverable, apply_nonancestor_delayed_set_stat)
(extract_dir, open_output_file, find_delayed_link_source)
(create_placeholder_file, extract_symlink, extract_node)
(extract_fifo, apply_delayed_link):
* src/incremen.c (update_parent_directory, scan_directory)
(read_obstack, read_incr_db_2, write_directory_file)
(try_purge_directory):
* src/map.c (map_read):
* src/misc.c (maybe_backup_file, undo_last_backup, chdir_do)
(tar_savedir):
* src/names.c (handle_file_selection_option, add_file_id)
(handle_option, read_next_name, add_hierarchy_to_namelist)
(collect_and_sort_names):
* src/system.c (run_decompress_program, dec_to_env, time_to_env)
(oct_to_env, str_to_env, chr_to_env, sys_exec_setmtime_script):
* src/tar.c (get_date_or_file, parse_default_options)
(decode_options, main):
* src/unlink.c (flush_deferred_unlinks):
* src/update.c (append_file):
* src/xattrs.c (xattrs__acls_set, xattrs_xattrs_set):
Prefer < 0 when looking at syscalls; prefer != 0 to nothing
when testing an integer in a boolean context.
This is for style, not substance; for example, it’s easier
to read ‘if (wordsplit (...) != WRDSE_OK) ...’ than
‘if (wordsplit (...)) ...’ if you don’t already know that
wordsplit returns an enum rather than bool.
* src/names.c (add_file_id, read_next_name, regex_usage_warning):
* src/transform.c (parse_xform_flags):
Return bool not int, possibly inverting sense so that true means OK.
All callers changed.
* src/tar.c (main): Report errno info if stdopen fails.

8 months agodumpdir_cmp signature
Paul Eggert [Fri, 1 Nov 2024 18:16:19 +0000 (11:16 -0700)] 
dumpdir_cmp signature

* src/compare.c (dumpdir_cmp): Return char, not int.

8 months agoCheck for checkpoint string overflow
Paul Eggert [Fri, 1 Nov 2024 18:04:39 +0000 (11:04 -0700)] 
Check for checkpoint string overflow

It’s very unlikely, but would lead to undefined behavior.
* src/checkpoint.c (format_checkpoint_string): Accept and return
intmax_t, not idx_t.  All callers changed.  Check for integer
overflow by using add_printf.  If overflow occurs, don’t bother
with extending width.

8 months agoPrefer int to idx_t for some small sizes
Paul Eggert [Fri, 1 Nov 2024 17:37:39 +0000 (10:37 -0700)] 
Prefer int to idx_t for some small sizes

* src/create.c (max_octal_val, to_octal, tar_copy_str)
(tar_name_copy_str, to_base256, to_chars_subst, to_chars)
(gid_to_chars, major_to_chars, minor_to_chars, mode_to_chars)
(off_to_chars, time_to_chars, uid_to_chars, string_to_chars)
(split_long_name, write_ustar_long_name, simple_finish_header):
* src/list.c (from_header, gid_from_header, major_from_header)
(minor_from_header, mode_from_header, off_from_header)
(time_from_header, uid_from_header):
Prefer int to idx_t where either will do because the buffer sizes
are known to be small, as this can be a performance win on 32-bit
platforms.  Also, in a few cases the values were negative, whereas
idx_t is supposed to be nonnegative.

8 months agoPacify gcc -Wmissing-variable-declarations
Paul Eggert [Fri, 1 Nov 2024 16:47:18 +0000 (09:47 -0700)] 
Pacify gcc -Wmissing-variable-declarations

* src/buffer.c (start_offset): Now static.

8 months agoPrefer other types to int in compare.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer other types to int in compare.c

* src/compare.c (get_stat_data, verify_volume):
Use bool for booleans.
(verify_volume): Count headers with intmax_t, not int.

8 months agoPrefer other types to int in checkpoint.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer other types to int in checkpoint.c

* src/checkpoint.c (checkpoint_state): Now enum, not int.
(tty_cleanup): Now bool, not int.

8 months agoPrefer other types to int in buffer.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer other types to int in buffer.c

This increases the volume number maximum from 2**31 - 1 to 2**63 - 1.
* src/buffer.c (record_index, inhibit_map, new_volume):
Prefer bool to int for booleans.
* src/buffer.c (volno, global_volno):
* src/system.c (sys_exec_info_script):
Prefer intmax_t to int.
* src/buffer.c (increase_volume_number): Omit by-hand check for
overflow that relied on undefined behavior.
(new_volume): Check for that overflow here instead, without
relying on undefined behavior.
(print_stats): Avoid undefined behavior if printf sums overflow,
and reliably treat printf error like overflow.
* src/common.h (add_printf): New inline function.

8 months agoPrefer other types to int in tar.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer other types to int in tar.c

Use types that are more specific than ‘int’, if that is easy.
* src/tar.c (after_date_option, xattrs_option, check_links_option)
(confirm, confirm_file_EOF, set_xattr_option, optloc_eq)
(get_date_or_file):
Prefer bool to int.
(tar_list_quoting_styles, tar_set_quoting_style, parse_opt):
Prefer idx_t to int.
(optloc_lookup, option_set_in_cl): Prefer enum option_class to int.
(decode_signal): Avoid some pointer reallocation.
(sort_mode_flag, hole_detection_types, set_old_files_option)
(is_subcommand_class): Prefer enum to int.
(parse_opt) [DEVICE_PREFIX]: Remove unused var.
Simplify creation of device name.
(find_argp_option_key, find_argp_option): Prefer char to int.
(enum subcommand_class): Now named.
(subcommand_class): Now char, not int.
(decode_options): Check for unlikely int overflow.

8 months agoRemove major, minor signedness assumption
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Remove major, minor signedness assumption

* src/common.h (uintmax): Remove; no longer used.
* src/list.c (simple_print_header): Don’t assume major and minor
agree in signedness.

8 months agoFix checkpoint_flush_actions width typo
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Fix checkpoint_flush_actions width typo

* src/checkpoint.c (checkpoint_flush_actions): long → intmax_t.

8 months agoFewer uses of uintmax_t in xheader.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Fewer uses of uintmax_t in xheader.c

* src/tar.h (struct xheader):
* src/xheader.c (xheader_string_end):
Use idx_t, not uintmax_t, for string length.
* src/xheader.c (xheader_string_add):
Avoid duplicate calls to strlen.
(xheader_string_end): Remove by-hand check for size overflow;
it’s not possible, as this is measuring allocated storage.

8 months agoPrefer intmax_t for occurrence counts
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer intmax_t for occurrence counts

* src/common.h (struct name):
* src/tar.c (occurrence_option, parse_opt):
Use intmax_t, not uintmax_t, for occurrence counts.

8 months agoRemove unnecessary casts
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Remove unnecessary casts

Some of these date back to pre-C89.
* src/buffer.c (backspace_output):
* src/create.c (to_base256, gid_to_chars, major_to_chars)
(minor_to_chars, off_to_chars, time_to_chars, uid_to_chars):
* src/list.c (from_header, tartime):
* src/map.c (owner_map_translate, group_map_translate):
* src/system.c (sys_truncate):
* src/utf8.c (utf8_init):
* src/xattrs.c (acls_one_line):
* src/xheader.c (xheader_string_end):
Remove casts.
* src/create.c (uintmax_to_chars): Remove.  All uses removed.
(simple_finish_header): Use to_octal.

8 months agoCheck for setenv failures when running scripts
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Check for setenv failures when running scripts

* src/system.c (dec_to_env): Use umaxtostr for speed,
since convenience isn’t needed here.
(sys_exec_info_script, sys_exec_checkpoint_script):
Check for setenv failure.

8 months agoPrefer off_t to uintmax_t for continued_file_*
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer off_t to uintmax_t for continued_file_*

* src/buffer.c (continued_file_size, continued_file_offset):
Now off_t, not uintmax_t.  All uses changed.
* src/common.h (UINTMAX_FROM_HEADER):
* src/list.c (uintmax_from_header):
Remove; unused.
* src/list.c (simple_print_header):
* src/xheader.c (volume_size_decoder, volume_offset_decoder):
Treat offset as off_t, not uintmax_t.

8 months agoPrefer idx_t to size_t in common.h
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer idx_t to size_t in common.h

* src/common.h (struct name): Prefer idx_t to size_t.
(volume_label_count): Remove; unused.

8 months agoPrefer idx_t to size_t in tar.h
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer idx_t to size_t in tar.h

* src/tar.h (struct xheader, struct tar_stat_info):
Prefer idx_t to size_t.  All uses changed.

8 months agoPrefer idx_t to size_t in xheader.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer idx_t to size_t in xheader.c

* src/xheader.c (x_obstack_grow, x_obstack_blank)
(xheader_format_name, xheader_ghdr_name, xheader_write)
(struct xhdr_tab, locate_handler, decode_record, decx, decg)
(xheader_read, xattr_encode_keyword, xheader_print_n)
(xheader_string_end, dummy_decoder, atime_decoder, gid_decoder)
(gname_decoder, linkpath_decoder, ctime_decoder, mtime_decoder)
(path_decoder, sparse_path_decoder, size_decoder, uid_decoder)
(uname_decoder, sparse_size_decoder, sparse_numblocks_decoder)
(sparse_offset_coder, sparse_offset_decoder)
(sparse_numbytes_coder, sparse_numbytes_decoder)
(sparse_map_decoder, dumpdir_decoder, volume_label_decoder)
(volume_size_decoder, volume_offset_decoder)
(volume_filename_decoder, xattr_selinux_decoder)
(xattr_acls_a_decoder, xattr_acls_d_decoder, xattr_coder)
(xattr_decoder, sparse_major_decoder, sparse_minor_decoder):
Prefer idx_t to size_t.

8 months agoPrefer intmax_t to size_t in xheader.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer intmax_t to size_t in xheader.c

* src/common.h (INTMAX_STRSIZE_BOUND): New constant.
(SYSINT_BUFSIZE): Use it.
* src/xheader.c (global_header_count, xheader_format_name):
Prefer intmax_t to size_t, as the values are not sizes.

8 months agoOmit unnecessary initialization in dunlink_alloc
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Omit unnecessary initialization in dunlink_alloc

* src/unlink.c (dunlink_alloc): Remove unnecessary assignment
to p->next.

8 months agoRemove unused static vars in unlink.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Remove unused static vars in unlink.c

* src/unlink.c (unlink_count, deferred_unlink_delay):
Remove.  All uses removed.

8 months agoPrefer idx_t to size_t in transform.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer idx_t to size_t in transform.c

* src/transform.c (struct replace_segm, struct transform)
(add_literal_segment, add_backref_segment, run_case_conv)
(_single_transform_name_to_obstack): Prefer idx_t to size_t.

8 months agoPrefer idx_t to size_t in xattrs.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer idx_t to size_t in xattrs.c

* src/xattrs.c (xattr_map_free, xattr_map_add)
(xheader_xattr_add, xattr_map_copy, struct xattrs_mask_map)
(fixup_extra_acl_fields, xattrs_acls_cleanup, acls_get_text)
(xattrs__acls_get_a, xattrs__acls_get_d, acls_one_line)
(mask_map_realloc, xattrs_xattrs_get, xattrs__fd_set)
(xattrs_matches_mask, xattrs_xattrs_set, xattrs_print_char)
(xattrs_print): Prefer idx_t to size_t.

8 months agoPrefer idx_t to size_t in tar.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer idx_t to size_t in tar.c

* src/tar.c (strip_name_components, archive_names)
(allocated_archive_names, tar_list_quoting_styles)
(expand_pax_option, parse_opt):
Prefer idx_t to size_t.
(decode_options): Use a static word rather than going
to to the bother of dynamically allocating an array.
(main): Do not preallocate array.  Do not call ‘free’
on a pointer that now might be to static storage.

8 months agoPrefer idx_t to size_t in system.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Prefer idx_t to size_t in system.c

* src/buffer.c (_flush_write): Return idx_t, not ssize_t,
to accommodate system.c changes.  All uses changed.
(_gnu_flush_write): Output correct errno value after write error.
Simplify multi-volume mode.
* src/system.c (sys_write_archive_buffer)
(sys_child_open_for_compress, sys_exec_setmtime_script):
Prefer idx_t to size_t.

8 months agoStreamline compression suffix detection
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Streamline compression suffix detection

* src/suffix.c (struct compression_suffix):
Use arrays rather than pointers that need relocation.
All uses changed.
(compression_suffixes): Now const.
Omit trailing null entry; all uses changed.
(find_compression_suffix): Simplify length calculations.
No longer any need to call strlen.

8 months agoFewer uses of size_t in suffix.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Fewer uses of size_t in suffix.c

* src/suffix.c (struct compression_suffix)
(find_compression_suffix, set_compression_program_by_suffix)
(strip_compression_suffix): Prefer idx_t to size_t.

8 months agoFewer uses of size_t in sparse.c
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Fewer uses of size_t in sparse.c

* src/sparse.c (struct tar_sparse_optab, dump_zeros)
(tar_sparse_dump_region, tar_sparse_extract_region)
(zero_block_p, sparse_add_map, sparse_dump_region)
(sparse_extract_region, sparse_dump_file, sparse_extract_file)
(check_data_region, sparse_diff_file, oldgnu_get_sparse_info)
(oldgnu_store_sparse_info, oldgnu_dump_header)
(star_get_sparse_info, pax_dump_header_0):
Prefer idx_t to size_t.

8 months agoAdjust better to Gnulib signed-int read changes
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Adjust better to Gnulib signed-int read changes

The 2024-08-09 Gnulib changes that caused some modules prefer
signed types to size_t means that Tar should follow suit.
* src/buffer.c (short_read):
* src/system.c (sys_child_open_for_compress)
(sys_child_open_for_uncompress):
rmtread and safe_read return ptrdiff_t not idx_t;
don’t rely on implementation defined conversion.
* src/misc.c (blocking_read): Never return a negative number.
Return idx_t, not ptrdiff_t, with the same convention for EOF
and error as the new full_read.  All callers changed.
* src/sparse.c (sparse_dump_region, check_sparse_region)
(check_data_region):
* src/update.c (append_file):
full_read no longer returns SAFE_READ_ERROR for I/O error; instead it
returns the number of bytes successfully read, and sets errno.
Adjust to this.
* src/system.c (sys_child_open_for_uncompress):
Rewrite to avoid need for goto and label.

8 months agoSimplify name_buffer initialization
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Simplify name_buffer initialization

* src/names.c (name_init): Remove no-longer-needed initialization
of name_buffer, name_buffer_length.  It was confusing anyway,
since it caused name_buffer_length to not equal the length of
name_buffer.

8 months agoSimplify add_hierarchy_to_namelist allocation
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Simplify add_hierarchy_to_namelist allocation

* src/names.c (add_hierarchy_to_namelist):
Use xpalloc rather than a complicated homebrew heuristic.

8 months agoRemove xattrs_clear_setup
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Remove xattrs_clear_setup

It’s never actually called.
* src/xattrs.c (clear_mask_map, xattrs_clear_setup):
Remove.  All uses removed.

8 months agoRemove name_term
Paul Eggert [Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)] 
Remove name_term

It’s never actually called.
* src/names.c (name_term): Remove.  All uses removed.

8 months agoDiagnose sys_exec_info_script failures
Paul Eggert [Fri, 1 Nov 2024 16:39:33 +0000 (09:39 -0700)] 
Diagnose sys_exec_info_script failures

* src/system.c (sys_exec_info_script): Diagnose failures in
getline, fclose.  Don’t worry about freeing memory
as caller will immediately exit anyway.

8 months agoPacify GCC in info_attach_exclist
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Pacify GCC in info_attach_exclist

* src/exclist.c (info_attach_exclist): Remove unnecessary test
for whether dir and ex are null.  GCC complains about the first
one in some cases.  Use C99-style decls.

8 months agoFewer uses of size_t in names.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in names.c

* src/names.c (name_buffer_length, read_name_from_file)
(copy_name, all_names_found, add_hierarchy_to_namelist)
(rebase_child_list, make_file_name, stripped_prefix_len):
Prefer idx_t to size_t.

8 months agoFewer uses of size_t in misc.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in misc.c

* src/misc.c (assign_string_n, quote_copy_string)
(normalize_filename, replace_prefix, remove_any_file)
(blocking_read, wd_alloc, wdcache_count, chdir_arg, chdir_do)
(read_diag_details, struct namebuf, namebuf_name):
Prefer idx_t to size_t.

8 months agoFewer uses of size_t in list.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in list.c

* src/list.c (recent_long_name_blocks, recent_long_link_blocks)
(read_header, from_header, gid_from_header, major_from_header)
(minor_from_header, mode_from_header, off_from_header)
(time_from_header, uid_from_header, uintmax_from_header)
(tartime): Prefer idx_t to size_t.

8 months agoFewer uses of size_t in incremen.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in incremen.c

* src/incremen.c (struct dumpdir, dumpdir_create0, struct dumpdir_iter)
(dumpdir_next, dumpdir_size, make_directory)
(dirlist_replace_prefix, rebase_directory, makedumpdir)
(maketagdumpdir, append_incremental_renames, read_obstack)
(read_incr_db_2, get_gnu_dumpdir, try_purge_directory)
(list_dumpdir): Prefer idx_t to size_t.

8 months agoFewer uses of size_t in extract.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in extract.c

* src/extract.c (struct delayed_set_stat, struct delayed_link)
(delay_set_stat, apply_nonancestor_delayed_set_stat)
(extract_file): Prefer idx_t to size_t.
(struct delayed_set_stat): Remove unused member xattr_map_size.

8 months agoFewer uses of size_t in exclist.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in exclist.c

* src/exclist.c (hg_addfn): Prefer idx_t to size_t.

8 months agoFewer uses of size_t in delete.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in delete.c

* src/delete.c (write_recent_blocks, write_recent_bytes):
Prefer idx_t to size_t.

8 months agoFewer uses of size_t in create.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in create.c

* src/create.c (struct exclusion_tag, to_octal, tar_copy_str)
(tar_name_copy_str, to_base256, to_chars_subst, to_chars)
(gid_to_chars, major_to_chars, minor_to_chars, mode_to_chars)
(off_to_chars, time_to_chars, uid_to_chars, uintmax_to_chars)
(string_to_chars, start_private_header, write_gnu_long_link)
(split_long_name, write_ustar_long_name, simple_finish_header)
(dump_dir0, ensure_slash, create_archive):
Prefer idx_t to size_t.

8 months agoFewer uses of size_t in compare.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in compare.c

* src/compare.c (read_and_process): Prefer idx_t to size_t.

8 months agoSimplify checkpoint_action allocation
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Simplify checkpoint_action allocation

* src/checkpoint.c: Include <flexmember.h>.
(struct checkpoint_action): New member commandbuf.
(checkpoint_action_tail): Now pointer to pointer,
to simplify updating.  All uses changed.
(alloc_action): New arg quoted_string, to lessen number of
separate allocations.  All uses changed.

8 months agocheckpoint_total_format is now const
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
checkpoint_total_format is now const

* src/checkpoint.c (checkpoint_total_format):
Now const, and local to format_checkpoint_string.

8 months agoFewer uses of size_t in checkpoint.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in checkpoint.c

* src/checkpoint.c (copy_string_unquote, getarg)
(format_checkpoint_string): Prefer idx_t to size_t.
(copy_string_unquote): Simplify by using ximemdup0.
(getarg): Avoid quadratic reallocation behavior by
using xpalloc.

8 months agoFewer uses of size_t in buffer.c
Paul Eggert [Fri, 1 Nov 2024 02:53:25 +0000 (19:53 -0700)] 
Fewer uses of size_t in buffer.c

* src/buffer.c (flush_write_ptr, flush_bufmap, bufmap_locate):
(struct zip_magic, available_space_after, _flush_write)
(short_read, flush_archive, try_new_volume)
(gnu_add_multi_volume_header, simple_flush_read)
(simple_flush_write, _gnu_flush_read, _gnu_flush_write)
(gnu_flush_write): Prefer idx_t to size_t when either will do, as
signed types are typically safer.  For a tiny value in memory,
just use ‘char’.

8 months agoDon't assume archive read from stdin starts at offset 0
Sergey Poznyakoff [Thu, 31 Oct 2024 17:09:28 +0000 (19:09 +0200)] 
Don't assume archive read from stdin starts at offset 0

* src/buffer.c (start_offset): New variable.
(get_archive_status): If reading from seekable stdin, store the
position in the stream corresponding to record_start in start_offset.
(seek_archive): Compute current offset relative to start_offset.

9 months agoAdd missing safety check
Sergey Poznyakoff [Fri, 25 Oct 2024 10:40:32 +0000 (13:40 +0300)] 
Add missing safety check

* src/system.c (sys_exec_info_script): Check if fdopen succeded.
Fix by Matteo Croce.

9 months agoRemove useless check
Sergey Poznyakoff [Fri, 25 Oct 2024 07:24:32 +0000 (10:24 +0300)] 
Remove useless check

* src/exclist.c (info_attach_exclist): Don't check whether dir
is NULL. It can't be.

9 months agoBugfix
Sergey Poznyakoff [Fri, 25 Oct 2024 06:50:22 +0000 (09:50 +0300)] 
Bugfix

This fixes an extra argument left over in a function call by commit
0dfcfa4aa4.  Reported by Matteo Croce.

* src/buffer.c (_open_archive): Fix extra argument to paxfatal.

11 months agoFewer macros in xheader.c
Paul Eggert [Mon, 19 Aug 2024 16:56:25 +0000 (09:56 -0700)] 
Fewer macros in xheader.c

* src/xheader.c (HEADER_TEMPLATE):
Remove.  All uses replaced with definiens.
(XHDR_PROTECTED, XHDR_GLOBAL): Now constants, not macros.

11 months agoFewer macros in xattrs.c
Paul Eggert [Mon, 19 Aug 2024 16:55:32 +0000 (09:55 -0700)] 
Fewer macros in xattrs.c

* src/xattrs.c (XATTRS_PREFIX, XATTRS_PREFIX_LEN, USER_DOT_PFX):
Now constants, not macros.

11 months agoFewer macros in unlink.c
Paul Eggert [Mon, 19 Aug 2024 16:54:15 +0000 (09:54 -0700)] 
Fewer macros in unlink.c

* src/unlink.c (IS_CWD): Now a (lower-cased) function.

11 months agoFewer macros in transform.c
Paul Eggert [Mon, 19 Aug 2024 16:53:35 +0000 (09:53 -0700)] 
Fewer macros in transform.c

* src/transform.c (CASE_CTL_RESET): Remove, replacing with one
instance of code (with a goto, alas).  Still a bit clearer, I think.

11 months agoFewer macros in tar.c
Paul Eggert [Mon, 19 Aug 2024 16:52:39 +0000 (09:52 -0700)] 
Fewer macros in tar.c

* src/tar.c (FORMAT_MASK, TAR_SIZE_SUFFIXES, SUBCL_READ)
(SUBCL_WRITE, SUBCL_UPDATE, SUBCL_TEST, SUBCL_OCCUR)
(IS_SUBCOMMAND_CLASS, NS_PRECISION_FORMAT_MASK):
Now constants or (lower-cased) functions, not macros.
(subcommand_class):
Replace hopeful comments with code implementing them.

11 months agoFewer macros in tar.h
Paul Eggert [Mon, 19 Aug 2024 16:50:02 +0000 (09:50 -0700)] 
Fewer macros in tar.h

* src/tar.h (REGTYPE, AREGTYPE, SYMTYPE, BLKTYPE, FIFOTYPE)
(XHDTYPE, XGLTYPE, TSUID, TSGID, TSVTX, TUREAD, TUWRITE, TUEXEC)
(TGREAD, TGWRITE, TGEXEC, TOREAD, TOWRITE, TOEXEC)
(SPARSES_IN_EXTRA_HEADER, SPARSES_IN_OLDGNU_HEADER)
(SPARSES_IN_SPARSE_HEADER, GNUTYPE_DUMPDIR, GNUTYPE_LONGLINK)
(GNUTYPE_LONGNAME, GNUTYPE_MULTIVOL, GNUTYPE_SPARSE)
(GNUTYPE_VOLHDR, SOLARIS_XHDTYPE, SPARSES_IN_STAR_HEADER)
(SPARSES_IN_STAR_EXT_HEADER, BLOCKSIZE):
Now constants, not macros.

11 months agoFewer macros in system.c
Paul Eggert [Mon, 19 Aug 2024 16:48:07 +0000 (09:48 -0700)] 
Fewer macros in system.c

* src/system.c (PREAD, PWRITE): Now constants, not macros.

11 months agoFewer macros in names.c
Paul Eggert [Mon, 19 Aug 2024 16:47:11 +0000 (09:47 -0700)] 
Fewer macros in names.c

* src/names.c (EXCLUDE_OPTIONS, INCLUDE_OPTIONS):
Now (lowercased) functions, not macros.
(SUCCESSOR): Remove, replacing uses with definiens.

11 months agoFewer macros in incremen.c
Paul Eggert [Mon, 19 Aug 2024 16:45:43 +0000 (09:45 -0700)] 
Fewer macros in incremen.c

* src/incremen.c (DIRF_INIT, DIRF_NFS, DIRF_FOUND, DIRF_NEW)
(DIRF_RENAMED, DIR_IS_INITED, DIR_IS_NFS, DIR_IS_FOUND)
(DIR_IS_RENAMED, DIR_SET_FLAG, DIR_CLEAR_FLAG, NFS_FILE_STAT)
(PD_FORCE_CHILDREN, PD_FORCE_INIT, PD_CHILDREN)
(TAR_INCREMENTAL_VERSION, TEMP_DIR_TEMPLATE):
Now constants or (lowercased) functions, not macros.
(ST_DEV_MSB) [!HAVE_ST_FSTYPE_STRING]: Remove.
Replace only use with something simpler.

11 months agoFewer macros in extract.c
Paul Eggert [Mon, 19 Aug 2024 16:42:59 +0000 (09:42 -0700)] 
Fewer macros in extract.c

* src/extract.c (ALL_MODE_BITS, RECOVER_NO, RECOVER_OK)
(RECOVER_SKIP): Now constants or inline functions, not macros.
(maybe_recoverable): Return enum recover, not int.

11 months agoFewer macros in create.c
Paul Eggert [Mon, 19 Aug 2024 16:41:37 +0000 (09:41 -0700)] 
Fewer macros in create.c

* src/create.c (CACHEDIR_SIGNATURE, CACHEDIR_SIGNATURE_SIZE)
(MAX_VAL_WITH_DIGITS, MAX_OCTAL_VAL): Now constants or
inline functions or removed, instead of macros.
(max_octal_val): Accept size rather than type.

11 months agoFewer macros in buffer.c
Paul Eggert [Mon, 19 Aug 2024 16:39:37 +0000 (09:39 -0700)] 
Fewer macros in buffer.c

* src/buffer.c (READ_ERROR_MAX, NMAGIC, VOL_SUFFIX):
Now constants rather than macros.  Rename NMAGIC to n_zip_magic.

11 months agoFewer macros in common.h
Paul Eggert [Mon, 19 Aug 2024 16:12:52 +0000 (09:12 -0700)] 
Fewer macros in common.h

In common.h, replace macros with constants or functions when that
is easy.  This makes code a bit more reliable (functions evaluate
their args exactly once) and easier to debug (many debugging
environments cannot access macros).
* src/common.h (CHKBLANKS): Remove.  All uses removed.
(NAME_FIELD_SIZE, PREFIX_FIELD_SIZE, UNAME_FIELD_SIZE)
(GNAME_FIELD_SIZE, TAREXIT_SUCCESS, TAREXIT_DIFFERS)
(TAREXIT_FAILURE, LG_8, LG_256, DEFAULT_CHECKPOINT)
(MAX_OLD_FILES, TF_READ, TF_WRITE, TF_DELETED, XFORM_REGFILE)
(XFORM_LINK, XFORM_SYMLINK, XFORM_ALL, WARN_ALONE_ZERO_BLOCK)
(WARN_BAD_DUMPDIR, WARN_CACHEDIR, WARN_CONTIGUOUS_CAST)
(WARN_FILE_CHANGED, WARN_FILE_IGNORED, WARN_FILE_REMOVED)
(WARN_FILE_SHRANK, WARN_FILE_UNCHANGED, WARN_FILENAME_WITH_NULS)
(WARN_IGNORE_ARCHIVE, WARN_IGNORE_NEWER, WARN_NEW_DIRECTORY)
(WARN_RENAME_DIRECTORY, WARN_SYMLINK_CAST, WARN_TIMESTAMP)
(WARN_UNKNOWN_CAST, WARN_UNKNOWN_KEYWORD, WARN_XDEV)
(WARN_DECOMPRESS_PROGRAM, WARN_EXISTING_FILE, WARN_XATTR_WRITE)
(WARN_RECORD_SIZE, WARN_FAILED_READ, WARN_MISSING_ZERO_BLOCKS)
(WARN_VERBOSE_WARNINGS, WARN_ALL, EXCL_DEFAULT, EXCL_RECURSIVE)
(EXCL_NON_RECURSIVE): Now enum constants rather than macros.
(time_option_initialized, isfound, wasfound, warning_enabled):
Now functions rather than macros TIME_OPTION_INITIALIZED, ISFOUND,
WASFOUND, WARNING_ENABLED.  All uses changed.
(OLDER_STAT_TIME, OLDER_TAR_STAT_TIME, EXTRACT_OVER_PIPE)
(TAR_ARGS_INITIALIZER): Remove.  All uses replaced with their
definiens or equivalent.

11 months agoFix non-ASCII in sparse.c
Paul Eggert [Mon, 19 Aug 2024 05:40:43 +0000 (22:40 -0700)] 
Fix non-ASCII in sparse.c

11 months agoPrefer function to COPY_BUF macro
Paul Eggert [Sun, 18 Aug 2024 18:02:51 +0000 (11:02 -0700)] 
Prefer function to COPY_BUF macro

* src/sparse.c (struct ok_n_block_ptr): New type.
(decode_num): Revamp API so that it does the work of both
the old decode_num and the old COPY_BUF.  Always read to the
next newline even if there is a lot of junk in between.
(pax_decode_header): Use the new API.
(COPY_BUF): Remove.

11 months agoPrefer function to COPY_STRING macro
Paul Eggert [Sun, 18 Aug 2024 16:44:25 +0000 (09:44 -0700)] 
Prefer function to COPY_STRING macro

* src/sparse.c (struct block_ptr):
New type, to allow a functional style.
(dump_str_nl, floorlog10): New static functions.
(COPY_STRING): Remove.  All uses replaced by dump_str_nl.
(pax_dump_header_1): Use floorlog10 instead of creating a string.
Simplify size calculation.

11 months agoFix string size bound calculation
Paul Eggert [Sun, 18 Aug 2024 15:45:41 +0000 (08:45 -0700)] 
Fix string size bound calculation

* src/common.h (UINTMAX_STRSIZE_BOUND):
Fix typo that luckily didn’t break anything.

11 months agomaint: switch from ERROR to paxerror etc
Paul Eggert [Sun, 18 Aug 2024 01:16:16 +0000 (18:16 -0700)] 
maint: switch from ERROR to paxerror etc

Prefer functions like ‘paxerror’ to macros like ‘ERROR’.
The functions have cleaner semantics, and calls are
easier to read.

11 months agobuild: update gnulib and paxutils submodules to latest
Paul Eggert [Sun, 18 Aug 2024 00:56:29 +0000 (17:56 -0700)] 
build: update gnulib and paxutils submodules to latest

11 months agoAdjust to verror change for program name
Paul Eggert [Thu, 15 Aug 2024 17:24:15 +0000 (10:24 -0700)] 
Adjust to verror change for program name

* configure.ac (ENABLE_ERROR_PRINT_PROGNAME):
Adjust to match new Gnulib behavior.

11 months agobuild: update gnulib and paxutils submodules to latest
Paul Eggert [Thu, 15 Aug 2024 05:21:12 +0000 (22:21 -0700)] 
build: update gnulib and paxutils submodules to latest

11 months agoFix duplicate write_error_details decl
Paul Eggert [Thu, 15 Aug 2024 06:07:14 +0000 (23:07 -0700)] 
Fix duplicate write_error_details decl

* src/common.h (write_error_details): Remove decl
that belongs to paxutils.

11 months agoFix minor diagnostic discrepancies in incrementals
Paul Eggert [Thu, 15 Aug 2024 06:05:33 +0000 (23:05 -0700)] 
Fix minor diagnostic discrepancies in incrementals

* src/incremen.c (read_directory_file, get_gnu_dumpdir):
Be more consistent about fatal errors.

11 months agoAdd verror module
Paul Eggert [Thu, 15 Aug 2024 06:01:57 +0000 (23:01 -0700)] 
Add verror module

* gnulib.modules: Add verror; paxlib will need this.

11 months agoUse idx_t for write_fatal_details size
Paul Eggert [Thu, 15 Aug 2024 05:19:30 +0000 (22:19 -0700)] 
Use idx_t for write_fatal_details size

* src/buffer.c (write_fatal_details): Prefer idx_t to size_t
for object size.

11 months agoUse intmax_t for read_incr_db_01 line numbers
Paul Eggert [Tue, 13 Aug 2024 15:39:25 +0000 (08:39 -0700)] 
Use intmax_t for read_incr_db_01 line numbers

* src/incremen.c (read_incr_db_01): Don’t assume line numbers
are less than LONG_MAX.

11 months agoAvoid need for base64_init and extra table
Paul Eggert [Tue, 13 Aug 2024 15:35:24 +0000 (08:35 -0700)] 
Avoid need for base64_init and extra table

Simplify the code by assuming C99 initializers.
* src/list.c (base_64_digits): Remove.
(base64_map): Now a constant.  Now has its (old value + 1) % 65,
as that’s the only easy portable way to do it with a static
initializer (even on platforms where CHAR_BIT != 8); all uses changed.
(base64_init): Remove; only use removed.
(from_header): Adjust to new values in base64_map.

* src/list.c (base_64_digits): Remove; no longer needed.
(base64_map): Now const, initialized statically, and with
invalid entries being 0 not 64, and with valid entries
being 1 greater than before.

11 months agoRemove cast from from_header
Paul Eggert [Tue, 13 Aug 2024 06:26:41 +0000 (23:26 -0700)] 
Remove cast from from_header

* src/list.c (from_header): Reword to avoid a cast
to unsigned char.

11 months agoPrefer signed to unsigned when decoding options
Paul Eggert [Tue, 13 Aug 2024 01:17:58 +0000 (18:17 -0700)] 
Prefer signed to unsigned when decoding options

* src/tar.c (assert_format, decode_options):
Prefer signed to unsigned integers.
(optloc_save): Prefer enum to unsigned integer.
Simplify allocation.
(decode_options): No need to call ngettext for a value known
to be plenty large.

11 months agoDon’t assume pid fits in unsigned long
Paul Eggert [Tue, 13 Aug 2024 01:04:42 +0000 (18:04 -0700)] 
Don’t assume pid fits in unsigned long

* src/system.c (sys_wait_command): Convert pid_t to intmax_t,
not to unsigned long.

11 months agoAvoid casts in tar_checksum
Paul Eggert [Tue, 13 Aug 2024 00:52:09 +0000 (17:52 -0700)] 
Avoid casts in tar_checksum

* src/list.c (tar_checksum, from_header):
Recode to avoid casts.

11 months agoSupport >UINT_MAX lines in map files
Paul Eggert [Tue, 13 Aug 2024 00:47:26 +0000 (17:47 -0700)] 
Support >UINT_MAX lines in map files

* src/map.c (parse_id, map_read): Prefer intmax_t to unsigned
for line numbers.