summaryrefslogtreecommitdiff
path: root/src/util.c
Commit message (Collapse)AuthorAgeFilesLines
* maint: update all copyright year number rangesJim Meyering2012-01-011-2/+2
| | | | Run "make update-copyright".
* build: update to latest gnulib and adaptJim Meyering2011-12-141-1/+1
| | | | | | | | | | | | | | | Mark functions as pure of const, per recommendations enabled by new gcc -W options. Apply _GL_ATTRIBUTE_PURE and _GL_ATTRIBUTE_CONST. * src/common.h: Apply new function attributes. * src/pch.c: Likewise. * src/pch.h: Likewise. * src/util.c: Likewise. * src/util.h: Likewise. * configure.ac: Use -Wno-format-nonliteral. * m4/.gitignore: Update. * gnulib: Update to latest. * cfg.mk: Exempt src/util.c from two tests, to avoid new "make syntax-check" failures.
* Timestamp not set when creating files with --set-time or --set-utcAndreas Gruenbacher2011-12-091-5/+6
| | | | | | | | | | | * src/util.h (enum file_attributes): Add FA_XATTRS flag for extended attributes. * src/patch.c (main): Use set_file_attributes() even when the infile doesn't exist: it may still set the file time (FA_TIMES). Omit all other FA_ flags if infile doesn't exist. Otherwise, add FA_XATTRS as well. * src/util.c (set_file_attributes): Only copy extended attributes if FA_XATTRS is set. Avoid using st where it may be undefined. * tests/preserve-mode-and-timestamp: Add file create test.
* emit one more diagnostic with the required "program_name: " prefixJim Meyering2011-05-251-2/+2
| | | | | | * src/util.c: Include "error.h". (ask): Use error, not perror. The latter would not have included the usual "program name: " prefix.
* remove side effect from assertJim Meyering2011-05-251-1/+2
| | | | * src/util.c (parse_c_string): Don't increment "s" in assert.
* explicitly ignore close return value to placate static analyzersJim Meyering2011-05-251-1/+2
| | | | | | | * src/util.c: Include "ignore-value.h". (ask): Use ignore_value to tell tools that yes, we really do mean to ignore any close failure on this error path. * bootstrap.conf (gnulib_modules): Add ignore-value.
* plug a leak in fetchnameJim Meyering2011-05-251-0/+1
| | | | * src/util.c (fetchname): Don't leak "timestr" when returning early.
* avoid a used-uninitialized error in fetchnameAndreas Gruenbacher2011-05-251-3/+2
| | | | | | | | * src/util.c (fetchname): Avoid a used-uninitialized error. Before, when "*t == '\n'", stamp.tv_nsec would have been used undefined. The fix is to set that member rather than stamp.tv_sec, which is already set to the desired value. This was reported by coverity.
* maint: remove now-unneeded macro definitionsJim Meyering2011-03-271-9/+0
| | | | | | | | | | * bootstrap.conf (gnulib_modules): Include gnulib's signal module, so that signal.h guarantees definition of certain macros. * src/util.c (SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK): Remove definition. Now, gnulib guarantees that these are defined. * src/common.h (SIZE_MAX): Likewise. * cfg.mk (local-checks-to-skip): Enable the sc_prohibit_always-defined_macros check, now that it passes.
* Ignore dangerous filenames instead of failing immediatelyAndreas Gruenbacher2011-02-161-11/+0
| | | | | | | | | | * src/pch.c (name_is_valid): New function. (intuit_diff_type, best_name): Use name_is_valid() here. (strip_leading_slashes): Remove name validation tests from here. * tests/bad-filenames: Add more tests for covering more of the file name guessing corner cases in intuit_diff_type(), update the existing tests. * NEWS: Update.
* Do not let a malicious patch create files above current directoryJim Meyering2011-02-031-1/+12
| | | | | | | | | | This addresses CVE-2010-4651, reported by Jakub Wilk. https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2010-4651 * src/util.c (strip_leading_slashes): Reject absolute file names and file names containing a component of "..". * tests/bad-filenames: New file. Test for this. * tests/Makefile.am (TESTS): Add it. Improvements by Andreas Gruenbacher.
* Create missing parent directories of temporary filesAndreas Gruenbacher2010-12-041-0/+10
| | | | | * src/util.c (make_tempfile): Create missing directories when necessary.
* Fix the USE_XATTR checksAndreas Gruenbacher2010-10-291-2/+2
| | | | | * src/util.c: USE_XATTR is defined to 0 or 1, so we need to use #if instead of #ifdef.
* Preserve extended attributes of patched files when possibleAndreas Gruenbacher2010-10-271-3/+67
| | | | | | | | | | | | | | * src/patch.c (main): Set all file attributes of the temporary output file before renaming it over the final output file (possibly replacing the input file). Pass the input file name to set_file_attributes(). * src/util.c (set_file_attributes): When enabled (USE_XATTR), also copy extended attributes including attributes which define permissions. (copy_attr_error, copy_attr_quote, copy_attr_free, copy_attr_check, copy_attr): Helper functions for copying extended attributes. * m4/xattr.m4 (gl_FUNC_XATTR): Import from coreutils. * src/Makefile.am (patch_LDADD): Add $(LIB_XATTR) here. * bootstrap.conf: Use the gnulib verror module.
* A minor set_file_attributes() cleanupAndreas Gruenbacher2010-10-271-3/+1
| | | | | | * src/util.c (set_file_attributes): Always expect the mode argument to be set when FA_MODE is specified. (create_backup_copy): Update accordingly.
* Only recognize quited filename in the "diff --git" formatAndreas Gruenbacher2010-10-051-3/+3
| | | | | | | | * src/util.c: Add a maybe_quoted parameter to fetchname. * src/pch.c: Only recognize quited filename in the "diff --git" format, at least for now. * tests/quoted-filenames: Update accordingly. * NEWS: Update accordingly.
* Add function make_tempfile()Andreas Gruenbacher2010-09-171-0/+56
| | | | | * bootstrap.conf: Use the gnulib tempname module. * src/util.c (make_tempfile): New function.
* build: silence some cygwin warningsEric Blake2010-05-041-2/+2
| | | | | | | | | * src/pch.c (includes): Add <io.h> for setmode. (intuit_diff_type): Avoid 8-bit problems. * src/util.c (parse_name): Likewise. * src/util.h (skip_spaces): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
* Fix backup file detection for deleted filesAndreas Gruenbacher2010-05-041-22/+62
| | | | | | | | | | * src/util.c (create_backup): Document patch's backup file logic. (create_backup, create_backup_copy): Add a flag to remember the backup file; use when a patch deletes a file. (move_file, copy_file): Better error messages. * tests/Makefile.am (TESTS): Remove remember-backup-files-2. * tests/remember-backup-files: Add tests from remember-backup-files-2. * tests/symlinks: Add a symlink backup file test.
* Minor cosmetic changesAndreas Gruenbacher2010-05-031-1/+1
|
* Do not try to set file permissions of symlinksAndreas Gruenbacher2010-05-031-1/+4
| | | | | | | * src/pch.c (fetchmode): Document that the "diff --git" format does not store file permissions of symlinks. * src/util.c (set_file_attributes): Since we don't have symlink file permissions, don't try to set them even on systems where we could.
* Add two test cases which are currently brokenAndreas Gruenbacher2010-05-031-0/+1
| | | | | | * Removing an empty file does not work as expected. * Deleted files are not being remembered correctly. * Symlinks are not being remembered, either.
* Do not modify the string arguments of makedirs and removedirsAndreas Gruenbacher2010-05-021-5/+9
| | | | | | | | | * src/patch.c (main): Convert outname into a char const *. * src/util.ch (create_backup, move_file, removedirs): Take char const * filenames. * src/util.c (makedirs): Take a char const * filename. (makedirs, removedirs): Take char const * filenames. Create and modify a copy of the filename.
* git diffs: Parse copy and rename headersAndreas Gruenbacher2010-05-021-9/+14
| | | | | | | | | | * src/pch.c (p_copy, p_rename): New variables. (pch_copy, pch_rename): New functions. (intuit_diff_type): Parse the "copy from", "copy to", "rename from", and "rename to" headers. * src/util.c (fetchname): Return the fetched name per reference (after freeing the previous name if any). Also free the previous timestamp string if any.
* git diffs: Support file mode changesAndreas Gruenbacher2010-05-021-4/+6
| | | | | | | | * src/patch.c (main): When a git diff includes a file mode change, change to the new mode. * src/util.c (set_file_attributes): Add a mode parameter. * tests/file-modes: New test case. * tests/Makefile.am (TESTS): Add test case.
* Add support for writing symlinksAndreas Gruenbacher2010-05-021-41/+93
| | | | | | | | | | | | * src/util.c (copy_file): Require the mode parameter to include the file type. Use that to decide whether to copy a regular file or a symlink. (create_backup): Refuse to back up files which are neither a regular file nor a symlink. (move_file): Add support for turning a temporary output file into a symlink. * src/patch.c (move_file, copy_file): Pass down the file type. * src/pch.h (prefix_components): Do not follow symlinks.
* Set file attributes only in a single placeAndreas Gruenbacher2010-04-291-15/+62
| | | | | | | | | | | | * src/util.h (enum file_attributes): New type. (set_file_attributes): New function. * src/util.c (set_file_attributes): Move the code for setting file attributes here from create_backup_copy() and make it usable from patch.c as well. Make it symlink safe. In addition, also preserve the file owner when permitted. (create_backup_copy): Use set_file_attributes(). * src/patch.c (main): Use set_file_attributes(). * bootstrap.conf: Use the gnulib lchmod module.
* Remove test which is always trueAndreas Gruenbacher2010-04-291-2/+1
| | | | * src/util.c (move_file): Remove test which is always true.
* Include backupfile.h in util.hAndreas Gruenbacher2010-04-271-1/+0
| | | | | * src/util.h: Include <backupfile.h> here and not in each C file individually; this avoids a warning in merge.c with some compilers.
* Refuse to patch symlinksAndreas Gruenbacher2010-04-271-1/+4
| | | | | | | | | | * src/inp.c (get_input_file), src/pch.c (there_is_another_patch, intuit_diff_type): Use lstat instead of stat. This causes patch to refuse patching symlinks (get_input_file() will refuse to read them). * src/util.c (create_backup): Refuse to create backups of symlinks. * tests/symlinks: New test case. * tests/Makefile.am (TESTS): Add test case. * bootstrap.conf: Use the gnulib lstat module.
* Do not declare variables as "volatile" unnecessarilyAndreas Gruenbacher2010-04-271-1/+1
| | | | | * src/common.h, src/patch.c, src/util.c, src/util.h: Do not declare variables as "volatile" unnecessarily.
* Do no declare local variables as "register" unnecessarilyAndreas Gruenbacher2010-04-271-5/+5
| | | | | | | * src/inp.c, src/patch.c, src/pch.c, src/util.c: Stop declaring local variables as "register" all over the place: a decent compiler will do a good enough job of place variables into registers where it makes sense.
* Parse filenames in "diff --git" linesAndreas Gruenbacher2010-04-231-0/+28
| | | | | | | | * src/pch.c (intuit_diff_type): Parse filenames in "diff --git" lines. * src/util.c (parse_name): New helper function for parsing unquoted or quoted filenames. * src/util.h (parse_name): Declare. (skip_spaces): New helper function for skipping spaces in a string.
* Add support for quoted filenamesAndreas Gruenbacher2010-04-231-13/+98
| | | | | | | * src/util.c (parse_c_string): New function. (fetchname): Add support for quoted filenames. * tests/quoted-filenames: New test case. * tests/Makefile.am (TESTS): Add test case.
* Untangle the name and timestamp parsingAndreas Gruenbacher2010-04-221-58/+52
| | | | * src/util.c (fetchname): Untangle the name and timestamp parsing.
* Strip leading slashes in a separate functionAndreas Gruenbacher2010-04-221-12/+32
| | | | | * src/util.c (strip_leading_slashes): Make this a separate function. (fetchname): Use strip_leading_slashes() here.
* Support for nanosecond timestampsAndreas Gruenbacher2010-04-221-4/+4
| | | | | | | | | | * src/patch.c (main): Support nanosecond timestamps. Replaqce utime() with utimens(). * src/util.c (create_backup_copy): Preserve nanosecond timestamps. Replace utime() with utimens(). * src/util.h: Remove the utime() related declarations, and include the utimens() and nanosecond related headers instead. * bootstrap.conf: Add the stat-time and utimens modules.
* Replace timestamp parsing code with gnulib getdateAndreas Gruenbacher2010-04-221-22/+18
| | | | | | | | | | | | | | | | | * src/Makefile.am (patch_SOURCES): Remove maketime.c, maketime.h, partime.c, and partime.h. (patch_LDFLAGS): Add LIB_CLOCK_GETTIME for clock_gettime(). * src/util.c: Replace maketime.h and partime.h with getdate.h. (fetchname): Replace str2time() with get_date(). Sanitize the test for epoch timestamps. * src/patch.c (main): When --set-utc is given, set the TZ environment variable to UTC so that get_date() will default to UTC timestamps. * tests/preserve-mode-and-timestamp: Switching to get_date() revealed that str2time() was ignoring timezones. In order to test --set-utc now that get_date() fixes this, we must use timestamps that do not include timestamps here. * bootstrap.conf: Add the clock-time, getdate, gettime, and setenv modules.
* Use struct timespec instead of time_t internallyAndreas Gruenbacher2010-04-221-3/+10
| | | | | | | | | | | | | | * src/pch.h (pch_timestamp): Return timestamp as struct timespec instead of time_t. * src/pch.c: Use struct timespec instead of time_t. A tv_sec value of -1 indicates "no timestamp". * src/util.h (fetchname): Return timestamp as struct timespec instead of time_t. * src/util.c (fetchname): str2time() does not give us nanoseconds; set them to zero for now. * src/patch.c (main): Only use the seconds in timestamps for now. * bootstrap.conf: Add the time module for getting struct timespec declared on old hosts.
* Replace quote_system_arg() with quoteargAndreas Gruenbacher2010-04-211-1/+11
| | | | | | | * src/util.c (quote_system_arg): Add a replacement for quote_system_arg() which uses quotearg's shell quoting style. * src/Makefile.am (patch_SOURCES): Remove quotesys.c and quotesys.h. * src/quotesys.c, src/quotesys.h: Delete.
* Cosmetic fixAndreas Gruenbacher2010-04-211-1/+1
| | | | * src/util.c (fetchname): Cosmetic fix.
* Globally rename type LINENUM to lin (as in diffutils)Andreas Gruenbacher2010-04-191-1/+1
| | | | * Globally rename type LINENUM to lin (as in diffutils).
* No longer use "continue" as the only instruction in a loop bodyAndreas Gruenbacher2010-01-151-3/+3
| | | | | | | | * src/bestmatch.h, src/diffseq.h, src/inp.c, src/maketime.c, src/merge.c, src/partime.c, src/pch.c, src/util.c: No longer use "continue" as the only instruction in a loop body: at least one compiler chokes on this in combination with variable-length arrays as in src/bestmatch.h.
* Do not allow timestamps in Index linesAndreas Gruenbacher2010-01-111-1/+4
| | | | * src/util.c (fetchname): Do not allow timestamps in Index lines.
* Try to preserve the owning group in backup filesAndreas Gruenbacher2010-01-041-0/+5
| | | | | * src/util.c (create_backup_copy): Try to preserve the owning group in backup files.
* * src/bestmatch.h, src/common.h, src/diffseq.h, src/inp.c, src/inp.h,Andreas Gruenbacher2010-01-021-7/+5
| | | | | | | | src/maketime.c, src/maketime.h, src/merge.c, src/partime.c, src/partime.h, src/patch.c, src/pch.c, src/pch.h, src/quotesys.c, src/util.c, src/util.h, src/version.c: Add year 2010 to copyright notice. Replace the GPLv2 license template with the GPLv3 license template.
* When copying files, use full_write() from gnulib instead of write()Andreas Gruenbacher2009-07-191-1/+2
|
* Don't fail when removing nonexistent files in move_fileAndreas Gruenbacher2009-06-151-1/+1
|
* Don't forget to NUL terminate ptimestr in fetchname()Andreas Gruenbacher2009-04-081-2/+3
|
* Preserve timestamps in reject filesAndreas Gruenbacher2009-04-071-4/+26
|