Commit Graph

3281 Commits

Author SHA1 Message Date
Paul Eggert
989842ff0d 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
6f5718a35f 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
d68c37b640 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
c0ef66da92 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
c2ce0b7e13 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
7b278044a7 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
025f19e6bd 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
c61a2bee73 Omit unnecessary initialization in dunlink_alloc
* src/unlink.c (dunlink_alloc): Remove unnecessary assignment
to p->next.
2024-11-01 23:47:23 -07:00
Paul Eggert
08a9174444 Remove unused static vars in unlink.c
* src/unlink.c (unlink_count, deferred_unlink_delay):
Remove.  All uses removed.
2024-11-01 23:47:23 -07:00
Paul Eggert
e0f9b0fdea 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
17ad155fb2 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
303ac16ec0 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
6df7a72434 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
23582f3445 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
317e4d6a3c 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
5f4a4164b7 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
7c0feaefd0 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
e513950080 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
2ce5791124 Simplify add_hierarchy_to_namelist allocation
* src/names.c (add_hierarchy_to_namelist):
Use xpalloc rather than a complicated homebrew heuristic.
2024-11-01 23:47:23 -07:00
Paul Eggert
d127dac10e Remove xattrs_clear_setup
It’s never actually called.
* src/xattrs.c (clear_mask_map, xattrs_clear_setup):
Remove.  All uses removed.
2024-11-01 23:47:23 -07:00
Paul Eggert
61a978f6d4 Remove name_term
It’s never actually called.
* src/names.c (name_term): Remove.  All uses removed.
2024-11-01 23:47:23 -07:00
Paul Eggert
fae968bd2d 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
9afbe6961c 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
5704e5795a 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
b73127edc4 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
dd71d3796d 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
f73c927a71 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
04b92eca49 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
5a00343006 Fewer uses of size_t in exclist.c
* src/exclist.c (hg_addfn): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
739483114d Fewer uses of size_t in delete.c
* src/delete.c (write_recent_blocks, write_recent_bytes):
Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
849f244a0b 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
15dc3210cc Fewer uses of size_t in compare.c
* src/compare.c (read_and_process): Prefer idx_t to size_t.
2024-11-01 23:47:23 -07:00
Paul Eggert
7abf1420c3 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
0b60228081 checkpoint_total_format is now const
* src/checkpoint.c (checkpoint_total_format):
Now const, and local to format_checkpoint_string.
2024-11-01 23:47:23 -07:00
Paul Eggert
f9ed22de9b 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.
2024-11-01 23:47:23 -07:00
Paul Eggert
78dd7bf0bc 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’.
2024-11-01 23:47:23 -07:00
Sergey Poznyakoff
647cafff96 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.
2024-10-31 19:17:05 +02:00
Sergey Poznyakoff
bd06b114d9 Add missing safety check
* src/system.c (sys_exec_info_script): Check if fdopen succeded.
Fix by Matteo Croce.
2024-10-25 13:40:32 +03:00
Sergey Poznyakoff
8767b1c84a Remove useless check
* src/exclist.c (info_attach_exclist): Don't check whether dir
is NULL. It can't be.
2024-10-25 10:24:32 +03:00
Sergey Poznyakoff
e59d09db7d 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.
2024-10-25 09:50:22 +03:00
Paul Eggert
dd1bae32ce Fewer macros in xheader.c
* src/xheader.c (HEADER_TEMPLATE):
Remove.  All uses replaced with definiens.
(XHDR_PROTECTED, XHDR_GLOBAL): Now constants, not macros.
2024-08-19 09:57:13 -07:00
Paul Eggert
8b3073e1d2 Fewer macros in xattrs.c
* src/xattrs.c (XATTRS_PREFIX, XATTRS_PREFIX_LEN, USER_DOT_PFX):
Now constants, not macros.
2024-08-19 09:57:13 -07:00
Paul Eggert
7c4f884747 Fewer macros in unlink.c
* src/unlink.c (IS_CWD): Now a (lower-cased) function.
2024-08-19 09:57:13 -07:00
Paul Eggert
82ef07c9bd 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.
2024-08-19 09:57:13 -07:00
Paul Eggert
350cc4077e 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.
2024-08-19 09:57:13 -07:00
Paul Eggert
7f557428a4 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.
2024-08-19 09:57:13 -07:00
Paul Eggert
dd0f95965d Fewer macros in system.c
* src/system.c (PREAD, PWRITE): Now constants, not macros.
2024-08-19 09:57:13 -07:00
Paul Eggert
cdcd1580c8 Fewer macros in names.c
* src/names.c (EXCLUDE_OPTIONS, INCLUDE_OPTIONS):
Now (lowercased) functions, not macros.
(SUCCESSOR): Remove, replacing uses with definiens.
2024-08-19 09:57:13 -07:00
Paul Eggert
dfb1da7253 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.
2024-08-19 09:57:13 -07:00
Paul Eggert
79cb9aaab6 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.
2024-08-19 09:57:13 -07:00