summaryrefslogtreecommitdiff
path: root/libarchive/archive_util.c
Commit message (Collapse)AuthorAgeFilesLines
* use O_TMPFILE if it works/is supported in __archive_mktempCristian Rodríguez2020-07-271-0/+5
| | | | | | This makes the function safer on linux since the file is warrantied to never be visible on the filesystem, cannot be linked anywhere unless O_EXCL is not specified and it is lost forever on any kind of program termination.
* Safe writes: improve error handlingMartin Matuska2020-03-021-0/+1
| | | | | | | Print message if creation of temporary file fails. When rename of temporary file fails, exit with ARCHIVE_FAILED. Reword message on failed rename. Revert d84ec3f and 85b9f66, call archive_set_error()w before unlinking.
* Implement ARCHIVE_EXTRACT_SAFE_WRITES on WindowsMartin Matuska2020-01-201-58/+87
| | | | | | | As Windows does not support atomic rename/_wrename we have to unlink the file right before calling _wrename leaving a short unsafe window where a different file with the same name can be created and make the rename operation fail.
* Introduce archive_write_disk(3) flag ARCHIVE_EXTRACT_SAFE_WRITESzoulasc2020-01-201-25/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | This flag changes the way that regular files are extracted: Instead of removing existing files first and re-creating them in order to replace their contents, a temporary file is created and when writing to the temporary file is completed, the file is rename(2)d to the final destination name. This has the effect of presenting a consistent view of the file to the system (either the file with the new contents or the file with the old contents). Removing and overwriting the file has the undesired side effect that the the system can either not see the file at all (from the time it is being removed till the time it is being re-created), or worse it can see partial file contents. This is problematic when extracting system files (for example shared libraries). If the existing file that is going to be overwritten is a hard link, for now we unlink it before calling rename(2). This can be done correctly by creating a hardlink to a tmpnam(3) generated file and then use rename(2), but that is fairly intrusive and requires refactoring. Fixes #1289
* Don't #undef stat and #define stat(). stat is one of those unfortunateJoel Uckelman2018-10-181-1/+1
| | | | | | | | | identifiers for which there is both a struct and a function. MinGW uses a #define for setting struct stat to be the right struct, so doing #undef stat to clear the way for a #define for stat() the function inadvertantly clobbers the selected stat struct. To avoid this, we define la_stat() to _la_stat on Windows and stat() elsewhere, and then use la_stat() instead of stat().
* Match archive.h for la_int64_t vs int64_tJoerg Sonnenberger2017-10-071-2/+2
|
* constify variables moreMike Frysinger2017-03-231-3/+3
| | | | | | | A bunch of constant variables/tables are missing const markings. Adding them allows moving more data to the read only sections, and ends up shrinking writable data a bit by 1k on x86_64/Linux. Not much, but still nice.
* Break out the library version functions into a separate source file.Tim Kientzle2017-03-111-82/+0
| | | | | | | | | | | | | | | | | This breaks a static dependency on libbz2. Before this, any use of libarchive that ended up linking archive_util.c would require libbz2. (And since archive_util.c contains a bunch of very core functions, this is pretty much everybody.) Now you only require libbz2 if you request library version information or actually use some other feature that involves bzip2 support. Note that most of the libraries provide version information via compile-time macros -- libbz2 only provides such information via a function call, which is why this issue only arises with libbz2. In particular, the libbz2 version reports the version that we are currently linked against; the other library versions report the version we were compiled with (which may not be the same as what we are currently using).
* Fix a couple of typographical errors.Peter Pentchev2016-07-071-1/+1
|
* Fix stringification hereTim Kientzle2016-02-131-1/+3
|
* Issue 422: Add archive_xxx_version() calls so tests can more accurately ↵Tim Kientzle2016-03-121-15/+59
| | | | | | | query libarchive support Rework some of the Zip, Cab, and LZ4 tests to use these to determine what behavior they should expect.
* Issue 382: Move variables to top of function for non-C99 compilers.Tim Kientzle2014-11-151-2/+3
| | | | | This should address an issue compiling with older versions of Visual Studio.
* Use archive_random() function instead of rand() function.Michihiro NAKAJIMA2014-10-131-12/+6
|
* Issue 378: compute string pointers after concatenation, to protect against ↵Tim Kientzle2014-09-251-2/+3
| | | | reallocation moving the string
* Add support for lz4 write filter.Michihiro NAKAJIMA2014-08-141-2/+9
|
* Style fix. space -> tab.Michihiro NAKAJIMA2014-07-061-59/+61
|
* Plug memory leaks which Clang Static Analyser pointed out.Michihiro NAKAJIMA2014-07-061-2/+8
|
* Style: Use 'int' not 'char' for status return types.Tim Kientzle2013-12-191-1/+1
| | | | Fix a const mistake.
* Refactor archive_version_details to eliminate size and printf concernsTim Kientzle2013-12-191-16/+21
|
* Show third party library versions in version stringRoss Lagerwall2013-09-161-0/+36
| | | | | | | | | Add a utility function, archive_version_details, to return a string containing the libarchive version as well as the versions of third party libraries such as zlib, bz2lib and liblzma. Use this function for bsdtar --version and bsdcpio --version. http://code.google.com/p/libarchive/issues/detail?id=118
* Redo the strings sorting function, allocate/free memory as needed.Andres Mejia2013-02-091-14/+40
| | | | This is the normal implementation of quicksort.
* Add a convenience function to sort a list of strings.Andres Mejia2013-02-091-0/+42
| | | | | This is useful for sorting a list of filepaths to multivolume RARs for example.
* Fix build failure on Win64.Michihiro NAKAJIMA2012-11-071-2/+3
|
* Apply *_CLOEXEC flags to system calls which can be used withMichihiro NAKAJIMA2012-10-021-3/+37
| | | | | | | | to avoid file descriptor leaks to the child process. - Pass O_CLOEXEC to open(2) system call if it is defined. - Use fcntl(2) and F_DUPFD_CLOEXEC instead of dup(2) if F_DUPFD_CLOEXEC is defined. - Set FD_CLOEXEC with fcntl(2) if a file descriptor does not have.
* When ENOMEM happened in archive_string_append_from_wcs and ↵Michihiro NAKAJIMA2012-01-231-2/+3
| | | | | | | | | | archive_string_append_from_mbs, those function should report the error to the caller instead of invoking __archive_errx(). We should report that ENOMEM error as possible as we can and we still need to further improve reporting ENOEM. SVN-Revision: 4193
* Fix build failure on Cygwin.Michihiro NAKAJIMA2011-09-081-1/+1
| | | | SVN-Revision: 3693
* __archive_mktemp function should simply be in one file for maintenance, and soMichihiro NAKAJIMA2011-08-281-1/+154
| | | | | | I migrated that of Windows implementation into archive_util.c. SVN-Revision: 3661
* Improve character-set conversion functions.Michihiro NAKAJIMA2011-03-281-13/+1
| | | | | | | | | | | | | | - Change the interface in order to reduece the comparison of charset names. Previous version always did it when the functions were called; it was very inefficient. So I have made a conversion object, struct archive_string_conv, to resolve that issue. - Integrate *_from_charset and *_to_charset into *_in_locale because of above. - Integrate *_from_utf16be and *_to_utf16be into *in_locale. - On Windows, Make a codepage from a charset name to know whether current codepage and specified charset are the same or not. SVN-Revision: 3108
* Remove UTF-8 <===> WCS conversion code, which was highly based on the wrogMichihiro NAKAJIMA2011-03-251-4/+0
| | | | | | | | | assumption that WCS was UNICODE. What format WCS has is deeply dependent on platform, and WCS must be converted to/from locale dependent MBS on every platform through mbstowcs/wcstombs or related functions, which the platforms provide. We should, thus, respect the platform policy about WCS for potability. SVN-Revision: 3074
* From Roman Neuhauser: Rework textual options handling.Tim Kientzle2011-03-181-192/+0
| | | | | | | | | | | | | | * New functions archive_{read,write}_set_{format,filter}_option accept three strings: module name, option name, value. This is a better match for C clients of the library, who want to set one option at a time anyway for better error handling. * archive_{read,write}_set_options still accept a single string with possibly multiple options, but are now much simpler internally because they build on the above. * New tests for all of the above. * Update a lot of tests to give good coverage of the new functions. SVN-Revision: 3026
* Add charset conversion functions which convert a string between Michihiro NAKAJIMA2011-03-171-4/+10
| | | | | | current locale and specific locale with iconv. SVN-Revision: 3021
* Move a conversion of UTF-16BE, which is used for Joliet extensions, intoMichihiro NAKAJIMA2011-03-161-0/+4
| | | | | | archive_string.c, and Use iconv for it if available. SVN-Revision: 3019
* Fix some broken tests from the earlier string workTim Kientzle2011-03-071-1/+2
| | | | | | and refactor the charset conversion routines to be more consistent. SVN-Revision: 2993
* Switch archive_string character set conversion over to use iconv()Tim Kientzle2011-03-061-28/+10
| | | | | | | when it's available. See Issue 66 and Issue 132 for more discussion. SVN-Revision: 2992
* Change archive_set_error() to clear the error string beforeTim Kientzle2011-02-261-0/+1
| | | | | | putting the new error into it. SVN-Revision: 2989
* Return NULL if there is no error message.Tim Kientzle2010-10-311-1/+1
| | | | | | | | In particular, we should start filling in assertions in lots of tests to verify that textual error messages are getting generated on errors. SVN-Revision: 2777
* Make sure that fd has a valid value.Joerg Sonnenberger2010-04-261-1/+1
| | | | SVN-Revision: 2316
* Set archive_error_number to zero here. I'm a little uneasy aboutTim Kientzle2010-02-251-0/+1
| | | | | | | this, as there are apparently libarchive uers that abuse archive_errno() and this change is likely to mask bugs in such software. SVN-Revision: 1989
* Stackable write filter support. This ended up touching an awful lotTim Kientzle2010-02-201-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of files. But, the old API is supported almost entirely unchanged, which I wasn't certain would be possible. Big changes: * You can add more than one write filter by using archive_write_add_filter_{bzip2,compress,gzip,lzma,xz}. This will be more interesting when we have uuencode, RPM, encryption. * The old archive_write_set_compression_XXXX are shorthands for "remove all the current filters and add this one." They're deprecated and scheduled to be removed in libarchive 4.0. * The internal API and life cycle for write filters has been rationalized: create, set options, open, write, close, free. * New utility functions provide information about each filter when there's more than one: code, name, and number of bytes processed * Old archive_bytes_compressed(), etc, are implemented in terms of the more generic new functions. * The read side was generalized to also support the new utility functions. In particular, the write filters are much simpler since each one doesn't have to deal with blocking. In this version, there's still a "write_add_filter_none" that handles blocking, but I think I'll soon fold that down into the client wrapper and add_filter_none will become a no-op. I think this also gets us a big step closer to multi-volume support on the write side. SVN-Revision: 1920
* Make a Windows version of __archive_mktemp() in archive_windows.cMichihiro NAKAJIMA2010-02-121-32/+3
| | | | | | | and merge __la_mkstemp() and __archive_mktemp() because __la_mkstemp() was only used by __archive_mktemp(). SVN-Revision: 1896
* Introduce a function __archive_mktemp() to create a temporary file,Michihiro NAKAJIMA2010-02-111-1/+164
| | | | | | which will be used by ISO writer and xar writer. SVN-Revision: 1895
* Sync $FreeBSD$ version info from FreeBSD SVNTim Kientzle2009-12-301-1/+1
| | | | SVN-Revision: 1786
* Suppress some "unused return value" warnings from clang.Tim Kientzle2009-11-291-0/+2
| | | | SVN-Revision: 1680
* Revert r1617.Michihiro NAKAJIMA2009-11-161-3/+5
| | | | | | My previous change caused error on linux. SVN-Revision: 1665
* Value stored to 's' is never read.Michihiro NAKAJIMA2009-11-091-5/+3
| | | | | | Found by Clang Static Analyzer. SVN-Revision: 1617
* Add archive_file_count() utility, for better statistics reporting.Tim Kientzle2009-07-161-0/+5
| | | | SVN-Revision: 1222
* Building on Ubuntu 9 provoked some complaints about return valuesTim Kientzle2009-05-081-3/+6
| | | | | | | | | | not being used. Some of these are good catches, a few are annoying. Unfortunately, GCC on this system won't just allow you to cast the result explicitly to (void) to shut up the error, so I've had to introduce some gratuitous extra variables. <sigh> SVN-Revision: 1075
* Initialize variables; fix a compile warning.Tim Kientzle2009-02-041-0/+2
| | | | SVN-Revision: 543
* Don't use ctype.h in the library, it is locale dependent.Joerg Sonnenberger2009-02-011-7/+5
| | | | SVN-Revision: 530
* Fix some compiling error when use strict warning options.Michihiro NAKAJIMA2009-01-291-0/+2
| | | | SVN-Revision: 510