Compare commits

...

529 Commits

Author SHA1 Message Date
Daniel Black
d161c9a9db Skip read-only check when output file specified
Only check if input files are read-only when overwriting them; skip
that check when the output goes to a different file.

* src/patch.c (main): Set read_only_behavior to RO_IGNORE when an output
file has been specified.
* tests/read-only-files: Add test case.
2025-05-01 13:40:20 +02:00
Andreas Gruenbacher
4c302306a8 Reject empty filenames
* src/safe.c (safe_xstat): Reject empty pathnames.
* tests/bad-filenames: Add a new test.
* src/patch.c (main): Don't check if the input file is writable when
we're not going to modify it.
2025-04-05 17:26:56 +02:00
Andreas Gruenbacher
aea66268c9 Add some missing filename quoting
* src/patch.c (main): Quote outname.
2025-04-05 17:25:45 +02:00
Andreas Gruenbacher
77c27209f6 Fix 'make release' for proper releases
(Proper releases have a signed git tag.)
2025-03-29 22:40:26 +01:00
Andreas Gruenbacher
48ceda8200 Version 2.8
* NEWS: Update.
2025-03-29 17:17:03 +01:00
Petr Vaněk
b3d0c93338 Regression in commit abe92e8010ab affecting MariaDB tests
I have disovered a regression in commit abe92e8010ab ("Prefer idx_t,
ptrdiff_t to lin") while I was running MariaDB tests. The regression is
related to a diff file [1], where the patch fails to apply it with
following error:

  patch: **** '---' expected at line 2 of patch

To illustrate the issue, I have attached a git patch containing a
testcase with simplified reproducer.

[1] https://github.com/MariaDB/server/blob/mariadb-10.6.21/mysql-test/suite/innodb/r/innodb-wl5522%2Cstrict_crc32.rdiff file
2025-02-26 16:46:07 -08:00
Paul Eggert
29fced6251 Count traditional diff pattern lines correctly
This fixes a bug I introduced on Thu Sep 5 16:37:50 2024 -0700.
Problem reported by Petr Vaněk in:
https://lists.gnu.org/archive/html/bug-patch/2025-02/msg00017.html
* src/pch.c (another_hunk): Fix method for counting number
of lines in a traditional diff hunk.
2025-02-26 16:46:07 -08:00
Paul Eggert
b5d2124e2e patch: fix --no-backup-if-mismatch regression
Problem reported by Sam James in:
https://lists.gnu.org/archive/html/bug-patch/2025-02/msg00014.html
https://bugs.gentoo.org/show_bug.cgi?id=949834
* src/patch.c (backup_if_mismatch_specified): New static var.
(get_some_switches): Set it.
(main): Default backup_if_mismatch only if not set on command line.
* tests/no-backup: New file.
* tests/Makefile.am (TESTS): Add it.
2025-02-24 23:29:59 -08:00
Sam James
86ac7e2d7b Fix dodgy assert with side-effects in insert_cached_dirfd
Michał Górny <mgorny@gentoo.org> reported that patch was running out of
FDs and that the `deep-directories` test was failing. This turns out
to be because `hash_insert` isn't called at all with `-DNDEBUG` because
`insert_cached_dirfd` only calls it in one case inside of an `assert`.

See https://github.com/conda-forge/patch-feedstock/issues/11.

This regressed in 025a54b789bd88ed15430f8633514e296826983e.

* src/safe.c (insert_cached_dirfd): Don't use 'assert' for 'hash_insert'
  call with side-effects.
2025-02-06 21:13:20 +01:00
Bruno Haible
7d876522e9 Declare an expected test failure on Haiku.
* bootstrap.conf (gnulib_modules): Add test-xfail.
* tests/preserve-mode-and-timestamp: Add a comment regarding Haiku.
* tests/Makefile.am (XFAIL_TESTS): On Haiku, add preserve-mode-and-timestamp.
2025-02-06 21:03:10 +01:00
Andreas Gruenbacher
86baf979f4 build: update gnulib submodule to latest 2025-02-06 21:02:41 +01:00
Bruno Haible
1ba2c1bdf8 Fix two test failures on Haiku.
On Haiku, all error numbers are negative, see
<https://www.gnu.org/software/gnulib/manual/html_node/errno_002eh.html>.

Bisected by Eli Schwartz <eschwartz@gentoo.org>.

This partially reverts commit 043355371a76de8ea7d06f79a69fde905af7cc45.

* src/inp.c (get_input_file):
* src/patch.c (main):
* src/safe.c (read_symlink):
* src/util.c (move_file):
Don't assume that all system-defined errno values are positive.
2025-02-05 13:29:32 -08:00
Paul Eggert
1da6bf84db Check for newlines only when creating a file name
Also, check only the last file name component.
In other words, mimic operating systems that follow POSIX.1-2024’s
encouragement to fail with EILSEQ when openat etc. create a file name.
This is more conservative than the previous patch to prohibit
newlines in file names.
* src/patch.c (main, backup_file_name_option, get_some_switches):
* src/util.c (parse_c_string, make_tempfile):
Don’t check for newlines in a file name unless we are definitely
creating a file, as it’s harmless to read and stat file with
newlines in their names if the OS allows that.
* src/safe.c (traverse_another_path, traverse_path): New arg
REJECT_NL.  If set, reject any file name whose last component
contains a newline.  Also, do not do traversal if unsafe.  All
callers changed to pass true if they are creating the file name,
false otherwise, and to not bother checking whether we are unsafe.
(safe_open): Special case for when O_CREAT is set but O_EXCL is not.
* src/util.c (pfatal): Report "Invalid byte sequence" for EILSEQ.
This POSIX wording is less confusing than glibc's "Invalid or
incomplete multibyte or wide character".  Also, this lets
the test cases check for this wording.
* tests/bad-filenames: Adjust to new diagnostic wording.
2025-01-08 09:53:45 -08:00
Paul Eggert
30ee6103a5 Gnulib renamed some modules
* bootstrap.conf (gnulib_modules):
Adjust to recent module renaming in Gnulib.
2025-01-05 13:33:00 -08:00
Paul Eggert
6dbc381055 maint: update bootstrap from gnulib 2025-01-05 13:33:00 -08:00
Paul Eggert
05ac924fef build: update gnulib submodule to latest 2025-01-05 13:33:00 -08:00
Paul Eggert
95e0092f97 maint: make update-copyright 2025-01-05 13:33:00 -08:00
Andreas Gruenbacher
5bac274507 Set --no-backup-if-mismatch when in --posix mode
When in POSIX mode, the --no-backup-if-mismatch option should be
enabled.  However, this is only true when the POSIXLY_CORRECT
environmant variable is set but not when the --posix command line
option is given.  Fix that by setting backup_if_mismatch after
evaluating the command line arguments.
2024-11-20 23:54:48 +01:00
Andreas Gruenbacher
910fecf695 Add missing feature tests to the test suite
Check for chmod, hardlink, symlink, and special character support to
prevent test suite failures in feature constrained environments.

Thanks to Bruno Haible and Nelson H. F. Beebe for their testing and
analysis.

* tests/test-lib.sh: Add new feature tests.
* tests/hardlinks: Split this hardlinks related test off from
tests/remember-backup-files.
* tests/Makefile.am (TESTS): Add new hardlinks test here.
* tests/file-create-modes, tests/file-modes, tests/read-only-files,
tests/preserve-mode-and-timestamp, tests/no-mode-change-git-diff: These
tests require chmod support.
* tests/hardlinks, tests/unmodified-files: These tests require hardlink
support.
* tests/symlinks: This test requires symlink support.
* tests/quoted-filenames: This test requires special character support
in filenames.
2024-11-11 22:21:27 +01:00
Andreas Gruenbacher
be8b3c68b0 Disable release-prep
* cfg.mk: Disable release-prep by overriding the release-prep-hook for
now.  With that, "make release" succeeds for alpha releases.
2024-10-11 13:56:15 +02:00
Eli Schwartz
c61485bd05 Fix "make release" to handle alpha releases
news-check-regexp to scan for unreleased changes, has to be set
conditional on the release type. It has to be defined in cfg.mk, not
Makefile.am, so key off of the RELEASE_TYPE as automake conditionals are
not available.

Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
2024-10-11 13:53:07 +02:00
Andreas Gruenbacher
499916fdd8 Add announce-gen module for "make release"
* bootstrap.conf (gnulib_modules): Add announce-gen.
2024-10-11 11:43:59 +02:00
Paul Eggert
adb1ebce7f Pacify gcc -fsanitize=address
Some of this merely pacifies -fsanitize=address by pointing
to storage rather than freeing it when we are about to exit anyway.
Other parts of it keep track of storage more carefully so that it
can be freed rather than leak.
* src/common.h (struct outfile): New member ‘alloc’.
* src/patch.c (files_to_output_root) [SANITIZE_ADDRESS]:
New externally visible variable, to pacify -fsanitize=address.
(main): Use new functions described below to remove
files and free memory.
(delete_files): Do not free the list as we go, as we are about
to exit and -fsanitize=address doesn’t care about this storage.
(output_file_later): Set and use new member ‘alloc’ to avoid
memory leaks.
(output_files): WIth -fsanitize=address, record the list head
in files_to_output_root that the address sanitizer can see,
so that it won’t complain when we don’t free storage just before exit.
Free only when not exiting, and free using ‘alloc’ rather than ‘name’.
(perfile_cleanup_remove): New function.
(cleanup_remove): Rename from ‘cleanup’.  All uses changed.
Reimplement in terms of perfile_cleanup_remove.
(free_outfile_name, perfile_cleanup_free): New functions.
* src/util.c (make_tempfile): Set new member ‘alloc’.
2024-09-20 00:20:06 -07:00
Paul Eggert
6bdae94eb3 Fix memory leak when malformed unidiff patch
* src/pch.c (another_hunk): Fix memory leak when scanning a
unidiff patch malformed due to a line that does not begin with
‘ ’, ‘-’, ‘+’, or ‘=’.
2024-09-20 00:20:06 -07:00
Paul Eggert
72a146cfaf Port to clang address sanitizer
* src/patch.c (FREE_BEFORE_EXIT): Port to clang, which
uses __has_feature (address_sanitizer) instead of
defined __SANITIZE_ADDRESS__.  Also, rename this to
SANITIZE_ADDRESS since it is really about -fsanitize=address
rather than freeing before exit and as subsequent patches
will show there are simpler ways to pacify -fsanitize=address.
All uses changed.
2024-09-20 00:20:06 -07:00
Paul Eggert
e2e6820f71 Refactor argc+argv processing
* src/patch.c (Argc, Argv): Remove these confusing static variables.
They date back to before the code used getopt_long,
and are no longer needed.  All uses changed.
(get_some_switches): New args argc+argv, which are now used
instead of the static vars.  All uses changed.
2024-09-20 00:20:06 -07:00
Paul Eggert
606c09176c Omit needless get_some_switches code
* src/patch.c (get_some_switches): Remove unnecessary
initialization and testing.
2024-09-20 00:20:06 -07:00
Andreas Gruenbacher
ee3cc4016d Revert "Remove obsolete require_gnu_diff function"
Oops, function require_gnu_diff is still needed in two places.

This reverts commit 8cae4fc2213649e36e8f9a4cf21c28a82de3705c.
2024-09-18 14:51:33 +02:00
Andreas Gruenbacher
8cae4fc221 Remove obsolete require_gnu_diff function
* tests/test-lib.sh (require_gnu_diff): Remove.
2024-09-18 14:42:49 +02:00
Paul Eggert
164b529f53 savebuf can return a null pointer
* src/util.h (savebuf): Do not declare with ATTRIBUTE_RETURNS_NONNULL.
Bug caught by gcc -fsanitize=undefined.
2024-09-17 23:46:23 -07:00
Paul Eggert
91c1e4f071 Spelling fixes 2024-09-17 22:51:04 -07:00
Paul Eggert
a03e1bac4a Port other reject-format test to non-GNU diff
* tests/reject-format: Also don’t assume GNU diff
for the ab.diff file.  Problem discovered on Solaris 11.4.
2024-09-17 22:28:45 -07:00
Paul Eggert
9ba5eb00b3 Don’t be fooled by NUL bytes in diff directives
* src/pch.c (get_line, pget_line): New arg ALLOW_NUL.
It is true when getting data lines, which can contain NUL,
but false when getting ‘diff’ directives, which cannot.
All uses changed.
* tests/bad-filenames: Check that ‘patch’ rejects
directives containing NUL.
2024-09-17 17:43:23 -07:00
Paul Eggert
79dd5e762c Don’t be fooled by "\000" in file name
* src/util.c (parse_c_string): Don’t be tricked by perverse
C-style quoted strings containing backslash, '0', '0', '0'.
* tests/quoted-filenames: Test this.
2024-09-17 17:43:23 -07:00
Paul Eggert
8492a6a212 Port to quasi-GNU diff
Problem reported by Jim Meyering: ‘diff’ acted like GNU diff,
and generated correct output, but the output differed slightly
from what the test wanted.  As the output of ‘diff’ is not
completely determined from its input, it’s better to put
the desired ‘diff’ output directly in the test when the test
depends on the exact output.
* tests/preserve-c-function-names, tests/reject-format:
Do not require GNU diff or use ‘diff’.
Instead, cat the desired ‘diff’ output.
2024-09-17 17:43:23 -07:00
Paul Eggert
f6f2c6f31a In previous patch, make w_q static 2024-09-17 08:32:25 -07:00
Paul Eggert
0525681eb5 Pacify -Wunterminated-string-initialization
Problem reported by Jim Meyering.
* src/pch.c (do_ed_script): Pacify bleeding-edge GCC
-Wunterminated-string-initialization.
2024-09-17 08:27:49 -07:00
Andreas Gruenbacher
301411d927 Spelling fixes
Prefer 'timestamp' over 'time stamp'.
2024-09-17 10:59:25 +02:00
Andreas Gruenbacher
461520693e Remove double semicolon
* src/safe.c (remove_cached_dirfd): Remove a stray double semicolon.
2024-09-17 10:59:25 +02:00
Andreas Gruenbacher
923e0ef280 Prefer angle bracket headers
* src/util.h: Prefer angle brackets for gnulib header files.
2024-09-17 10:59:25 +02:00
Andreas Gruenbacher
5d17ca0e5f Update more old copyright notices
* configure.ac: Replace the old copyright notice with the current
version from COPYING.
* ChangeLog-2011: Likewise.
2024-09-17 10:59:15 +02:00
Paul Eggert
5f4edd389e Simplify memory allocation of files to delete
This pacifies ‘make sc_cast_of_argument_to_free’, which otherwise
complains about the ‘free ((void *) elt)’ in dispose_file_to_delete.
Rather than worry about pacifying that ‘make’ rule,
simplify memory allocation by doing the linked list by hand,
with a ‘next’ member the way our grandfathers did it.
This reduces the number of source code lines by 23,
removes the need for Gnulib’s linked-list and xlist modules,
and makes the code type-safer (as opposed to going through void *).
* bootstrap.conf (gnulib_modules): Remove linked-list, xlist.
* src/patch.c: Do not include gl_linked_list.h, gl_xlist.h.
(struct file_to_delete): New member ‘next’.
(files_to_delete): Now struct file_to_delete *, not gl_list_t.
(dispose_file_to_delete, init_files_to_delete):
Remove; no longer needed.
(files_to_delete_tail): New static var.
(delete_file_later): Append the new file by hand.
(delete_files): Iterate and free by hand.
2024-09-16 22:58:28 -07:00
Paul Eggert
802511c09b Report patch read errors more immediately
* src/pch.c (open_patch_file): Cache patch file descriptor.
When reading a patch, report read errors right away rather
than possibly waiting until end of input.
2024-09-16 17:39:10 -07:00
Paul Eggert
a93b50de71 Port fflush usage to OpenBSD 7.5
* src/inp.c (scan_input): Accept file descriptor, not stream.
All callers changed.
* src/patch.c (main): Do not obtain a stream for the patch
file descriptor, as scan_input merely needs a file descriptor.
This removes the need to call Fclose, which calls fflush,
which fails on OpenBSD 7.5 which (contra POSIX) does not
let you fflush an input stream.
2024-09-16 17:39:10 -07:00
Andreas Gruenbacher
55e224bd73 Update old copyright notices
* NEWS: Replace the old copyright notice with the current version from
COPYING.
* m4/setmode.m4: Likewise.
2024-09-17 00:07:22 +02:00
Paul Eggert
33a7fd89ec Fix gl_gcc_warnings typo in ‘configure’
* configure.ac (gl_gcc_warnings): Always set before using,
fixing a typo I introduced Sat Aug 24 08:28:18 2024 -0700.
2024-09-16 14:11:43 -07:00
Paul Eggert
2313b37f6a build: update gnulib submodule to latest 2024-09-16 13:35:24 -07:00
Paul Eggert
37fec39c58 Remove some dependencies no longer needed
* bootstrap.conf (gnulib_modules): Remove clock-time,
nstrftime, stdc_bit_ceil, time.
* src/inp.c: Do not include stdbit.h.
2024-09-16 13:34:01 -07:00
Paul Eggert
cc87173e46 Update NEWS as per recent changes 2024-09-15 22:50:38 -07:00
Paul Eggert
7887622b77 Update POSIX citations 2024-09-15 22:50:38 -07:00
Paul Eggert
18f4dd67ad Use “Gruenbacher” in international contexts
* patch.man: “Grünbacher” → “Gruenbacher”,
as per 2024-08-30 email from Andreas.
2024-09-15 22:50:38 -07:00
Paul Eggert
638675c19a Adjust libs to match recent Gnulib
* src/Makefile.am (patch_LDADD): Add $(CLOCK_TIME_LIB) (replacing
$(LIB_CLOCK_GETTIME)), $(EUIDACCESS_LIBGEN) (replacing
$(LIB_EACCESS), $(GETRANDOM_LIB), $(HARD_LOCALE_LIB), $(LIBINTL),
$(MBRTOWC_LIB), $(SETLOCALE_NULL_LIB).  This matches recent
Gnulib and is needed for AIX 7.1 which requires linking
with -lpthread.
2024-09-15 22:50:38 -07:00
Paul Eggert
53400a17ed Pacify clang -Wbitwise-conditional-parentheses
* src/util.c (copy_attr): Pacify clang 18.1.3 (1ubuntu1).
2024-09-15 22:50:38 -07:00
Paul Eggert
e8e1bcb7a0 Remove “support” for nested critical sections
It was a bit racy, and it’s no longer needed now that
we have shrunk critical sections.
* src/util.c (signals_are_deferred): Rename from signal_deferring_level.
Now effectively a boolean, instead of being a counter.
All uses changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
b963510dcd Simplify critical section code in util fns
* src/util.c (move_file, create_file, copy_file):
Do not worry about whether the file is temporary
when deciding whether to make a section of code critical.
Just do it.  There’s no need for optimization now
that we don’t need syscalls around critical sections.
2024-09-15 22:50:38 -07:00
Paul Eggert
85949fb4ac Shrink critical sections
* src/patch.c (main):
Do not put calls to output_files in critical sections,
as it can now deal with signals.
(struct file_to_output): ‘from’ member is now struct outfile, not
char volatile *volatile.  All uses changed.
(output_file_later): Append new structure to list in a critical section.
(output_files): Redo so that calls need not be in a critical section.
Instead, put critical sections around small subsidiary parts.
2024-09-15 22:50:38 -07:00
Paul Eggert
448ff9bc72 Defer signals by hand with sigatomic_t
Refactor by using a sig_atomic_t variable instead of a sigprocmask
call to defer signals.  This should be good enough for a
single-thread app where we write all the code that needs critical
sections, and where the signal handler merely cleans up and exits.
The resulting code should have the same behavior (including
signal-handling races!) as the original.
* bootstrap.conf (gnulib_modules): Remove sigaction, sigprocmask.
Instead, use sigaction only if it’s supported natively,
as the Gnulib emulation of sigaction drags in code we no longer need.
* configure.ac: Check for sigaction, sigfillset.
* src/patch.c (fatal_cleanup): New async-signal-safe function,
which does the cleanup that the old fatal_exit (SIG) did when SIG
was nonzero.
(fatal_exit): Do what the old fatal_exit (SIG) did when SIG was zero.
Omit SIG arg.  All callers changed.  This function is no longer
called from signal handlers, and so no longer needs to be
async-signal-safe under some circumstances.  However, it now
defers signals.
* src/util.c (signal_received): New static var.
(signal_deferring_level): Now sig_atomic_t.
(fatal_cleanup_and_terminate, handle_signal): New functions.
(defer_signals, undefer_signals): Reimplement by
using sigatomic_t volatile vars, not by using sigprocmask.
(init_signals): Don’t assume SIGPIPE since we don’t use the
Gnulib sigpipe module.  Use simple sigfillset signal mask
so that we needn’t use sigprocmask to inquire about the
current signal mask.  Have a fallback for old platforms
that lack sigaction and sigfillset, since we no longer use
Gnulib’s sigaction module.
(exit_with_signal): Remove; no longer needed.
2024-09-15 22:50:38 -07:00
Paul Eggert
b95a603908 output_file_later avoid a malloc+free pair
* src/patch.c (output_file_later, output_files):
Combine two malloc calls into one, and likewise for free.
Rename local to ‘f’ to make the code easier to follow.
2024-09-15 22:50:38 -07:00
Paul Eggert
2663228379 Defend against closed stdin/stdout/stderr
Various parts of ‘patch’ can misbehave when stdin, stdout, stderr
are closed.  For example, ‘dup’ can yield 0, 1, or 2 and the
resulting file descriptor will be misused.  Although POSIX
requires that ‘patch’ be invoked with stdin/stdout/stderror open,
it’s better to defend against the possbility that they’re not
open.  Use Gnulib’s xstdopen module to defend against this.
* bootstrap.conf (gnulib_modules): Add xstdopen.
* src/patch.c: Include xstdopen.h.
(main): Call xstdopen before doing I/O.
2024-09-15 22:50:38 -07:00
Paul Eggert
fc779640b0 Stop using Gnulib ‘execute’ module
This is motivated by wanting to remove dependencies on
Gnulib’s sigprocmask etc. modules, in later patches.
* bootstrap.conf (gnulib_modules): Remove execute.
* src/pch.c: Don’t include execute.h.
(do_ed_script): Use ‘quote_system_arg’ and ‘systemic’, not
‘execute’, to run the editor command while avoiding
quoting vulnerabilities.
* src/util.c (quote_system_arg): Now extern.
2024-09-15 22:50:38 -07:00
Paul Eggert
470699c8f2 Move defer_signals up
* src/util.c (signal_deferring_level, defer_signals, undefer_signals):
Refactor by moving up.  This should simplify later patches.
2024-09-15 22:50:38 -07:00
Paul Eggert
f696e4ef12 Make sigs, NUM_SIGS local
* src/util.c (sigs, NUM_SIGS): Refactor by moving these static
constants into the only function that uses them.
2024-09-15 22:50:38 -07:00
Paul Eggert
4d3a4ab09a Rename block_signals
This refactoring prepares for a new algorithm that does not use
SIG_BLOCK, and where the name ‘block_signals’ would be misleading.
* src/util.c (signal_deferring_level, defer_signals, undefer_signals):
Rename from signal_blocking_level, block_signals, unblock_signals.
All uses changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
b3bb925cee Trade a bit of space for time in parse_c_string
* src/util.c (parse_c_string): Omit unnecessary realloc.
2024-09-15 22:50:38 -07:00
Paul Eggert
070d859e07 Allocate first patchbuf statically
This way we avoid the need to call malloc first thing.
Usually there will no need to call malloc at all, for patchbuf.
* src/common.h (patchbuf, patchbufsize): Move extern decls from here ...
* src/pch.h: ... to here.
* src/patch.c (patchbuf, patchbufsize): Move defns from here ...
* src/pch.c: ... to here, and initialize patchbuf statically.
* src/patch.c (main): No need to initialize patchbuf.
* src/pch.c (initial_patchbuf): New static vbar.
(grow_patchbuf): New function.
(pget_line): Use grow_patchbuf rather than growing by hand.
* src/util.c: Include pch.h, for patchbuf.
(ask): Return patchbuf, not void, so that callers need not
include pch.h merely to access patchbuf.  All callers changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
f46a90f137 Use bigger buffer size by default
This idea is taken from GNU coreutils.
* src/patch.c (patchbufsize): Initialize statically rather than
dynamically.
* src/util.c (IO_MAX): Remove.  All uses replaced by IO_BUFSIZE.
* src/util.h (IO_BUFSIZE): New constant, taken from coreutils.
2024-09-15 22:50:38 -07:00
Paul Eggert
2e64cfd98c Preinitialize fatal_act.sa_hander
* src/util.c (fatal_act): Initialize .sa_handler statically ...
(init_signals): ... rather than dynamically.
2024-09-15 22:50:38 -07:00
Paul Eggert
45de0d99c8 Prefer EXIT_SUCCESS etc. to literal integers
* src/patch.c (main, usage, get_some_switches, fatal_exit):
* src/pch.c (do_ed_script):
* src/util.c (exit_with_signal):
Prefer EXIT_SUCCESS, EXIT_FAILURE, EXIT_TROUBLE to 0, 1, 2.
* src/util.h (EXIT_TROUBLE): New constant.
2024-09-15 22:50:38 -07:00
Paul Eggert
82c4940a2e Fix some signal handling races
Also, when a signal arrives, clean up temporary files that were
not put in /tmp.
* src/patch.c (main): Block signals around every call to output_files
and to remove_if_needed.
(struct file_to_output): ‘from’ and ‘to’ are now volatile,
as they are accessed in signal handler.
(files_to_output): Now volatile, and done by hand instead of
using gl_list_t so that it can be volatile.  All uses changed.
(files_to_output_tail): New var, which points to pointer to last
object in list (if any).  Volatile so it can be accessed by
signal handler.  All updates of list changed.
(dispose_file_to_output, init_files_to_output, gl_list_clear):
Remove; no longer used now that we are doing this list by hand.
(output_files): 2nd arg is now int, not bool; -1 means we
are in a signal handler.  When exiting due to a signal handler,
merely unlink (not safe_unlink) the source, and do not use
‘free’; this way, the code is async-signal-safe.
(fatal_exit): Arrange for signals to be blocked, when not
invoked as a signal handler.  Call output_files even when
signaled, as it will now do something sensible by deleting
temp files without renaming them.
2024-09-15 22:50:38 -07:00
Paul Eggert
eceea619a6 Fix --set-utc TZ setting
* src/patch.c (main): Set TZ to "UTC0", which older POSIX requires
support for, as opposed to "UTC", which even POSIX.1-2024 arguably
does not require support for.  Also, check for setenv failure.
2024-09-15 22:50:38 -07:00
Paul Eggert
9c55d3f541 Improve logic for when rename removes source
* src/util.c (move_file): Don’t test outfrom when it’s already
known to be non-null.  Don’t worry about destination link count
if we created the source.
2024-09-15 22:50:38 -07:00
Paul Eggert
61c72f07b3 Fix signal race when renaming file
* src/util.c (move_file): Fix race if a signal arives between
the time we rename a file and we mark the source as not existing.
2024-09-15 22:50:38 -07:00
Paul Eggert
705c9bcdc1 Simplify traverse_another_path via last_component
* src/safe.c: Include basename-lgpl.h.
(traverse_another_path): Simplify by using last_component.
2024-09-15 22:50:38 -07:00
Paul Eggert
77f21a6068 Stop using Gnulib dirname module
We don’t need its dir_name and base_name functions, since we
merely copy the strings elsewhere.  Instead, use some of the
modules that dirname uses.
* bootstrap.conf (gnulib_modules): Add basename-lgpl, filename.
Remove dirname.
* src/pch.c, src/util.c:
Include basename-lgpl.h and filename.h instead of dirname.h.
* src/pch.c (best_name):
* src/util.c (version_controller):
Use last_component instead of the dirname module’s functions.
* src/safe.c: Include filename.h instead of dirname.h.
* src/util.c (make_tempfile): No need to break the file name
into directory and basename; just use the whole file name.
2024-09-15 22:50:38 -07:00
Paul Eggert
fe8ffd9ba4 Fix implausible overflow when reading symlinks
* src/safe.c (read_symlink): Check for integer overflow
in bufferi size calculation.
2024-09-15 22:50:38 -07:00
Paul Eggert
5e84bda3ff Access checks should use effective, not real
* src/safe.c (safe_access): Use effective user and group ID,
not real user and group ID.
2024-09-15 22:50:38 -07:00
Paul Eggert
8d4ca493ed Don’t assume AT_FDCWD != -1
* src/safe.h (DIRFD_INVALID): New constant.
* src/safe.c (traverse_another_path, traverse_path, safe_xstat)
(safe_open, safe_rename, safe_mkdir, safe_rmdir, safe_unlink)
(safe_symlink, safe_chmod, safe_lchown, safe_lutimens)
(safe_readlink, safe_access):
Use it to port to perverse platforms where AT_FDCWD == -1.
2024-09-15 22:50:38 -07:00
Paul Eggert
fe5d4a06f7 Copy input to output attributes via fd if possible
* src/inp.c (scan_input): New arg ifp.  It is now the
caller’s responsibility to open and close the input.
Caller changed.
* src/patch.c (main): Open the input file for scan_input, and use
its file descriptor, if available, to avoid some races while
setting output file attributes.
2024-09-15 22:50:38 -07:00
Paul Eggert
ca4c431f8a Simplify timestamp epoch checking
* src/util.c (fetchname): Simplify timestamp calculations.
Also, add a comment saying why they are buggy in obscure
cases that have little practical implication.
2024-09-15 22:50:38 -07:00
Paul Eggert
0ad4347277 Check for ftello failures
Also, use Gnulib modules fseeko, ftello, and rely on off_t,
fseeko, ftello as they are safe to use nowadays.
* bootstrap.conf (gnulib_modules): Add fseeko, ftello.
This is needed only for very old platforms, plus MSVC.
* src/common.h (file_offset, file_seek, file_tell): Remove.
All uses replaced with off_t, fseek, ftell.
* src/util.c (Fseeko): Rename from Fseek.  All uses changed.
(Ftello): New function.  All ftello callers that rely on
nonnegative results changed to Ftello.
2024-09-15 22:50:38 -07:00
Paul Eggert
c49a16d0ca Remove format_linenum
* src/util.c (format_linenum):
* src/util.h (LINENUM_LENGTH_BOUND):
Remove.  They are no longer needed now that line numbers can be
printed with %td.  All uses replaced by printf with %td.
2024-09-15 22:50:38 -07:00
Paul Eggert
22efdeebaa Fix "with multiple words" line number
* src/pch.c (intuit_diff_type): Fix typo in diagnostic,
which output a file offset as if it were a line number.
2024-09-15 22:50:38 -07:00
Paul Eggert
5a70a1b6b9 Drop Plan B
‘patch’ dates back to when porting to 16-bit machines still
mattered, and where it was therefore useful to support files that
did not fit in RAM.  So ‘patch’ had two operating modes, Plan A
and Plan B.  In Plan A the input was simply read into memory, but
if memory was exhausted ‘patch’ fell back onto Plan B where input
was transformed into a temporary file that holds the input lines.
The idea was to not use any malloc calls during the main part of
the ‘patch’ run, so that ‘patch’ could not exhaust memory if Plan
A succeeded.  Over the years, though, that approach has not always
been observed, as malloc is called for sundry reasons and ‘patch’
immediately fails when malloc fails other than during the Plan A
initial phase.  In practice this misbehavior has not been a
problem, as ‘patch’ now invariably runs on machines where source
file contents fit into RAM so Plan B is never used.  The GNU
Coding Standards says not to worry about supporting machines too
small to read file contents, and now’s a good time to remove the
Plan B code, as it is making further maintenance a pain.
* bootstrap.conf (gnulib_modules): Remove ialloc.
All uses of ialloc.h and its API removed, and replaced by
xalloc.h API as needed.
* src/common.h (lin, LINENUM_MIN, LINENUM_MAX): Remove.
All uses of ‘lin’ replaced by idx_t if known to be nonnegative,
ptrdiff_t otherwise.  All uses of LINENUM_MAX replaced by IDX_MAX.
LINENUM_MIN was not used.
* src/inp.c (tibufsize, TIBUFSIZE_MINIMUM, tifd, tibuf, tiline)
(lines_per_buf, tireclen, last_line_size, too_many_lines)
(lines_too_long, plan_a, plan_b): Remove.  All uses removed.
(scan_input): Do just what plan_a used to do, except report a fatal
error on memory exhaustion.
Do not worry about file types other than regular file or symlink
as they are not possible.  All uses changed.
(ifetch): Omit WHICHBUF arg, which is no longer needed now that
we always use Plan A.  All uses changed.
* src/patch.c (tmpin): Remove.  All uses removed.
* src/pch.c (grow_hunkmax, pget_line): Use xpalloc rather than
doing the equivalent by hand.
(grow_hunkmax): Always succeed.  All uses changed.
(another_hunk): Return bool not signed char, since -1 is
no longer possible.  All uses changed.
Use ximemdup0 instead of savestr when that is more convenient.
(get_line, pget_line): Return idx_t, not ptrdiff_t, since -1
is no longer possible.  All uses changed.
* src/util.c (savebuf): Always succeed.  All callers changed.
Simplify.
(Write): Now static.
2024-09-15 22:50:38 -07:00
Paul Eggert
c0d465f21b Prefer ximemdup0 to xmemdup0
This is natural, as the args are all nonnegative ptrdiff_t, not size_t.
It also removes the need for Gnulib’s xmemdup0 module.
* bootstrap.conf (gnulib_modules): Remove xmemdup0.
* src/pch.c, src/util.c: Do not include xmemdup0.h.
All calls to xmemdup0 replaced by ximemdup0.
2024-09-15 22:50:38 -07:00
Paul Eggert
b91aab2c88 Refactor ifetch API
* src/inp.c (ifetch): Return struct iline, instead of
returning a pointer and storing through a pointer.
All callers changed.
* src/inp.h (struct iline): New type.
2024-09-15 22:50:38 -07:00
Paul Eggert
55c8a5c494 Do not attempt huge I/Os
Also, simplify I/O error checking by moving some of it into
new functions Read and Write.
* bootstrap.conf (gnulib_modules): Remove full-write.
* src/inp.c (plan_a, plan_b, ifetch):
* src/util.c (move_file, copy_to_fd):
Use Read or Write instead of checking for I/O errors by hand.
* src/util.c: Do not include full-write.h.
(IO_MAX): New constant.
(ifetch): Diagnose temp file shrinkage.
(ask): Do not attempt a read of more than IO_MAX bytes.
Use xpalloc to reallocate, instead of doing it by hand.
(Read, Write): New functions.
2024-09-15 22:50:38 -07:00
Paul Eggert
e0e121efe5 Use outfd when setting file attributes
* src/patch.c (main): Check for output error when closing outfd.
Use outfd when setting file attributes, to fix some races.
This means delaying closing until after setting file attributes.
(spew_output): Don’t close output stream; that is now the
caller’s responsibility.  Caller changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
241e57ea5b Don’t assume Linux-like S_IFREG
* boostrap.conf (gnulib_modules): Add assert-h.
* src/pch.c (fetchmode): Convert Git type to local file type.
2024-09-15 22:50:38 -07:00
Paul Eggert
0f8c62835f Use STDOUT_FILENO etc
* src/patch.c (open_outfile):
* src/pch.c (do_ed_script): Prefer macros like STDOUT_FILENO to
expressions like 1 or fileno (stdout).
2024-09-15 22:50:38 -07:00
Paul Eggert
f2c3676393 Fix unlikely glitch with ed diffs
* src/patch.c (main): If tmpout can’t be created, don’t
continue when diff_type == ED_DIFF.
2024-09-15 22:50:38 -07:00
Paul Eggert
cec6407930 Use fds to copy attrs in create_backup_copy
* src/util.c (create_backup_copy): Let the new copy_file set file
attributes, as this can be done more straightforwardly via
file descriptors.
(copy_to_fd): Return the source file descriptor instead of closing
it, so that the caller can use it before closing.  All callers changed.
(copy_file): New arg ATTR.  Set the destination’s attributes
accordingly.  All callers changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
6b7b01b89b Be more careful about (time_t) -1
* src/patch.c (main):
* src/pch.c (intuit_diff_type):
* src/util.c (fetchname):
Mark an invalid timespec with both .tv_sec = (time_t) -1
and with .tv_nsec = -1.  This is more reliable in case
time_t is unsigned and narrower than int, in which case
(time_t) -1 != -1.  It’s also more reliable in the unusual case
where (time_t) -1 is a valid timestamp.  All uses changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
043355371a X == -1 → X < 0
* src/inp.c (get_input_file, plan_b, ifetch):
* src/patch.c (main, get_some_switches, open_outfile)
(init_reject, output_file_now):
* src/pch.c (open_patch_file, there_is_another_patch)
(another_hunk, do_ed_script):
* src/safe.c (read_symlink, traverse_another_path):
* src/util.c (move_file):
Prefer X < 0 to X == -1 when either comparison will do.
This lets us focus better on oddball cases like uid_t and time_t
when converted from -1.
2024-09-15 22:50:38 -07:00
Paul Eggert
0a66dee829 Let set_file_attributes use fds not names
Although this ability is currently not used, so this commit is
merely refactoring, the patch should help ‘patch’ avoid some race
conditions in followup commits.
* bootstrap.conf (gnulib_modules): Add futimens.
* src/util.c: Include utimens.h.
(lacks_appropriate_privileges, copy_fdattr_error): New functions.
(copy_attr): New args src_fd, dst_fd.  All uses changed.
(set_file_attributes): New args tofd, fromfd.  All uses changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
36ff2c9296 Port to narrow unsigned uid_t
* src/util.c (set_file_attributes): Work even if uid_t or gid_t
is unsigned and narrower than int, so that (uid_t) -1 != -1.
2024-09-15 22:50:38 -07:00
Paul Eggert
3951496739 Check for output errors more systematically
* bootstrap.conf (gnulib_modules): Add closeout.
* src/merge.c (print_linerange, merge_result, merge_hunk):
* src/patch.c (main, usage, get_some_switches)
(print_unidiff_range, abort_hunk_unified, abort_hunk_context)
(apply_hunk, copy_till, spew_output):
* src/pch.c (open_patch_file, there_is_another_patch)
(another_hunk, pch_write_line, do_ed_script):
* src/safe.c (traverse_another_path):
* src/util.c (putline, vsay, ask, systemic):
* src/version.c (version):
Check for output errors more systematically.
* src/patch.c: Include closeout.h.
(main): Invoke close_stdout at exit.
* src/util.c (fatal): Use fputc, not putc; no need for speed here.
(pfatal): Use fprintf, not putline, to avoid recursion loop
on write error.
(Fclose, Fflush, Fprintf, Fputc, Fputs, Fwrite):
New functions, to go with Fseek.
* src/version.c: Include util.h, for Fprintf.
2024-09-15 22:50:38 -07:00
Paul Eggert
6429630c0c Report input error right away
* src/inp.c (plan_b):
* src/pch.c (incomplete_line):
When getc fails due to an input error, report the error right away.

Simplify EOF testing
2024-09-15 22:50:38 -07:00
Paul Eggert
03cb187db6 Simplify EOF testing
* src/inp.c (plan_b):
* src/patch.c (apply_hunk, copy_till):
* src/pch.c (skip_to, pget_line, incomplete_line, do_ed_script):
Just check whether a value is negative, rather than exactly EOF.
This simplifies the code a bit, and speeds it up very slightly.
2024-09-15 22:50:38 -07:00
Paul Eggert
cc7cde7a2c Prefer other types to ‘int’
* src/merge.c (merge_result, merge_hunk):
Hunk number is intmax_t, not int, fixing an unlikely overflow.
* src/patch.c (invc): Now signed char, not int.
(numeric_string): Use bool, not int, for sign.
* src/pch.c (p_says_nonexistent, sha1_says_nonexistent)
(pch_says_nonexistent): Now char, not int.  All uses changed.
(p_rfc834_nesting, pget_line): Use idx_t, not int,
fixing an unlikely overflow.  All uses changed.
(another_hunk): Now signed char, not int.  All uses changed.
* src/util.c (format_linenum): Remove unnecessary casts to int.
2024-09-15 22:50:38 -07:00
Paul Eggert
4c6650b507 Detect unlikely integer overflow in size calcs
* src/pch.c (set_hunkmax, grow_hunkmax): Check for unlikely
integer overflow in size calculations, by using ireallocarray
rather than realloc and similarly for xireallocarray vs xmalloc.
(grow_hunkmax): Rely on C89 guarantee that when realloc fails, the
old storage is still available.  We need not worry any more about
ancient hosts where that was not true.  Grow by a factor of
1.5, as per xpalloc, instead of by a factor of 2.
2024-09-15 22:50:38 -07:00
Paul Eggert
abe92e8010 Prefer idx_t, ptrdiff_t to lin
Prefer idx_t and ptrdiff_t to lin when counting lines in main
memory.  This is mostly for clarity, though it should help
efficiency slightly in obsolescent 32-bit platforms.
* src/inp.c (ifetch):
* src/merge.c (locate_merge, merge_hunk, count_context_lines)
(context_matches_file, compute_changes):
* src/patch.c (main, locate_hunk, mangled_patch)
(print_unidiff_range, abort_hunk_unified, abort_hunk_context)
(apply_hunk, patch_match):
* src/pch.c (p_ptrn_lines, p_repl_lines, p_end, p_max)
(p_prefix_content, p_suffix_content, hunkmax, p_efake, p_bfake)
(another_hunk, pch_swap, pch_ptrn_lines, pch_repl_lines)
(pch_end, pch_prefix_context, pch_suffix_context, pch_line_len)
(pch_char, pfetch, pch_write_line, pch_normalize):
Prefer idx_t to lin for object sizes.
Prefer ptrdiff_t to lin for pointer differences.
All uses changed.
* src/merge.c (compute_changes): Check for integer overflow
when combining file with memory counts, when the result
must fit into memory.
2024-09-15 22:50:38 -07:00
Paul Eggert
30449e294b Fix compatibility issue with blanks in patches
* src/util.c (remove_prefix): Remove; no longer used.
* src/pch.c (intuit_diff_type, scan_linenum, another_hunk):
Allow a nonempty sequence of blanks in places where POSIX requires
support for these sequences.
(another_hunk): Parse the "0,0" instead of comparing it literally,
since there can be blanks around the comma.
* tests/Makefile.am (TESTS): Add unusual-blanks.
* tests/unusual-blanks: New file.
2024-09-15 22:50:38 -07:00
Paul Eggert
9228a8cf28 pch_swap return type cleanup
* src/pch.c (pch_swap): Return void not bool, since it always
returns true if it returns at all.  All uses changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
c1c438d3a8 Fix unlikely int overflow in hunk counts
* src/patch.c (main): Don’t assume hunk counts fit in int.
2024-09-15 22:50:38 -07:00
Paul Eggert
5d3f41f6fc Use char for char in plan_a
* src/inp.c (plan_a): Use char, not int, for local.
2024-09-15 22:50:38 -07:00
Paul Eggert
fb056f23ac Cache cwd_is_root dev, ino
* src/util.c (cwd_is_root): Cache stat results.
2024-09-15 22:50:38 -07:00
Paul Eggert
84b5f34f2a Avoid ‘unsigned’ in safe.c
* src/safe.c (MAX_SAFE_COMPONENTS): Now an enum instead of unsigned.
(dirfd_cache_misses): Now intmax_t instead of unsigned.
All uses changed.
(count_path_components): Return idx_t, not unsigned, to
avoid issues with file names with more than INT_MAX components.
All uses changed.
2024-09-15 22:50:38 -07:00
Paul Eggert
d2e113e9a4 Simplify get_sha1
* src/pch.c (get_sha1): Return the new string instead of storing
through a pointer.  All uses changed.  Use xmemdup0 instead of
duplicating its logic.
2024-09-15 22:50:38 -07:00
Paul Eggert
f73718b634 Avoid casts in patch.c
* src/patch.c (main, get_some_switches, abort_hunk_context):
Redo to avoid casts.
(main): Use %#o rather than 0%o for octal output, to avoid
unnecessary leading 0.
2024-09-15 22:50:38 -07:00
Paul Eggert
79eef3e014 Prefer idx_t in util.c
* src/util.c (file_id_hasher): Avoid unlikely signed integer
overflow when adding e->ino and e->dev.
(create_backup, copy_to_fd, quote_system_arg, version_controller)
(savebuf, remove_prefix, removedirs): Prefer idx_t to size_t.
2024-09-15 22:50:38 -07:00
Paul Eggert
11588d0fa2 Prefer idx_t in pch.c
* src/pch.c (p_len, p_indent, open_patch_file, intuit_diff_type)
(prefix_components, best_name, another_hunk, get_line, pget_line)
(pch_swap, pch_line_len):
Prefer idx_t or ptrdiff_t to size_t.  All uses changed.
(intuit_diff_type): Rename local distance_from_minimum to
above_minimum, and make it 1 or 0 which is all that is needed.
This avoids integer overflow when the distance exceeds INT_MAX.
2024-09-15 22:50:38 -07:00
Paul Eggert
e16037d11f Prefer idx_t in patch.c
* src/patch.c (patchbufsize, main, similar):
Prefer idx_t to size_t.  All uses changed.
* src/pch.c (pget_line):
* src/util.c: Include ialloc.h.
(ask): Avoid bad behavior on unlikely size overflow.
When converting from size_t to idx_t,
prefer reallocation growth by 50% not 100%, to match xpalloc.
2024-09-15 22:50:38 -07:00
Paul Eggert
388926ffa7 Prefer idx_t in list.h
* src/list.h (list_entry): Prefer idx_t to size_t.
2024-09-15 22:50:38 -07:00
Paul Eggert
3582fdb953 Prefer idx_t in inp.c
Prefer signed to unsigned types for object sizes,
as they have better checking (e.g., gcc -fsanitize=undefined).
* bootstrap.conf (gnulib_modules): Add idx (already being used
indirectly) and stdc_bit_ceil.
* src/common.h: Include idx.h.
* src/inp.c: Include stdbit.h.
(tibufsize, tireclen, last_line_size, plan_a, ifetch):
Prefer idx_t to size_t for object sizes.  All uses changed.
(lines_per_buf): Prefer idx_t to lin when it's talking about
object sizes.
(plan_b): Check for idx_t overflow too.  Use stdc_bit_ceil
instead of doing it by hand.
2024-09-15 22:50:38 -07:00
Paul Eggert
4a47c002fa build: update gnulib submodule to latest 2024-09-15 22:50:38 -07:00
Paul Eggert
4f8c4b8842 Don’t limit strip counts etc. to INT_MAX
* src/patch.c (debug): Now unsigned short int, not int, since
it is used as a mask and only the bottom 9 bits matter.
(patch_get, strippath, maxfuzz): Now intmax_t, not int.
(numeric_string): Return intmax_t, not int.
On overflow return an extremum rather than reporting an error,
since the resulting values are effectively infinity anyway.
All uses changed.
* src/util.c (success, fetchname, parse_name): Accept intmax_t, not int.
2024-09-15 22:50:38 -07:00
Paul Eggert
0a810b6e27 Fix unlikely integer overflows in patch.c
* src/patch.c (numeric_string): Use stdckdint instead of
by-hand overflow checks that might not work.
2024-09-15 22:50:38 -07:00
Paul Eggert
bac3b6d06a Fix unlikely integer overflows in pch.c
* src/pch.c (scan_linenum): Use stdckdint instead of by-hand
overflow checks that might not work.  Fix already-existing
use of ckd_add that wasn’t done quite correctly.
2024-09-15 22:50:38 -07:00
Paul Eggert
8fb784b7d0 Fix unlikely integer overflows in inp.c
* bootstrap.conf (gnulib_modules): Add ialloc.
* src/inp.c: Include ialloc.h.
(plan_a, plan_b): Prefer idx_t and ssize_t to size_t.
Use stdckdint instead of by-hand overflow checks that might not work.
2024-09-15 22:50:38 -07:00
Paul Eggert
e10f3ca472 Promote minmax.h to common.h
* src/common.h: Include minmax.h here ...
* src/merge.c, src/patch.c, src/safe.c: ... instead of here.
2024-09-15 22:50:38 -07:00
Paul Eggert
57e2165767 Avoid some memory allocation by not using ‘const’
* src/common.h (struct outfile.exists):
* src/safe.c (struct symlink.path):
Member is no longer pointer to const.  All uses changed.
* src/inp.c (get_input_file, plan_a, plan_b):
* src/patch.c (delete_file_later):
* src/pch.c (do_ed_script):
* src/safe.c (safe_xstat, safe_stat, safe_lstat, safe_open)
(safe_rename, safe_mkdir, safe_rmdir, safe_unlink, safe_symlink)
(safe_chmod, safe_lchown, safe_lutimens, safe_readlink)
(safe_access):
* src/util.c (volatilize set_file_attributes, create_backup_copy)
(create_backup, copy_to_fd, copy_file, append_to_file, trystat)
(version_get, stat_file):
Arg no longer points to const.  All callers changed.
* src/safe.c (openat_cached):
Make a copy of arg, to simplify API.
Arg now points to const, since it no longer needs write access.
(traverse_next, traverse_another_path, traverse_path):
Arg points to pointer that is no longer pointer to const.
Temporarily change argument string instead of duplicating it and
changing the copy.  All uses changed.
* src/util.c (volatilize): Result is no longer pointer to const.
2024-09-15 22:50:38 -07:00
Paul Eggert
eb18b39cc7 Remove unnecessary char * casts in inp.c
* src/inp.c (plan_a): Remove unnecessary casts to char *.
2024-09-15 22:50:38 -07:00
Paul Eggert
d60cb724bd Pacify gcc -Wunused-parameter when !USE_XATTR
* src/common.h (struct outfile.exists):
Now char const volatile *volatile, not bool volatile,
so that we follow the C standard more strictly.
All uses changed.
* src/util.c (UTIL_INLINE): New macro.
(volatilize): New function.
* src/util.h: Use _GL_INLINE_HEADER_BEGIN, UTIL_INLINE.
(devolatilize): New function.
2024-09-15 22:50:38 -07:00
Paul Eggert
05ef886471 Pacify gcc -Wunused-parameter when !USE_XATTR
* src/util.c (copy_attr) [!USE_XATTR]: Mark args with MAYBE_UNUSED.
2024-09-15 22:50:38 -07:00
Paul Eggert
1f8d192897 maint: stop using alloca
It means unbounded allocation on the stack, which is trouble
on some platforms.  Also, gcc-12 on Pop!_OS 22.04 LTS complains.
* bootstrap.conf (gnulib_modules): Remove alloca.
* src/pch.c, src/safe.c: Don’t include alloca.h.
* src/pch.c (do_ed_script):
Use designated initializer instead of fixed-size alloca.
* src/safe.c (new_cached_dirfd, openat_cached):
Name arg is now allocated on heap by caller, and is now char * not
char const *.  All callers changed.
(openat_cached, traverse_next): Redo to avoid gotos.
(traverse_next, traverse_another_path):
Use ximemdup0 instead of alloca, to allocate on the heap rather than
unboundedly on the stack.
2024-09-15 22:50:38 -07:00
Paul Eggert
ba92722539 Don’t assume O_RDONLY == 0
* src/safe.c (O_PATHSEARCH): New constant.
(openat_cached): Use it, so as to not assume that
O_RDONLY == 0, and so that the open works even if
the directory is unreadable (except on ancient hosts).
2024-09-15 22:50:38 -07:00
Paul Eggert
0f98e033f2 Avoid syscall when nested signal block
* src/util.c (block_signals): Don’t call sigprocmask
when nesting, as the signals are already blocked.
2024-09-15 22:50:38 -07:00
Paul Eggert
1235ccc55b Add signal comment
* src/patch.c (main): Comment why signals are blocked here,
and add a FIXME.
2024-09-15 22:50:38 -07:00
Paul Eggert
43ee674679 build: update gnulib submodule to latest 2024-08-28 23:13:44 -07:00
Paul Eggert
e3819470dc Update NEWS, README-prereq 2024-08-28 23:13:44 -07:00
Paul Eggert
2c2a83b77a Omit _Noreturn when easy
* src/inp.c (too_many_lines, lines_too_long):
* src/patch.c (mangled_patch):
* src/pch.c (malformed):
Omit _Noreturn for functions where it is automatically deduced in
a default build by gcc (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1) x86-64.
2024-08-28 23:13:44 -07:00
Paul Eggert
a13c2eaf16 Replace __attribute__ with attribute.h
* src/common.h (__attribute__): Remove.
All uses replaced by _Noreturn or ATTRIBUTE_FORMAT.
2024-08-28 23:13:44 -07:00
Paul Eggert
6eb2d138e6 Switch from ctype.h to c-ctype.h
* bootstrap.conf (gnulib_modules): Add c-ctype.
It’s alreay being used indirectly.
* src/common.h: Include c-ctype.h instead of ctype.h.
All uses of isspace replaced by c_isspace; this is equivalent
since we do not call setlocale.  All uses of c==' ' || c=='\t'
replaced by c_isblank.
Sort includes, system includes last.
(ISDIGIT): Remove.  All uses replaced by c_isdigit.
2024-08-28 23:13:44 -07:00
Paul Eggert
d1a6847368 Simplify warning configuration
* configure.ac (WARN_CFLAGS): Simplify configuration
by not bothering to suppress warnings that don’t
need to be suppressed with GCC 14.2.1.
2024-08-28 23:13:44 -07:00
Paul Eggert
d6631b3125 Prefer ATTRIBUTE_* to _GL_ATTRIBUTE_*
When attribute.h defines a shorthand macro, use it
to avoid _GL_ prefixes.  This affects _GL_ATTRIBUTE_FORMAT
and _GL_ATTRIBUTE_PURE.
2024-08-28 23:13:44 -07:00
Paul Eggert
bc6899dc6f Pacify gcc -Wno-unused-parameter
* bootstrap.conf (gnulib_modules): Add ‘attribute’.
It’s already being used indirectly.
* configure.ac (WARN_CFLAGS): Omit -Wno-unused-parameter.
* src/common.h: Include attribute.h.
(FALLTHROUGH): Remove, as attribute.h does this now.
* src/util.c (copy_attr_error, copy_attr_quote, copy_attr_free):
Use MAYBE_UNUSED.
2024-08-28 23:13:44 -07:00
Paul Eggert
da259855ca Improve ‘git diff’ output if desired
* .gitattributes: New file.
2024-08-28 23:13:44 -07:00
Paul Eggert
248ef134f8 Prefer strerror to perror
* src/patch.c (putline): Move from here ...
* src/util.c: ... to here, and make it extern.
* src/pch.c (there_is_another_patch):
* src/util.c (pfatal):
Use putline with strerror rather than attempting to work
around old perror bugs.  This also works better in the
unlikely case where the program name length does not fit
in int.
2024-08-28 23:13:44 -07:00
Paul Eggert
6cb321aff4 A bit more long-string fixing
* src/util.c (fatal, pfatal): Avoid unlikely int overflow
with very long program names.
2024-08-28 23:13:44 -07:00
Paul Eggert
47bc09dc6a Prefer nullptr to NULL
C23-style nullptr has some minor static-checking advantages over
C89-style NULL, and we’re already using Gnulib’s nullptr module.
* src/inp.c, src/patch.c, src/pch.c, src/safe.c, src/util.c:
Prefer nullptr to NULL.
2024-08-28 23:13:44 -07:00
Paul Eggert
7608746040 More fixing of printing of very long strings
* bootstrap.conf (gnulib_modules): Add nullptr.
* src/patch.c (if_defined, not_defined):
Now merely strings, not printf formats.  All uses changed.
(putline): New static function.
(print_header_line, abort_hunk_unified, abort_hunk_context)
(apply_hunk): Use it to remove assumptions that string
lengths fit in int.  Also, prefer fputs to printf with plain %s.
(print_header_line): TAG arg now is assumed to have an appended ' ',
to save us the trouble of outputting ' ' separately.  All uses changed.
2024-08-28 23:13:44 -07:00
Paul Eggert
323da0da04 Don’t assume string sizes fit in int when printing
* src/common.h: Move stdckdint.h include here ...
* src/util.c: ... from here.
* src/pch.c (scan_linenum):
* src/safe.c (traverse_another_path):
Don’t assume pointer differences fit in int when calling printf.
2024-08-28 23:13:44 -07:00
Paul Eggert
53d10143f2 Avoid fprintf INT_MAX overflow when merging
* src/merge.c (merge_hunk): Don’t assume patch line lengths
fit in int.
2024-08-28 23:13:44 -07:00
Paul Eggert
59681c8e9a Avoid sprintf INT_MAX overflow
The bug is extremely unlikely, but it’s easy to fix.
* bootstrap.conf (gnulib_modules): Add stpcpy.
* src/util.c (SCCSPREFIX): Now a macro, so that it can be concatenated.
(try1, try2): Remove these macros.  Replace all uses with ...
(trystat): ... this new function.
* src/util.c (version_controller, make_tempfile):
Avoid issues with sprintf result exceeding INT_MAX.
2024-08-28 23:13:44 -07:00
Paul Eggert
4278b91942 Reject output file names containing '\n'
This is encouraged by POSIX.1-2004.
* bootstrap.conf (gnulib_modules): Add mempcpy.
* src/patch.c (main, get_some_switches):
* src/util.c (parse_c_string):
Reject output file names containing newlines.
(backup_file_name_option): New function, to help with that.
(make_tempfile): Reject TMPDIR values containing newlines.
Do not silently screw up if TMPDIR length exceeds INT_MAX.
* tests/bad-filenames: Test for file names containing '\n'.
2024-08-28 23:13:44 -07:00
Paul Eggert
34b45bc78b Update man page a bit.
* patch.man: Fix minor formatting glitches.
Remove obsolete references to news articles, as Larry Wall’s
once-famous ‘rn’ program is no longer used.
Mention Git.  Update Autoconf mention.
Remove discussion of differences between current patch
and patch 2.1 and earlier, as 2.1 is so old I can’t
easily find out its release date.
2024-08-28 23:13:44 -07:00
Paul Eggert
d18c05d5bd Update copyright notices
Switch to single intervals for FSF notices,
and consistently put them first.
Update copyright notices for 2024.
* cfg.mk (update-copyright-env): Use UPDATE_COPYRIGHT_FORCE=1,
UPDATE_COPYRIGHT_USE_INTERVALS=2.
* patch.man: Always use \(co, so that update-copyright
updates these dates.
* src/version.c: Correct Larry Wall copyright years.
2024-08-28 23:13:44 -07:00
Paul Eggert
af828e563c Fix some races involving signals
* src/common.h (struct outfile.exists): Now volatile.
2024-08-28 23:13:44 -07:00
Paul Eggert
b3a6c95537 Don’t attempt to remove files we didn’t create
Fix part of a race condition when a signal arrives, which can
cause ‘patch’ to remove the wrong file.
* src/common.h (struct outfile.temporary): New member.
* src/patch.c (tmped, tmpin, tmppat, tmpout): Initialize it.
(outrej): New static var, replacing the old rejname, but now
of type struct outfile rather than char *.  All uses changed.
* src/patch.c (create_output_file):
* src/util.c (create_file, copy_file):
Accept struct outfile * instead of char *.  All uses changed.
* src/patch.c (open_outfile, output_file_now, output_file):
* src/util.c (create_backup_copy, move_file):
Accept char * instead of char const *, so that the pointer can be
copied into a struct outfile.  All uses changed.
* src/util.c (create_file, copy_file, try_safe_open):
Block signals for temporary files, so that signal handlers always
see an ‘exists’ member consistent with whether we created the file.
(unblock_signals): Preserve errno so that caller need not do that.
(struct try_safe_open_args.out): New member.  All uses changed.
(try_safe_open, make_tempfile): Rely on try_tempname to set
out->exists, rather than having make_tempfile do it (which
would mean a much longer critical section).
2024-08-28 23:13:44 -07:00
Paul Eggert
9abc949979 Omit goto in try_safe_open
* src/util.c (try_safe_open): Rewrite to avoid goto.
2024-08-28 23:13:44 -07:00
Paul Eggert
90e62d5195 Pacify clang re obsolete O_CREAT test
* src/util.c (create_file): Remove obsolete test O_CREAT && O_TRUNC.
clang compares about it, and we don’t need to worry about ancient
platforms lacking O_CREAT or O_TRUNC.
2024-08-28 23:13:44 -07:00
Paul Eggert
2b87c1eb7f Allow nested block/unblock of signals
* src/util.c (initial_signal_mask): Now auto, not static.
(init_signals): Do not block a signal that is already blocked.
(signal_blocking_level): New static var.
(block_signals, unblock_signals): Support nested block/unblock calls.
2024-08-28 23:13:44 -07:00
Paul Eggert
7aa1c3bc32 Adjust to new Gnulib bootstrap post imports
* bootstrap.conf (bootstrap_post_import_hook): New function,
replacing the old inline code.  Remove unnecessary gettext comments.
2024-08-28 23:13:44 -07:00
Paul Eggert
99c0c0b7b8 maint: remove generated file lib/Makefile.am 2024-08-28 23:13:44 -07:00
Paul Eggert
1c087d6fcb Rely on Gnulib inttypes module
* bootstrap.conf (gnulib_modules): Add inttypes.  Remove size_max.
* configure.ac: Do not call gl_SIZE_MAX.
* src/common.h: Include inttypes.h unconditionally.
2024-08-28 23:13:44 -07:00
Paul Eggert
7214f8d44b Update main locals more consistently
* src/patch.c (main): Be a bit more disciplined about updating
local vars.  No need to set outfd = -1 if outstate.ofp is
non-null, since it must be -1 in that case.
2024-08-28 23:13:44 -07:00
Paul Eggert
6785b2c42c Use struct outfile * in function args
* src/patch.c (output_file_later, output_file_now, output_file)
(remove_if_needed):
* src/pch.c (do_ed_script):
* src/util.c (move_file, make_tempfile):
Accept struct outfile * instead of one or two args.
All callers changed.
* src/pch.c (pch_name): Return char *, not char const *.
2024-08-28 23:13:44 -07:00
Paul Eggert
72d7ed09bc Refactor temp names into struct
* src/common.h (struct outfile): New type.
* src/patch.c (tmped, tmpin, tmpout, tmppat, tmppat): New vars,
using this type.  They replace TMPEDNAME, TMPEDNAME_needs_removal,
TMPINNAME, TMPINNAME_needs_removal, TMPOUTNAME,
TMPOUTNAME_needs_removal, TMPPATNAME, TMPPATNAME_needs_removal,
TMPREJNAME, TMPREJNAME_needs_removal.  All uses changed.
(tmprej): Now static.
* util.c (make_tempfile): First arg is now char **,
not char const **.  All callers changed.
2024-08-28 23:13:44 -07:00
Paul Eggert
abf6fb176b Simplify by using Gnulib sigaction
* bootstrap.conf (gnulib_modules): Add raise, sigaction, signal-h,
sigprocmask.  Remove signal.
* configure.ac: Do not check for raise, sigaction, sigprocmask,
sigsetmask.
* src/patch.c (main): Do not block signals during dry runs; there's
no need.
* src/util.c (SIGCHLD, raise, sigset_t, sigemptyset, sigmask)
(sigaddset, sigismember, sigprocmask, sigblock, sigsetmask):
Remove substitutes; not needed now that we have Gnulib.
(sigs): Don’t worry about whether SIGHUP and SIGPIPE are present.
(NUM_SIGS): Now a constant, not a macro.
(signals_to_block): Remove.  All uses changed to fatal_act.sa_mask.
(fatal_exit_handler) [!HAVE_SIGACTION]: Remove.  All uses removed.
(init_signals): Rename from set_signals.  All uses changed.
Only do the true part; the false part is now done by unblock_signals.
(block_signals): Rename from ignore_signals, since it now blocks
instead of ignoring on all platforms.  All uses changed.
(init_signals, block_signals): Simplify by assuming
HAVE_SIGACTION, HAVE_SIGPROCMASK, HAVE_SIGSETMASK.
(setup_handler): Remove macro.
(unblock_signals): New function.
2024-08-25 18:14:30 -07:00
Paul Eggert
d3816ac315 Avoid unnecessary freeing in output_files
If we’re about to exit, calling ‘free’ just slows us down
and is more likely to trigger a bug somewhere.
* src/patch.c (FREE_BEFORE_EXIT): Now a boolean, not
defined-or-not-defined.  All uses changed.
(output_files): New arg EXITING.  All uses changed.
2024-08-25 18:14:30 -07:00
Paul Eggert
346d3aca37 Clean up cleanup
* src/patch.c (cleanup): Do not call output_files,
since this function can be called from a signal handler
and output_files is not async-signal-safe.  All callers changed.
No need for the ‘already_cleaning_up’ static.
2024-08-25 18:14:30 -07:00
Paul Eggert
ff2317b2cb Port better to GNU/Hurd
It lacks PATH_MAX, so don’t use PATH_MAX.
* bootstrap.conf (gnulib_modules): Add stdckdint.
* src/util.c: Include stdckdint.h.  Omit duplicate stdarg.h include.
(move_file, copy_file): Don’t limit symlink contents to PATH_MAX.
Check for symlink or file contents that unexpectedly grew.
(copy_file): New arg FROMST.  All callers changed.
2024-08-25 18:14:30 -07:00
Paul Eggert
c2d9792e92 Don’t say empty backups are unreadable
* patch.man: Remove text that became obsolete in 2011.
2024-08-25 18:14:30 -07:00
Paul Eggert
8c27a03b2e Spelling fixes 2024-08-25 18:14:30 -07:00
Paul Eggert
d46d729c0c Change manywarnings usage to be more like coreutils
* configure.ac: Treat --enable-gcc-warnings more like coreutils does.
This mostly just migrates coreutils changes into this file.
2024-08-25 18:14:30 -07:00
Paul Eggert
924698bfd6 Pacify clang, which dislikes n + "y"
* src/merge.c (merge_hunk):
* src/patch.c (main): Do not add an integer to a string literal,
as Clang unhelpfully warns that you’re using C, not C++.
2024-08-25 18:14:30 -07:00
Paul Eggert
8939519c06 Pacify -Wstrict-overflow in pch.c
* src/pch.c (fetchmode): Avoid undefined behavior in the unlikely
event that str happens to be next to the end of memory.
2024-08-25 18:14:30 -07:00
Paul Eggert
531cc2b9c6 Pacify -Wsuggest-attribute=format in util.c
* src/util.c (copy_attr_error): Mark with printf attribute.
(copy_attr): Ignore -Wsuggest-attribute=format.
2024-08-25 18:14:30 -07:00
Paul Eggert
ff13fea205 Port to non-VLA C compilers
The C standard does not require support for VLAs.
* src/util.c (cwd_is_root): Don’t use VLA.
2024-08-25 18:14:30 -07:00
Paul Eggert
3d5c0d1fd9 Rename vars to pacify gcc -Wshadow
* src/patch.c (noreverse_flag, reverse_flag, patchbuf, patchbufsize):
Rename from noreverse, reverse, buf, bufsize.
All uses changed.
* src/pch.c (do_ed_script): Rename locals.
2024-08-25 18:14:30 -07:00
Paul Eggert
56788ce462 Stop including stdbool.h
With current Gnulib it’s not needed.
* src/common.h, src/list.h, src/safe.h: Don’t include stdbool.h
2024-08-25 18:14:30 -07:00
Paul Eggert
c10da772ef Recommend 64-bit time_t on 32-bit platforms
* bootstrap.conf (gnulib_modules): Add year2038-recommended.
2024-08-25 18:14:30 -07:00
Paul Eggert
1e217677df Remove pch_sha1
* src/pch.c (pch_sha1): Remove; unused.
2024-08-25 18:14:30 -07:00
Paul Eggert
39005cfce9 Move skip_spaces
* src/pch.c (skip_spaces): Move here ...
* src/util.h: ... from here, since it is used only in pch.c.
No need for it to be declared inline.
2024-08-25 18:14:30 -07:00
Paul Eggert
755712d85e Remove pch_timestamp function
* src/pch.h (pch_timestamp): Remove.  All uses removed.
It wasn’t worth the aggravation to keep it.
2024-08-25 18:14:30 -07:00
Paul Eggert
04f0eeb438 Prefer extern inline to static inline for list.h
* src/list.h: Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
(LIST_INLINE): New macro, if not already defined.
(INIT_LIST_HEAD, list_add, list_del, list_del_init, list_empty)
(list_entry): Now LIST_INLINE, not static inline.
* src/safe.c (LIST_INLINE): New macro.
2024-08-25 18:14:30 -07:00
Paul Eggert
f06c1230d7 maint: pacify gcc 14 -Wcast-align
* src/list.h (list_entry): Now a 2-arg function rather than
a 3-arg macro.  All uses changed.
2024-08-25 18:14:30 -07:00
Paul Eggert
aab6e7bc8a maint: pacify -Wanalyzer-null-argument
* src/pch.c (do_ed_script): Simplify slightly to pacify
GCC 14 -Wanalyzer-null-argument.
2024-08-25 18:14:30 -07:00
Paul Eggert
d1d32c9747 maint: work around GCC bug 109839
* src/patch.c, src/pch.c: Ignore -Wanalyzer-fd-leak.
2024-08-25 18:14:30 -07:00
Paul Eggert
7575694ee8 maint: pacify gcc -Wmissing-variable-declarations
* src/common.h, src/inp.c, src/inp.h, src/merge.c, src/patch.c:
* src/pch.c, src/pch.h, src/safe.c, src/util.c, src/util.h:
* src/version.c:
Stop using XTERN, as that trick doesn’t work with gcc
-Wmissing-variable-declarations.  Instead, use the vanilla
approach of extern declarations in .h files, and definitions
without ‘extern’ in .c files.
2024-08-25 18:14:30 -07:00
Paul Eggert
8f78b098c2 maint: pacify gcc -Winline
* configure.ac (nw): Add -Winline.
2024-08-25 18:14:30 -07:00
Paul Eggert
bb841fd7b0 maint: port _FORTIFY_SOURCE to Ubuntu
* configure.ac (_FORTIFY_SOURCE): Define only if not already defined,
so as to not collide with the builtin definition on Ubuntu 24.04 LTS.
2024-08-25 18:14:30 -07:00
Paul Eggert
4887683ab0 maint: assume STDC_HEADERS
We don’t need to worry about pre-C89 any more.
* src/common.h (CTYPE_DOMAIN, ISSPACE): Remove.
All uses of ISSPACE replaced by isspace.
(errno): Remove decl.
2024-08-25 18:14:30 -07:00
Paul Eggert
5b8ecde1a2 maint: spruce up our .m4 files a bit
* m4/setmode.m4 (AC_FUNC_SETMODE_DOS):
Use AC_CHECK_HEADERS_ONCE instead of AC_CHECK_HEADERS.
* m4/xattr.m4: Bump serial.
2024-08-25 18:14:30 -07:00
Paul Eggert
009a424a74 maint: omit obsolete macro calls
* configure.ac: Remove gl_USE_SYSTEM_EXTENSIONS.
It is no longer needed, since Gnulib does this for us.
2024-08-25 18:14:30 -07:00
Paul Eggert
299167f059 maint: simplify .gitignore
* .gitignore: Update for current Gnulib.
Merge m4/.gitignore, tests/.gitignore into this.
* m4/.gitignore, tests/.gitignore: Remove.
2024-08-25 18:14:30 -07:00
Paul Eggert
3ec44a42c4 build: update gnulib submodule to latest 2024-08-25 18:14:30 -07:00
Andreas Gruenbacher
68cb5293f7 build: update gnulib submodule to latest
* bootstrap, bootstrap.conf: Update.
* configure.ac: Remove obsolete AC_PROG_CC_STDC macro (AC_PROG_CC is
already present). Remove obsolescent AC_HEADER_STDC macro.
* m4/xattr.m4: Replace obsolete AC_HELP_STRING by AS_HELP_STRING.
* m4/setmode.m4: Replace obsolete AC_TRY_LINK by AC_LINK_IFELSE.
* Makefile.am (EXTRA_DIST): Add missing m4/gnulib-cache.m4.
* lib/Makefile.am: Regenerate.
2024-08-23 22:37:40 +02:00
Collin Funk
f144b35425 build: Enable the 'subdir-objects' Automake option.
* configure.ac (AM_INIT_AUTOMAKE): Add 'subdir-objects'.
* src/safe.c (remove_cached_dirfd): Use hash_remove instead of the
deprecated hash_delete.
2024-03-02 00:17:51 +01:00
Collin Funk
faafc79f8d build: update gnulib submodule to latest
The current version of gnulib causes build failures which are fixed by
the following commit:
<https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=8002ca7b56acb46b42eeac4a343e112a8ee283cf>
* src/pch.c (do_ed_script): Update arguments to gnulib's execute
function to match the addition of the directory argument. No
functional changes.
2024-03-02 00:17:51 +01:00
Takashi Iwai
c835ecc67b Pass the correct stat to backup files
The last case to call output_file() in the main loop is
    output_file (outname, NULL, &tmpoutst, NULL, NULL,
                 file_type | 0, backup);
and this essentially means to create a backup file (where to=NULL)
only if backup=true, and does nothing else.

And, in the current code, the passed file stat (&tmpoutst) is a file
stat of the temporary file that has been processed, not the original
file (outname) to be backed up.  When the backup is performed
immediately, this is no big problem.  However, output_file() may
schedule the deferred handling, and the given file may be backed up at
a later point.  The problem is that create_backup() tries to avoid the
backup of the same file twice, and it checks the given stat i-node
number in the hash list.  Since it's a stat of a temporary file, the
same i-node number may be reused once a temp file is deleted and
another is created.  This results in a false-positive detection of the
already existing file, eventually missing a backup file.

This patch attempts to address the issue:
- Modify the condition for better understanding, clearly indicating
  that the code there is for creating a backup file
- Pass the stat of the original file instead of a temporary file

BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1198106
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jean Delvare <jdelvare@suse.de>
2022-05-10 10:53:04 +02:00
Paul Eggert
24f81beb27 maint: modernize README-{hacking,prereq} 2021-10-30 16:33:05 -07:00
Kerin Millar
7623b2dc0d Fix test for presence of BASH_LINENO[0]
eval is not some sort of magical sandbox for executing code that might cause
the shell's parser to take exception. Render the test resilient by carrying
it out within a subshell. While at it, position the redirection so that
STDERR is, in fact, muted.

Signed-off-by: Kerin Millar <kfm@plushkava.net>
Reported-by: Paolo Pedroni <paolo.pedroni@iol.it>
Closes: https://bugs.gentoo.org/738810
2021-01-08 10:15:31 +01:00
Andreas Gruenbacher
0993940034 gnulib: update to latest
* bootstrap: Update.
* bootstrap.conf (gnulib_modules): Replace getdate with parse-datetime, malloc
with malloc-gnu, and realloc with realloc-gnu.
* src/patch.c (main): Function find_backup_file_name has gained a new dir_fd
argument.
* src/util.c (create_backup): Likewise.
(fetchname): Function get_date has been renamed to parse_datetime.
2020-05-14 14:01:13 +02:00
Andreas Gruenbacher
78ed9decdf Add missing-section tests to context-format test case
* tests/context-format: Add tests with a missing pattern and a missing
replacement section in a hunk.  Patch should fill in the missing
sections from the existing sections.
2019-12-24 00:26:49 +01:00
Andreas Gruenbacher
76e775847f Fix failed assertion 'outstate->after_newline'
The assertion triggers when the -o FILE option is used, more than one output
file is written into FILE, and one of those files (except the last one) ends in
the middle of a line.
* src/patch.c (main): Fix the case described above.
2019-07-16 01:16:28 +02:00
Andreas Gruenbacher
15b158db3a Avoid invalid memory access in context format diffs
* src/pch.c (another_hunk): Avoid invalid memory access in context format
diffs.
2019-07-15 19:53:50 +02:00
Andreas Gruenbacher
dce4683cbb Don't follow symlinks unless --follow-symlinks is given
* src/inp.c (plan_a, plan_b), src/util.c (copy_to_fd, copy_file,
append_to_file): Unless the --follow-symlinks option is given, open files with
the O_NOFOLLOW flag to avoid following symlinks.  So far, we were only doing
that consistently for input files.
* src/util.c (create_backup): When creating empty backup files, (re)create them
with O_CREAT | O_EXCL to avoid following symlinks in that case as well.
2019-07-15 19:53:27 +02:00
Andreas Gruenbacher
61d7788b83 Don't crash when RLIMIT_NOFILE is set to RLIM_INFINITY
* src/safe.c (min_cached_fds): Define minimum number of cached dir file
descriptors.
(max_cached_fds): Change type to rlim_t to allow storing RLIM_INFINITY.
(init_dirfd_cache): Set max_cached_fds to RLIM_INFINITY when RLIMIT_NOFILE is
RLIM_INFINITY.  Set the initial hash table size to min_cached_fds, independent
of RLIMIT_NOFILE: patches commonly only affect one or a few files, so a small
hash table will usually suffice; if needed, the hash table will grow.
(insert_cached_dirfd): Don't shrink the cache when max_cached_fds is
RLIM_INFINITY.
2019-06-28 11:20:31 +02:00
Andreas Gruenbacher
b7b028a77b Abort when cleaning up fails
When a fatal error triggers during cleanup, another attempt will be made to
clean up, which will likely lead to the same fatal error.  So instead, bail out
when that happens.
src/patch.c (cleanup): Bail out when called recursively.
(main): There is no need to call output_files() before cleanup() as cleanup()
already does that.
2019-06-28 00:46:06 +02:00
Andreas Gruenbacher
a5b442ce01 Skip "ed" test when the ed utility is not installed
* tests/ed-style: Require ed.
2019-06-27 11:09:31 +02:00
Andreas Gruenbacher
2b584aec9e Improve support for memory leak detection
When building with the address sanitizer on, free some more resources before
exiting.  (This is unnecessary when not looking for memory leaks.)
* src/patch.c (init_files_to_delete): Add dispose function for freeing
filenames.
2019-06-27 11:07:01 +02:00
Andreas Gruenbacher
9c986353e4 Fix swapping fake lines in pch_swap
* src/pch.c (pch_swap): Fix swapping p_bfake and p_efake when there is a
blank line in the middle of a context-diff hunk: that empty line stays
in the middle of the hunk and isn't swapped.

Fixes: https://savannah.gnu.org/bugs/index.php?53133
2018-08-17 16:27:11 +02:00
Andreas Gruenbacher
ff81775f4e Make the (debug & 2) output more useful
* src/pch.c (another_hunk): In the (debug & 2) output, fix how empty
lines that are not part of the patch context are printed.  Also, add
newlines to lines that are missing them to keep the output readable.
2018-08-17 13:13:54 +02:00
Jean Delvare
369dcccdfa Don't leak temporary file on failed multi-file ed-style patch
The previous fix worked fine with single-file ed-style patches, but
would still leak temporary files in the case of multi-file ed-style
patch. Fix that case as well, and extend the test case to check for
it.

* src/patch.c (main): Unlink TMPEDNAME if needed before moving to
  the next file in a patch.

This closes bug #53820:
https://savannah.gnu.org/bugs/index.php?53820

Fixes: 123eaff0d5d1 ("Fix arbitrary command execution in ed-style patches (CVE-2018-1000156)")
Fixes: 19599883ffb6 ("Don't leak temporary file on failed ed-style patch")
2018-05-07 15:15:33 +02:00
Jean Delvare
19599883ff Don't leak temporary file on failed ed-style patch
Now that we write ed-style patches to a temporary file before we
apply them, we need to ensure that the temporary file is removed
before we leave, even on fatal error.

* src/pch.c (do_ed_script): Use global TMPEDNAME instead of local
  tmpname. Don't unlink the file directly, instead tag it for removal
  at exit time.
* src/patch.c (cleanup): Unlink TMPEDNAME at exit.

This closes bug #53820:
https://savannah.gnu.org/bugs/index.php?53820

Fixes: 123eaff0d5d1 ("Fix arbitrary command execution in ed-style patches (CVE-2018-1000156)")
2018-05-03 14:34:48 +02:00
Bruno Haible
f322a7e0e5 Request 'alloca' module from gnulib.
* bootstrap.conf (gnulib_modules): Add 'alloca'.
2018-04-07 16:41:14 +02:00
Bruno Haible
458ac51a05 Fix 'ed-style' test failure.
* tests/ed-style: Remove '?' line from expected output.
2018-04-07 16:41:14 +02:00
Bruno Haible
1e9104c180 Fix check of return value of fwrite().
* src/patch.c (copy_till): Consider incomplete fwrite() write as an error.
* src/pch.c (pch_write_line, do_ed_script): Likewise.
2018-04-07 16:41:14 +02:00
Jim Meyering
ae81be0024 maint: avoid warnings from GCC8
Hi Andreas,

I configured with --enable-gcc-warnings and bleeding-edge gcc
(version 8.0.1 20180406) and hit some warning-escalated-to-errors.
This fixes them:

>From a71ddb200dbe7ac0f9258796b5a51979b2740e88 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Fri, 6 Apr 2018 16:47:00 -0700
Subject: [PATCH] maint: avoid warnings from GCC8

* src/common.h (FALLTHROUGH): Define.
* src/patch.c (abort_hunk_context): Use FALLTHROUGH macro in place of
a comment.  This avoids a warning from -Wimplicit-fallthrough=.
* src/pch.c (do_ed_script): Add otherwise unnecessary initialization
to avoid warning from -Wmaybe-uninitialized.
(another_hunk): Use FALLTHROUGH macro here, too, twice.
2018-04-07 09:58:05 +02:00
Andreas Gruenbacher
2a32bf09f5 Minor cleanups in do_ed_script
* src/pch.c (do_ed_script): Minor cleanups.
2018-04-06 21:29:56 +02:00
Andreas Gruenbacher
ff1d3a67da Use gnulib execute module
* bootstrap.conf (gnulib_modules): Add execute.
* src/pch.c (do_ed_script): Switch from fork + execlp to execute.
2018-04-06 21:29:19 +02:00
Andreas Gruenbacher
3fcd042d26 Invoke ed directly instead of using the shell
* src/pch.c (do_ed_script): Invoke ed directly instead of using a shell
command to avoid quoting vulnerabilities.
2018-04-06 20:50:06 +02:00
Andreas Gruenbacher
123eaff0d5 Fix arbitrary command execution in ed-style patches (CVE-2018-1000156)
* src/pch.c (do_ed_script): Write ed script to a temporary file instead
of piping it to ed: this will cause ed to abort on invalid commands
instead of rejecting them and carrying on.
* tests/ed-style: New test case.
* tests/Makefile.am (TESTS): Add test case.
2018-04-06 12:23:02 +02:00
Andreas Gruenbacher
b5a91a01e5 Allow input files to be missing for ed-style patches
* src/pch.c (do_ed_script): Allow input files to be missing so that new
files will be created as with non-ed-style patches.
2018-04-06 12:23:02 +02:00
Andreas Gruenbacher
f290f48a62 Fix segfault with mangled rename patch
http://savannah.gnu.org/bugs/?53132
* src/pch.c (intuit_diff_type): Ensure that two filenames are specified
for renames and copies (fix the existing check).
2018-02-12 16:48:24 +01:00
Andreas Gruenbacher
074e2395f8 Test suite: fix Korn shell incompatibility
tests/merge: In a Korn shell, shift apparently fails when $# is 0.
2018-02-07 17:05:00 +01:00
Andreas Gruenbacher
f6bc5b14bd Test suite compatibility fixes
* tests/crlf-handling, tests/git-cleanup, tests/test-lib.sh: Use printf
instead of echo -e / echo -n for compatibility with systems that don't
support these echo options.
* tests/merge: Minor other cleanups.
2018-02-07 13:19:24 +01:00
Andreas Gruenbacher
3bbebbb29f Avoid set_file_attributes sign conversion warnings
* src/util.c (set_file_attributes): Avoid sign conversion warnings when
assigning -1 to uid_t / gid_t.
2018-02-07 12:01:22 +01:00
Andreas Gruenbacher
40b387de08 Version 2.7.6
* NEWS: Update.
2018-02-03 19:43:57 +01:00
Andreas Gruenbacher
66f9fa2690 Fix typo in README
* README: Fix typo.
2018-02-03 19:43:57 +01:00
Andreas Gruenbacher
107e1cecfc Switch to gnupload module
* bootstrap.conf: use gnupload module.
* (RELEASE_TYPE): Define, as maint.mk expects it to be defined.
(tell-upload): Remove obsolete target.
2018-02-03 14:46:17 +01:00
Andreas Gruenbacher
e6da0b81bf Remove stale reference to m4/utimbuf.m4
* Makefile.am (EXTRA_DIST): Remove stale reference to m4/utimbuf.m4.
2018-02-03 14:44:53 +01:00
Andreas Gruenbacher
9ab866d562 maint: update bootstrap and gnulib submodule
* bootstrap: Update from gnulib.
2018-02-03 13:26:55 +01:00
Andreas Gruenbacher
6a737fca57 Clarify the error messages for malformed normal diff patches
* src/pch.c (another_hunk): Clarify the error messages for malformed
normal diff patches.
2018-01-23 11:01:47 +01:00
Thomas Orgis
592e1f9163 Create git diff files with indicated mode
* src/patch.c (main): Create git diff files with indicated mode.
* tests/file-create-modes: New test case.
* tests/Makefile.am (TESTS): Add test case.

This fixes building current Linux 4.14.x from the signed tarball and
patch file, where the patch creates a script with the executable bit
set.
2018-01-23 10:56:27 +01:00
Andreas Gruenbacher
15cc7d44d4 gnulib: update to latest 2018-01-23 10:41:04 +01:00
Bruno Haible
5bf48c87ca Don't use an undocumented Autoconf macro
* configure.ac: Use AC_CONFIG_HEADERS instead of AC_CONFIG_HEADER.
2018-01-23 10:40:56 +01:00
Andreas Gruenbacher
00947f4111 Don't allow hunks to overlap
* src/patch.c (locate_hunk): Don't allow a hunk to overlap with the
previous one.
* tests/false-match: Add regression test.
2017-09-06 18:35:44 +02:00
Andreas Gruenbacher
61b6ec8857 patch.man: Clarify --forward description 2017-09-06 17:57:29 +02:00
Andreas Gruenbacher
a2b6fb1672 gnulib: update to latest 2017-09-04 13:56:25 +02:00
Tim Waugh
817d7d1767 Rename canonicalize global variable
* src/common.h, src/merge.c (context_matches_file), src/patch.c
(get_some_switches, patch_match), src/pch.c(another_hunk): Rename the
global variable 'canonicalize' to 'canonicalize_ws'.

Patch uses a global variable 'canonicalize' as part of its
implementation of the --ignore-whitespace flag.

In glibc there is a function canonicalize():
https://www.gnu.org/software/libc/manual/html_node/FP-Bit-Twiddling.html#index-canonicalize

Rename the global variable so that it will not conflict.

Original bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=1422463
2017-02-22 11:03:43 +01:00
Hanno Boeck
49705d1d8d Add a missing NULL check in parse_name
* src/util.c (parse_name): parse_c_string() can fail and return NULL.
Check for that so that we won't access the NULL pointer here.
2016-08-10 09:25:29 +02:00
Hanno Boeck
a0d7fe4589 Fix out-of-bounds access to lines in a patch
This bug can trigger with malformed patches.
* src/pch.c (pch_write_line): Avoid out-of-bounds access to
p_line[line][p_len[line] - 1] when p_len[line] is 0.
2016-08-10 00:13:25 +02:00
Jim Meyering
4c43a0b1cb tests: use $PATCH rather than hard-coded path
* tests/git-cleanup: Don't hard-code program name.
2016-07-31 10:17:52 +02:00
Jim Meyering
d874c38335 maint: placate a "make syntax-check" rule
* src/pch.c (set_hunkmax): Don't cast return value of xmalloc.
(grow_hunkmax): Likewise for two uses of realloc that the syntax-check
rule did not detect.
2016-07-31 10:17:52 +02:00
Jim Meyering
b6c4780f73 maint: avoid new warning-errors from gcc-6.1
When configured with --enable-gcc-warnings and gcc-6.1, ...
* src/safe.c (count_path_components): Use _GL_ATTRIBUTE_PURE,
to avoid an error from -Werror=suggest-attribute=pure.
* src/util.h (filename_is_safe): Likewise.
* src/patch.c (main): Placate -Werror=format= by casting
pch_mode's mode_t return type to the "unsigned int" required
to match the %o format string.
* src/patch.c (delete_files): Correct indentation, to avoid
this error from -Werror=misleading-indentation:

  patch.c: In function 'delete_files':
  patch.c:1816:4: error: this 'if' clause does not guard...
      if (verbosity == VERBOSE)
      ^~
  patch.c:1820:6: note: ...this statement, but the latter is
    misleadingly indented as if it is guarded by the 'if'
	move_file (0, 0, 0, file_to_delete->name, mode,
	^~~~~~~~~
2016-07-31 10:17:52 +02:00
Jim Meyering
9ca38fa1e6 gnulib: update to latest 2016-07-31 10:17:52 +02:00
Andreas Gruenbacher
66fdcf0e7c Fix broken git-style patch behavior
When a git-syle patch is applied, all file modifications are done to
temporary files which are put in place when the patch ends.  When a
patch fails, GNU patch was trying to "roll back" to the start.  A bug in
that code that lead to accidental file deletion was recently discovered
by Richard Weinberger <richard@nod.at>.  Even worse though, GNU patch
should not exhibit this "rollback" behavior in the first place; that's
not what people expect. Instead, the files modified so far should be put
in place.
* src/patch.c (cleanup): Put output files processed successfully
in place instead of trying to "roll back" to the start.
(forget_output_files): Remove obsolete (and broken) function.
* tests/git-cleanup: New broken git-style patch test case that exercises
the cleanup path.
* tests/Makefile.am (TESTS): Add new test case.
2016-07-27 15:47:47 +02:00
Andreas Gruenbacher
83a3ed012c Fix inname test case
* src/safe.h (unsafe): New flag to allow turning off safe file
operations.
* src/safe.c (safe_xstat, safe_open, safe_rename, safe_mkdir,
safe_rmdir, safe_unlink, safe_symlink, safe_chmod, safe_lchown,
safe_lutimens, safe_readlink, safe_access): When safe file operations
are turned off, skip safe path traversal.  Any symlink checks of the
last path component are still done though.
* src/patch.c (main): When the file to patch is specified on the command
line, turn off safe file operations.
* tests/inname: Fix typo in test.
2016-07-27 15:47:47 +02:00
Andreas Gruenbacher
70532e21a8 Add context-format test to XFAIL_TESTS for now
* tests/Makefile.am (XFAIL_TESTS): Add context-format test until someone
gets to fixing it.
2016-07-27 10:58:03 +02:00
Andreas Gruenbacher
4f4fd1b41d Add broken context-format test cases
* tests/context-format: Add context-format test cases from
Mattias Andrée <maandree@member.fsf.org> that patch doesn't parse
correctly.
2016-03-18 10:12:31 +01:00
Andreas Gruenbacher
3270d221a9 Don't use a zero-size array in struct symlink
* src/safe.c (struct symlink): Get rid of the zero-size array which is a gcc
extension.
(read_symlink): Adapt to this struct symlink change.
2015-10-03 15:25:49 +02:00
Andreas Gruenbacher
98b86e970a Input file outside current directory: add test case
Patch currently makes sure that input / output files are inside the current
working directory even when the input files are explicitly specified on the
command line (see http://savannah.gnu.org/bugs/?45581).
* tests/inname: Add a test case for this bug.
2015-07-20 11:18:12 +02:00
Tobias Stoeckmann
68049159f2 Terminate readlink string
The function readlink does not nul terminate its result string.  safe_readlink
is a wrapper for readlinkat, which has the same behaviour.
* src/util.c (copy_file): Therefore, explicitly set '\0' and reserve one byte
for it.  (agruen: Reserve PATH_MAX + 1 bytes instead of only reading PATH_MAX -
1 characters.)
2015-07-12 15:38:23 +02:00
Tobias Stoeckmann
871f87824a Use xmalloc in bestmatch
* src/bestmatch.h (bestmatch): Use xmalloc instead of malloc to handle
out-of-memory situations.
2015-07-08 20:55:51 +02:00
Andreas Gruenbacher
5c6625bf62 Don't require traditional patch header after "git --diff"
Reported by Tim Waugh <twaugh@redhat.com>.
* src/pch.c (intuit_diff_type): Don't require a traditional patch header
("--- old\n+++ new/n") after a "git --diff" header; the "git --diff" header
gives us enough information for being able to process subsequent hunks.  This
deals with corrupted patches more gracefully.
* tests/corrupt-patch: New test case.
* tests/Makefile.am (TESTS): Add test case.
2015-03-09 15:29:15 -04:00
Andreas Gruenbacher
6a55099e7a Use gnulib size_max module
* bootstrap.conf (gnulib_modules): Add size_max.
* configure.ac: Call gl_SIZE_MAX.
2015-03-08 14:55:48 -04:00
Andreas Gruenbacher
3b698ab6a1 Version 2.7.5
* NEWS: Update.
2015-03-07 01:32:27 +01:00
Andreas Gruenbacher
3cd040cf4c build: update gnulib submodule to latest 2015-03-07 01:32:21 +01:00
Andreas Gruenbacher
7a77ae9f81 Allow absolute symlinks that lead back into the working directory
* src/safe.c (cwd_stat_errno, cwd_stat): stat() result of ".".
(read_symlink): When a symlink is absolute, check if it leads back into the
working directory.  If it does, strip off the prefix above the working
directory. If the symlink points to the working directory, return an empty
path.
(traverse_another_path): Recognize empty paths from read_symlink().
* tests/symlinks: Absolute symlink test cases.
2015-03-07 01:23:29 +01:00
Andreas Gruenbacher
274c66c775 Describe better how the dirfd cache works 2015-03-05 23:14:57 +01:00
Andreas Gruenbacher
99d3b514e9 Use overflow safe arithmetic for counting cache misses
* src/safe.c: We don't need a long counter if we use overflow-safe arithmetic
here.
2015-03-05 23:14:25 +01:00
Andreas Gruenbacher
a6615bcb83 Also cache resolved symlinks
When resolving a symlink in a pathname, we traverse each path component in the
symlink and cache all of them.  At the end, add an additional cache entry for
the symlink itself so that we don't have to resolve the symlink again (even
though this will usually be cached).  Skip that if the symlink's parent isn't
in the cache anymore, though.
* src/safe.c (free_cached_dirfd): Remove from parent here instead of in
callers. Move close() to remove_cached_dirfd() instead.
(insert_cached_dirfd): Only insert if the entry's parent still exists; entries
without parent are invalid (see compare_cached_dirfds()); "top-level" entries
have cwd as their parent.
(new_cached_dirfd): New function split off from openat_cached().
(openat_cached): Use new_cached_dirfd() here.
(traverse_another_path): When starting to resolve a symlink, create an unhashed
dirfd cache entry for the symlink lookup result. When the symlink is completely
resolved, add that entry to the cache.
2015-03-05 22:57:44 +01:00
Andreas Gruenbacher
914d06b7c3 Invalidate child dirfd cache entries when their parent goes away
If we don't do that, a directory could be removed from the cache, a new
directory with the same dirfd could be created, and the entries from the old
directory would appear in the new directory.
* src/safe.c (struct cached_dirfd): Keep track of the children of each dirfd
cache entry.
(remove_cached_dirfd): Remove all the entry's children from the lookup hash,
take them off the list of children, and initialize the children's
children_link.  Then, remove the entry itself from its parent. This has no
effect if the entry doesn't have a parent because then, children_link is empty.
(openat_cached): Add new dirfd cache entries to their parent's list of children
and initialize the entry's list of children.
(traverse_another_path): Also initialize cwd's list of children.
2015-03-05 22:57:44 +01:00
Andreas Gruenbacher
c5705fd476 Convert lru list into a list_head list
* src/safe.c (struct cached_dirfd): Replace prev and next with a lru_link
list_head.
(lru_list): Turn into a list_head.
(lru_list_add, lru_list_del, lru_list_del_init): Replace by list_add(),
list_del(), list_del_init().
(insert_cached_dirfd): Get to the list entry from the embedded list_head with
the list_entry() macro.
2015-03-05 22:57:42 +01:00
Andreas Gruenbacher
ca9df22fe6 Add list_head based double linked list
* src/list.h: New data structure.
src/Makefile.am (patch_SOURCES): Add list.h.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
0d3df382d6 Invalidate dirfd less aggressively
src/safe.c (safe_rename, safe_rmdir): Only invalidate cache entries when the
underlying sycall succeeds and the entry actually goes away.  This keeps the
cache filled upon speculative rmdir when the directory may not be empty, for
example.
2015-03-05 22:57:07 +01:00
Tim Waugh
9f92e52c9f Add more path traversal test cases
* tests/symlinks: Add more path traversal test cases.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
6fbdcefe7d Move path traversal error reporting into main()
* src/safe.c (traverse_another_path): Don't report errors here.
* src/patch.c (main): Instead, recognize and report them here. Detect when an
output file name is invalid; it doesn't make sense to try creating a
reject file based on the same outbut file name in that case.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
a025a51ca5 Limit the number of path components
src/safe.c (MAX_PATH_COMPONENTS): The maximum number of path components
allowed.
(count_path_components): New function.
(traverse_another_path): Fail if the number of path components gets too high.
2015-03-05 22:57:07 +01:00
Andreas Gruenbacher
ef609c26b2 Follow directory symlinks within the working directory
* src/safe.c (struct symlink): A symlink to resolve.
(push_symlink, pop_symlink): New functions.
(read_symlink): Create a new symlink stack entry.
(traverse_next): Follow ".." components within the working directory. When
hitting symlinks, "follow" them by reading and returning them.
(traverse_another_path): Recursively traverse symlinks.
2015-03-05 22:57:04 +01:00
Andreas Gruenbacher
3c58eb50ce Keep track of the directory hierarchy
* src/safe.c (struct cached_dirfd): Add parent pointer. Now that we know our
parent, we no longer need to duplicate its directory file descriptor.
(lookup_cached_dirfd): Don't update the lru list here.
(insert_cached_dirfd): The lru list may now be empty even if the cache is not.
(put_path): New function to put a path back into the lru list.
(openat_cached): Take cached entried off the lru list.  They are added back
in put_path().
(traverse_another_path): Put lookup result back into the lru list with
put_path().
2015-03-05 21:49:55 +01:00
Andreas Gruenbacher
e1f0aa0a9d Refactor traverse_another_path() and helpers
Prepare for keeping track of the directory hierarchy:
* src/safe.c (traverse_another_path): Pass struct cached_dirfd to
traverse_next().
(traverse_next, openat_cached): Pass through struct cached_dirfd.
2015-02-28 21:10:34 +01:00
Andreas Gruenbacher
c5da382c0b Move error reporting out of make_tempfile()
* src/util.c (make_tempfile): Remove error reporting here.
* src/inp.c (plan_b): Readd error reporting here.
* src/patch.c (main): Likewise.
* src/pch.c (open_patch_file): Likewise.
2015-02-28 21:10:34 +01:00
Andreas Gruenbacher
d55ab5b941 Minor cosmetic changes
* src/safe.c: Minor cosmetic changes
2015-02-28 21:10:22 +01:00
Andreas Gruenbacher
db9f39507e Fix handling of renamed files
When a file has already been renamed, make sure it is not renamed back to its
old name.  Reported by Guido Draheim.
* src/patch.c (main): Make sure we never rename a file back to its previous
name. Report when a file was renamed already.
* tests/copy-rename: Add "already renamed" test cases.
2015-02-22 18:50:16 +01:00
Andreas Gruenbacher
8d12036047 Fix symlinks test case on some architectures
* src/safe.c: Include util.h for say(). Define EFTYPE if it isn't defined
already.
(traverse_another_path): When openat fails, also check for EMLINK, EFTYPE, and
ENOTDIR. Change the error message to "file ... is not a directory" and only
skip the rest of the patch instead of aborting.
* tests/symlinks: Update.
2015-02-10 22:31:56 +01:00
Andreas Gruenbacher
7297352e16 Test suite portability fixes
Reported and fixed (mostly) by Christian Weisgerber <naddy@mips.inka.de>:
* tests/deep-directories: Avoid the bash >& redirection operator.
* tests/no-mode-change-git-diff: Instead of "stat -c", use "ls -l  sed".
* tests/read-only-files: A redirection failure for a special built-in causes
some shells (FreeBSD sh, OpenBSD sh (pdksh), some bash --posix) to exit, and
the colon command is a special built-in. Perform the redirection in a subshell.
2015-02-04 10:54:03 +01:00
Andreas Gruenbacher
69434de2d5 Switch from gen_tempname() to try_tempname()
* Update gnulib submodule to latest.
* src/util.c (try_safe_open_args, try_safe_open): Arguments and callback for
try_tempname().
(make_tempfile): Switch from gen_tempname() to try_tempname().
2015-02-04 10:53:56 +01:00
Andreas Gruenbacher
ddf16e1209 Check the result of the --follow-symlinks option
* tests/symlinks: Check the result of treating a symlink as a file with
--follow-symlinks.
2015-02-02 15:43:56 +01:00
Andreas Gruenbacher
8a9f5432d4 Link patch with LIB_EACCESS where needed
* src/Makefile.am (patch_LDADD): Add LIB_EACCESS here. At least on Solaris,
faccessat() is implemented through eaccess() which is in the "gen" library.
2015-02-01 17:09:59 +01:00
Andreas Gruenbacher
b73c1f95cb Fix minor signedness warning
* src/pch.c (intuit_diff_type): Don't assign signed dummy value to unsigned
variable.
2015-02-01 15:47:16 +01:00
Andreas Gruenbacher
709458d9d9 Use gnulib faccessat module
* bootstrap.conf (gnulib_modules): Add faccessat.
2015-02-01 15:45:24 +01:00
Andreas Gruenbacher
de89dde09e Upate NEWS 2015-01-31 22:14:01 +01:00
Andreas Gruenbacher
38d87ecb9e Fix indentation heuristic for context diffs
Diffs can be indented by a variable number of spaces, tabs, or X characters.
Make sure that intuit_diff_type() only accepts context diffs where the first
and second line are indented identically, or else another_hunk() will fail.
* src/pch.c (intuit_diff_type): Remember the indentation of the last line. Only
recognize context diff hunks with the same amount of indentation on the first
and second line.
* tests/garbage: New test case.
* tests/Makefile.am (TESTS): Add test case.
2015-01-31 22:14:01 +01:00
Quentin Casasnovas
82b800c955 patch: git-diff mode: do not change permissions if there isn't an explicit mode change.
Signed-off-by: Quentin Casasnovas <quentin.casasnovas@oracle.com>
2015-01-31 22:14:01 +01:00
Quentin Casasnovas
68d39ff29f tests: add a test case for unwanted mode changes.
Signed-off-by: Quentin Casasnovas <quentin.casasnovas@oracle.com>
2015-01-31 22:14:01 +01:00
Quentin Casasnovas
c80b1a06a9 test-lib.sh: factorize require_* functions
Since the code is identical when just checking if a utility is present on
the system or not, we can factorize it.

Signed-off-by: Quentin Casasnovas <quentin.casasnovas@oracle.com>
2015-01-31 22:14:01 +01:00
Andreas Gruenbacher
8d621e8819 Add test case for patch behind symlink
* tests/symlinks: Add a test case where the patch file itself is in a path that
follows a symbolic link; we want to continue allowing that.
2015-01-31 22:14:01 +01:00
Tim Waugh
290ffcb488 Allow arbitrary symlink targets again
* src/util.c (symlink_target_is_valid): Remove.
(move_file): Remove symlink target checking.
* tests/symlinks: Update test case.
2015-01-31 22:14:01 +01:00
Andreas Gruenbacher
b72e3be5c8 Update list of gnulib modules used
* bootstrap.conf (gnulib_modules): Remove lchmod, lstat, mkdir, readlink,
rename, mkdir, symlink, unlink, utimens. Add fchownat, fchmodat, fstatat,
mkdirat, openat, readlinkat, renameat, symlinkat, unlinkat, utimensat.
* src/util.h: Don't include <utimens.h> anymore.
2015-01-31 22:14:01 +01:00
Andreas Gruenbacher
71a3172c7e Use symlink-safe system call replacements
Use the symlink-safe replacements for system calls in many places throughout
the code: In some places this makes patch safe against path traversal attacks;
in other places, it saves the kernel from having to re-traverse the pathnames.
* src/inp.c (plan_b): Use safe_open() + fdopen() instead of fopen().
* src/util.c (copy_attr): Document why we are safe here.
(create_backup): Use safe_open() instead of creat().
2015-01-31 22:14:00 +01:00
Tim Waugh
025a54b789 Add symlink-safe system call replacements
Add wrappers around system calls that traverse relative pathnames without
following symlinks. Written by Tim Waugh <twaugh@redhat.com> and Andreas
Gruenbacher <agruenba@redhat.com>.
* src/safe.h: Declare functions here.
* src/safe.c: Implement safe_* system call replacements that do not follow
symlinks along pathnames. Pathname components are resolved with openat().
Lookup results are cached to keep the overhead reasonably low.
* tests/deep-directories: New path traversal cache test.
* src/Makefile.am (patch_SOURCES): Add safe.[ch].
* tests/Makefile.am (TESTS): Add new test.
2015-01-31 22:13:44 +01:00
Andreas Gruenbacher
6a56d401d2 build: update gnulib submodule to latest 2015-01-31 18:25:15 +01:00
Tim Waugh
75fcb4b560 Avoid closing file descriptor twice
* src/patch.c (main): Make sure we don't close() outfd after passing it on to
fdopen(): the file descriptor might have been reused in the meantime.
2015-01-31 18:25:12 +01:00
Andreas Gruenbacher
3e7113a6b5 Remove unused variable
* src/pch.c (name_is_valid): Remove unused variable.
2015-01-29 19:31:53 +01:00
Andreas Gruenbacher
41688ad8ef Fix the fix for CVE-2015-1196
* src/util.c (filename_is_safe): New function split off from name_is_valid().
(symlink_target_is_valid): Explain why we cannot have absolute symlinks or
symlinks with ".." components for now.
(move_file): Move absolute filename check here and explain.
* tests/symlinks: Put test case with ".." symlink in comments for now.
* NEWS: Add CVE number.
2015-01-22 21:51:51 +01:00
Andreas Gruenbacher
17953b5893 For renames and copies, make sure that both file names are valid
* src/patch.c (main): Allow there_is_another_patch() to set the
skip_rest_of_patch flag.
* src/pch.c (intuit_diff_type): For renames and copies, also check the "other"
file name.
(pch_copy, pch_rename): Now that both names are checked in intuit_diff_type(),
we know they are defined here.
2015-01-21 16:32:41 +01:00
Andreas Gruenbacher
0c08d7a902 Fail when out of memory in set_hunkmax()
src/pch.c (another_hunk): Call set_hunkmax() from here to make sure it is
called even when falling back from plan A to plan B.
(open_patch_file): No need to call set_hunkmax() anymore.
src/pch.c (set_hunkmax): Fail when out of memory. Make static.
src/pch.h: Remove set_hunkmax() prototype.
2015-01-20 12:43:57 +01:00
Andreas Gruenbacher
19285e563a Don't try applying hunks at offsets that can't work
* src/patch.c (locate_hunk): Start trying to apply the hunk at the minimum
offset which puts the hunk in the valid range of lines. This will often still
be offset 0.
2015-01-20 12:00:24 +01:00
Andreas Gruenbacher
ae88d1c270 Move symlink_target_is_valid() and cwd_is_root()
* src/util.c: Move symlink_target_is_valid() and cwd_is_root() here from
src/pch.c.
2015-01-20 10:10:10 +01:00
Andreas Gruenbacher
4e9269a5fc Make sure symlinks don't point outside working directory (CVE-2015-119)
When creating symlinks from git-style patches, make sure the symlinks don't
point above the current working directory.  Otherwise, a subsequent patch could
use the symlink to write outside the working directory.

* src/pch.c (symlink_target_is_valid): New function to check for valid symlink
targets.
* src/util.c (move_file): Use symlink_target_is_valid() here.
* tests/symlinks: Add valid and invalid symlink test cases.
2015-01-19 23:18:30 +01:00
Andreas Gruenbacher
44a987e02f Add line number overflow checking
* bootstrap.conf: use intprops module.
* src/common.h: Define LINENUM_MIN and LINENUM_MAX macros.
* src/pch.c (another_hunk): Add line number overflow checking.  Based on Robert
C. Seacord's INT32-C document for integer overflow checking and Tobias
Stoeckmann's "integer overflows and oob memory access" patch for FreeBSD.
2014-11-30 20:56:46 +01:00
Andreas Gruenbacher
f22e47d873 More savebuf/savestr error handling
* bootstrap.conf: use xmemdup0 module.
* src/pch.c (there_is_another_patch): Use xmemdup0 instead of savebuf when we
cannot recover from out-of-memory situations.
(intuit_diff_type): Likewise, use xstrdup instead of savestr.
(another_hunk): Handle the case when savestr returns NULL.
* src/util.c (fetchname, parse_name): Use xmemdup0 instead of savebuf when we
cannot recover from out-of-memory situations.

Bugs pointed out by Tobias Stoeckmann <tobias@stoeckmann.org>.
2014-11-30 15:52:42 +01:00
Tobias Stoeckmann
e4c6511f46 savebuf/savestr error handling
* src/patch.c (get_some_switches): The function savebuf (and therefore savestr)
copies strings using malloc.  If malloc fails, NULL is returned.  This is
intentional behavior so that in case of failure during "plan a" patching, "plan
b" can step in.  The return value has to be properly checked for NULL.  If the
return value must not be NULL, use xstrdup instead.
2014-11-30 15:35:44 +01:00
Andreas Gruenbacher
3fd4144ae9 build: update gnulib submodule to latest
* src/merge.c (compute_changes): The TOO_EXPENSIVE heuristic in diffseq has
been removed, including compareseq's find_minimal parameter and the context's
too_expensive limit.  Adjust.
2014-11-30 15:35:31 +01:00
Jean Delvare
65193f1cc1 Drop useless test in another_hunk()
src/pch.c (another_hunk): This test will always succeed.
2014-11-10 11:43:36 +01:00
Tobias Stoeckmann
e25e622dec Buffer overflow on malicious input file
There is a hard to reach but possible buffer overflow when using
patch with a very large (modified) input file.  I doubt you will ever
see this with a 64 bit system, but it's possible with 32 bit:

$ echo hello > file1
$ echo world > file2
$ diff -Nau file1 file2 > file.diff

Nothing fancy so far.  Adjust file1 so it contains at least one line that
is 2 GB in size.  Larger is fine too, but stay below 4 GB.

$ tr '\0' c < /dev/zero | dd bs=1K count=2097152 of=file1

Now try to patch it.

$ patch -Np0 -i file.diff
Segmentation fault

The issue is in patch's "plan b" strategy  (If your system would still
want to use "plan a", force patch to use "plan b" through debug flag).

Plan b writes lines into a temporary file, with equally long lines, so
it can use a buffer mechanism to access them in a kind of randomly
fassion.  In order to do that, it retrieves the longest line.

In this example, it will encounter the 2 GB line and stores that as the
longest one.  Afterwards it will adjust the tibufsize variable to be
large enough:

  for (tibufsize = TIBUFSIZE_MINIMUM;  tibufsize < maxlen;  tibufsize <<= 1)
    /* do nothing */ ;

Due to maxlen's size (2 GB), tibufsize will be SIZE_T_MAX, i.e. 4 GB.
A few lines later it allocates space for the tibuf buffers:

  tibuf[0] = xmalloc (2 * tibufsize);
  tibuf[1] = tibuf[0] + tibufsize;

This will allocate 0 bytes because tibufsize overflowed.  The next
time patch writes into the buffer, a segmentation fault will occur...
Depends on your system how long it takes until that happens. ;)

The fix is simple:  Bail out on lines that are too long.  Patch already
does that for files that have too many lines.
2014-10-30 22:47:40 +01:00
Andreas Gruenbacher
f926295f4f Improve error message when refusing to delete file
* src/patch.c: Improve error message.
* tests/create-delete: Update the test case.
2014-08-13 01:16:44 +02:00
Andreas Gruenbacher
dc63883f08 Correct the --help text of option --merge
* src/patch.c (option_help): The --merge option does not have a short
form; update the help text.
2013-12-09 09:26:16 +01:00
Steven Rostedt
a2f4bfe0f3 Preserve function names in reject files
* src/patch.c (main): Preserve function names in reject files.
* tests/reject-format: Update the test case.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andreas Gruenbacher <agruen@linbit.com>
2013-08-19 22:44:46 +02:00
Andreas Gruenbacher
89dbba7229 Test case for the dry-run fix
* tests/create-directory: Add test case here.
2013-07-30 15:28:25 +02:00
Andreas Gruenbacher
afdfa9ec8e In dry-run mode, create temporary files in a temporary directory
* src/util.c (make_tempfile): Do not create temporary files in the final output
directory when in dry-run mode: the path may be read-only.  In addition, we do
not want to leave intermediary empty output directories around.
2013-07-30 12:52:42 +02:00
Eric S. Raymond
aac14e3187 Fix some formatting problems in the manpage
* patch.1: Use higher-level markup that translates better into HTML and other
formats.  (With changes by Andreas Gruenbacher.)
2013-06-18 09:48:32 +02:00
Stefano Lattarini
60c9d4838f build: don't use -Werror in AM_INIT_AUTOMAKE
Doing so prevents bootstrapping with bleeding-edge autotools,
because of harmless deprecation warnings (that are not planned
to become hard errors for at least a few years to come).  And
unfortunately, options in AM_INIT_AUTOMAKE take precedence over
those given on the command line (this is a long-time wart of
automake).

* configure.ac (AM_INIT_AUTOMAKE): Drop '-Werror' option.

Copyright-paperwork-exempt: yes
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
2013-05-02 06:03:31 +02:00
Andreas Gruenbacher
2f40ef66be Fix removing empty directories
Reported by Thomas Moschny <thomas.moschny@gmx.de>:
src/patch.c (main): Temporary output files are created in the same directory as
the output file.  Make sure to remove them before removing empty files and
their empty ancestor directories; else the directories won't be empty.
tests/remove-directories: Add directory removal test case.
tests/Makefile.am (TESTS): Add new test case.
2013-03-10 19:02:54 +01:00
Andreas Gruenbacher
082baa326a Clarify the description of option --forward
* patch.man: Clarify the description of option --forward.
2013-01-03 22:19:20 +01:00
Andreas Gruenbacher
291ec17581 Initialize data structures early enough
* src/patch.c (main): Initialize data structures early enough, before error
paths can access them.
* tests/bad-usage: Test bad command line usage.
* tests/Makefile.am (TESTS): Add bad-usage here.
2012-10-04 12:43:05 +02:00
Andreas Gruenbacher
47191c287d Don't fail test suite if printf '\0' is broken
* tests/create-delete: Skip binary diff test if printf '\0' is broken.
2012-09-30 13:06:35 +02:00
Andreas Gruenbacher
bbb840edca Version 2.7.1 2012-09-28 18:39:33 +02:00
Andreas Gruenbacher
6214f5e222 build: update gnulib submodule to latest 2012-09-28 18:39:33 +02:00
Andreas Gruenbacher
fc5ddce20e Repair 'backup of unmodified file' test
tests/create-delete: Repair 'backup of unmodified file' test.
2012-09-28 18:39:33 +02:00
Andreas Gruenbacher
ac59899327 Use gnulib errno module instead of our own default ENOTSUP fallback
* bootstrap.conf (gnulib_modules): Add errno module.
* src/common.h: Remove ENOTSUP fallback.
2012-09-28 16:00:04 +02:00
Andreas Gruenbacher
c9de555284 Trailing whitespace fix
* NEWS: Trailing whitespace fix.
2012-09-28 12:43:42 +02:00
Andreas Gruenbacher
e8bfce6547 Improve the previous commit
* src/patch.c: Only print the "file is not empty after patch" message when
trying to delete the output file.  Say that we were trying to delete the file.
* tests/create-delete: Fix the expected messages.  Add test cases for the
--remove-empty-files and --posix options.
* NEWS: Better describe this change.
2012-09-26 01:33:22 +02:00
Andreas Gruenbacher
1d9ed51e9c Only expect files to become empty if the patch says so
Test cases based on patches from Dmitry V. Levin <ldv@altlinux.org>.
* src/patch.c (main): Only expect files to become empty if the patch says so.
* NEWS: Document this change.
* tests/create-delete: Add (more) empty vs. non-empty test cases.
2012-09-25 04:07:53 +02:00
Jim Meyering
b272c2d535 build: avoid gcc warnings from -Wsuggest-attribute=format
* configure.ac (WARN_CFLAGS): Disable -Wsuggest-attribute=format,
to avoid some warnings that are not worth working around.
2012-09-22 21:35:04 +02:00
Andreas Gruenbacher
89e5f702eb Update NEWS
* NEWS: Update.
2012-09-22 20:34:53 +02:00
Andreas Gruenbacher
3ccb16e10b Improve messages when in --dry-run mode
* src/patch.c (main): Say that we are checking a file and not that we are
patching it in --dry-run mode.  Don't say "saving rejects to file" when we
don't create reject files.
* tests/reject-format: Add rejects with --dry-run test case.
* tests/bad-filenames, tests/fifo, tests/mixed-patch-types: Update.
2012-09-22 20:10:53 +02:00
Andreas Gruenbacher
db1bd7f693 Improve handling of LF vs. CRLF line endings
* src/patch.c (check_line_endings): New function.
(main): When a hunk fails, report when the line endings differ between the
input file and the patch.
* src/pch.c (there_is_another_patch): When saying that we strip trailing CRs,
also say how to turn this off.
* tests/crlf-handling: Update changed messages.  Add test case that fails.
2012-09-22 20:02:48 +02:00
Andreas Gruenbacher
d24f630fbc Ignore when preserving extended attributes is not supported or allowed
* src/common.h (ENOTSUP): Make sure this error code is defined.
* src/util.c (set_file_attributes): Ignore ENOSYS, ENOTSUP, and EPERM errors.
2012-09-22 18:32:10 +02:00
Andreas Gruenbacher
1d9d403394 Add a missing explanation in the tests/crlf-handling test case
* tests/crlf-handling: Add explanation.
2012-09-20 04:34:40 +02:00
Andreas Gruenbacher
293415dbcf Add --follow-symlinks option for backwards compatibility
* src/common.h (follow_symlinks): New variable.
* src/patch.c (longopts): Add new --follow-symlinks option.
(get_some_switches): Recognize the new option.
* src/util.c (stat_file): Follow symlinks if requested.
* patch.man: Document the new option.
* tests/symlinks: Add test case.
2012-09-19 03:16:07 +02:00
Andreas Gruenbacher
59609b50c5 Introduce function to lstat all input files
* src/util.c (stat_file): New function.
(move_file): Use here.
* src/util.h (stat_file): Declare here.
* src/inp.c (get_input_file): Use here.
* src/patch.c (main): Use here.
(delete_file_later): Use here.
* src/pch.c (there_is_another_patch): Use here.
(intuit_diff_type): Use here.
2012-09-19 03:07:31 +02:00
Andreas Gruenbacher
b578985c3c Use stat where we want to follow symlinks
* src/pch.c (prefix_components): Follow symlinks.
(cwd_is_root): Follow symlinks.
2012-09-19 02:51:23 +02:00
Andreas Gruenbacher
3b934d6903 Document command-line options in alphabetic order
* patch.man: The options are mostly listen in alphabetical order; stick to
that.
2012-09-19 02:51:23 +02:00
Andreas Gruenbacher
99f2638763 Fix file truncation when switching from git diff to non-git diff
* src/patch.c (main): Output queued output files only when switching from a git
diff to a non-git diff.  This can modify the input file, so make sure to
stat() it again.
* tests/concat-git-diff: Add test case growing a file with a git diff and then
with a non-git diff; without this fix; the result would be truncated.
2012-09-18 12:53:38 +02:00
Andreas Gruenbacher
0f22a35cec Rename get_input_file() parameter to clarify code
* src/inp.c (get_input_file): Rename mode parameter to file_type, it's all we
care about here.
2012-09-18 00:48:01 +02:00
Andreas Gruenbacher
4c7c0976ac Improve error message when patching a file of different type
* src/inp.c (get_input_file): Improve error message when patching a file of
different type.
* tests/symlinks: Update test case.
2012-09-18 00:48:01 +02:00
Andreas Gruenbacher
95f6823325 Minor test case updates
* tests/dash-o-append: Minor update (still expected to fail).
* tests/symlinks: Minor update.
2012-09-18 00:47:30 +02:00
Andreas Gruenbacher
1ea53aae17 Disable xattrs if libattr doesn't implement attr_copy_action()
* m4/xattr.m4 (gl_FUNC_XATTR): Only enable USE_XATTR if both attr_copy_file()
and attr_copy_action() are defined.
* src/util.c (copy_attr_check): No fallback needed if attr_copy_action() is not
defined.
2012-09-17 17:04:20 +02:00
Andreas Gruenbacher
20c9d7d5ab Allow to use potentially dangerous filenames from the root directory
* src/pch.c (cwd_is_root): New function to check if we are in the root
directory of a filename.
(name_is_valid): Allow to use potentially dangerous filenames when the current
working directory is the root directory: from there, those names are not
any more dangerous than other names.
* tests/bad-filenames: New test case.
2012-09-17 15:48:06 +02:00
Andreas Gruenbacher
2b2fb1f36c Update leftover license notice in README
* README: Change leftover GPLv2 license notice to GPLv3.
2012-09-14 11:39:09 +02:00
Andreas Gruenbacher
543906f1a4 Check if libattr implements attr_copy_action()
* m4/xattr.m4 (gl_FUNC_XATTR): Check if attr_copy_action() is defined.
* src/util.c: If attr_copy_action() doesn't exist, fall back to the default
copy_attr_file() behavior of copying most extended attributes except ACLs.
2012-09-14 11:39:02 +02:00
Andreas Gruenbacher
f0388d2dbf Change the type of *_needs_removal from int to bool 2012-09-13 16:34:58 +02:00
Andreas Gruenbacher
281537bcd9 In a git-style diff, make sure not to unlink the original by accident
* src/patch.c (main): Fail if a file is not empty as expected.
(output_files): In a git-style diff, make sure not to unlink the original when
making a backup of an unmodified file.
* tests/create-delete: Fix failed-file-deletion test and add
successful-file-deletion test.
2012-09-13 16:32:53 +02:00
Andreas Gruenbacher
dc3cdeebca Do not pass file type in mode of open(..., O_CREAT, mode)
* src/patch.c (main): Strip file type off of create mode for temporary output
files: some systems don't ignore the file type; we want to create a regular
file even when patching a symlink.
2012-09-13 16:31:25 +02:00
Andreas Gruenbacher
474bb7d333 Add note on GPLv3 license change in version 2.6
* NEWS: Add note.
2012-09-13 14:38:38 +02:00
Andreas Gruenbacher
58ec5b5643 Version 2.7
* NEWS: Update.
2012-09-12 11:35:43 +02:00
Andreas Gruenbacher
e4b9ff4cfe maint: update gnulib submodule 2012-09-12 11:35:03 +02:00
Andreas Gruenbacher
66aeedee12 Support double-quoted filenames in all context diff formats
* src/util.c (fetchname): Always recognize double-quoted filenames.
* src/util.h (fetchname): Update prototype.
* src/pch.c (intuit_diff_type): Update calls to fetchname().
* tests/quoted-filenames: Change to a normal unified diff.
* NEWS: Update.
2012-08-11 11:09:11 +02:00
Andreas Gruenbacher
9a37354cc6 Remove SHA1 hashes from the file id cache
* src/util.c (file_id): Remove sha1 field.
(update_sha1, lookup_sha1): Remove functions.
* src/util.h (update_sha1, lookup_sha1): Remove declarations.
2012-08-08 13:39:19 +02:00
Andreas Gruenbacher
a18960d31e Detect concatenated git-style patches by tracking what's in the output queue
* src/patch.c (main): Instead of looking at the SHA hashes to detect
concatenated git-style patches, detect when a file to write to is already in
the output queue.
* tests/concat-git-diff: Add create/delete tests.
2012-08-08 13:39:08 +02:00
Andreas Gruenbacher
e294241b86 In the file id cache, allow to flag files in the output queue
* src/util.c (file_id): Add queued_output field.
(__insert_file_id): Initialize queued_output.
(set_queued_output, has_queued_output): New functions.
* src/util.h (set_queued_output, has_queued_output): Declare.
2012-08-08 13:10:41 +02:00
Dmitry V. Levin
3980c923dc Add another git-style diff concatenation regression test
* tests/concat-git-diff: Add test case here.
2012-08-08 13:02:31 +02:00
Andreas Gruenbacher
a3f2ca32c3 maint: ignore more build artifacts 2012-08-08 01:41:42 +02:00
Andreas Gruenbacher
81d006fe4b Change outst variable name to tmpoutst to be less misleading
* src/patch.c (main): Rename outst to tmpoutst.
2012-08-07 22:38:32 +02:00
Andreas Gruenbacher
1e6c0d07ab In git-style diffs, create new files immediatetly and only remember files to modify
* src/patch.c (output_file): Create new files immediately.  Document why
things are implemented that way.
* tests/concat-git-diff: Fix glitch in test case.
2012-08-02 20:38:31 +02:00
Jim Meyering
cdc94fade3 Don't close a negative file descriptor
* src/inp.c (re_input): Don't close FD if it's negative.
2012-08-01 15:51:54 +02:00
Andreas Gruenbacher
120927804d Add file create test case which still needs to be fixed
* tests/concat-git-diff: Add file create test case.
2012-08-01 15:10:22 +02:00
Jim Meyering
46e58be9cc build: remove unnecessary if-before-free
* src/util.c (update_sha1): Remove unnecessary if-before-free,
to avoid "make syntax-check" failure.
2012-08-01 15:05:42 +02:00
Jim Meyering
1118f832ef build: mark an internal function as "pure"
* src/pch.c (sha1_says_nonexistent): Apply _GL_ATTRIBUTE_PURE,
to avoid failure with -Werror=suggest-attribute=pure.
2012-08-01 15:05:42 +02:00
Andreas Gruenbacher
386ae15bce maint: update bootstrap and gnulib submodule
* bootstrap: Update from gnulib.
2012-08-01 04:50:00 +02:00
Andreas Gruenbacher
6be1a126bd Try to recognize concatenated git diffs and handle them appropriately
* src/patch.c (main): Remember the "before" SHA1 hashes of git-style patches;
the same patch will always use the same "before" SHA1 for a specific file.
Try to recognize concatenated patches based on that.
* tests/concat-git-diff: New test case.
* tests/Makefile.am (TESTS): Add new test case.
2012-08-01 04:28:07 +02:00
Andreas Gruenbacher
57eb3007ab Allow to process only part of the deferred output file list
* src/patch.c (output_files): Add parameter to specify which file to stop at.
(main): Pass NULL to output_files() to process the entire list.
2012-08-01 04:25:16 +02:00
Andreas Gruenbacher
ea4212ee51 Allow to remember SHA1 hashes in the file id cache
* src/util.c (file_id): New sha1 field.
(__insert_file_id): Split off from insert_file_id().  Initialize sha1 field.
(__lookup_file_id): Split off from lookup_file_id().
(update_sha1): Remember SHA1 hash of a file or update the remembered SHA1 hash.
(lookup_sha1): Look up the SHA1 hash of a file.
* src/util.h (update_sha1, lookup_sha1): Declare.
2012-07-31 21:58:30 +02:00
Andreas Gruenbacher
b0c22022be Accessor functions for SHA1 hashes in git-style diffs
* src/pch.c (p_sha1): New variable.
(get_sha1): New function for saving a sha1 checksum.
(sha1_says_nonexistent): Take a NULL terminated string instead of an end
pointer.
(intuit_diff_type): Remember the SHA1 hashes from index headers in git-style
diffs in p_sha1.
(pch_sha1): New function for accessing p_sha1.
* src/pch.h (pch_sha1): Declare.
2012-07-31 21:58:30 +02:00
Andreas Gruenbacher
6e21796422 Add missing "diff --git" index lines
* tests/copy-rename, tests/criss-cross, tests/file-modes,
tests/mixed-patch-types, tests/quoted-filenames: Add missing index lines in the
"dif --git" test cases: We will use some of them for consistency checks soon.
2012-07-31 21:58:24 +02:00
Andreas Gruenbacher
90d4e1f3d5 Fix segfault in output_file_later()
Bug reported by Dmitry V. Levin <ldv@altlinux.org>.
* src/patch.c (output_file_later): Fix case where the output file is identical
with the input file (and to == NULL).
2012-04-24 12:37:26 +02:00
Andreas Gruenbacher
709688a8d9 maint: update bootstrap and gnulib submodule
* bootstrap: Update from gnulib.
2012-04-17 17:17:17 +02:00
Andreas Gruenbacher
e0a7877a6e Update NEWS
* NEWS: Update.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
9a26fde226 Only warn when trying to modify read-only files
Failing when trying to patch read-only files causes various users of patch to
break.  Instead, warn by default and introduce a command line option for
choosing a different behavior.
* patch.man: Describe the new behavior and command-line option.
* src/patch.c (read_only_behavior): New variable.
(main): Implement the new behavior.
(longopts): Add the new --read-only option.
(option_help): Describe the new behavior.
(get_some_switches): Recognize the new --read-only option.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
b9a1ff0cfa Fix "delete file which does not exist" test case
* tests/create-delete: Remove left-over file f.orig before the test.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
c43eeb22a4 For git-style patch files, do not output files immediately
In git-style patch files, all patches refer to the initial state of the input
files; files cannot be modified more than once.  Implement these semantics by
creating all output files once all patches in the patch file have been
processed.
* src/patch.c (init_files_to_output, output_files): Add prototypes.
(main): Remember which type of patch file we are processing.  Initialize the
output files list.  Output files of git-style patches once all patches have
been read, or when from git-style to normal patches.
(file_to_output): New struct.
(files_to_output): List of the files to output.
(output_file, output_file_now, output_file_later): Either queue a file for
deletion, remember to output a file later (git-style), or output the file
immediately (normal).
(dispose_file_to_output, init_files_to_output, output_files,
 forget_output_files): New functions.
(gl_list_clear): Should be provided by gnulib but isn't.
(cleanup): Clean up any left-over temporary output files as well.
* tests/Makefile-am (XFAIL_TESTS): Remove criss-cross; this test case works now.
* tests/mixed-patch-types: Patch files that change from normal to git-style, or
from git-style to normal.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
309ece2e5a Export the patch type
* src/pch.c (p_git_diff): New global variable.
(intuit_diff_type): Use p_git_diff instead of a local variable.
(pch_git_diff): New function.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
5081f42226 Remove invalid symlink test case
* tests/symlinks: Remove test case which deletes and then recreates a symlink:
all patches in a git-style input file must refer to the "before" state; the
test case is invalid.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
9ff0689857 No longer remember backup files
Remembering backup files was needed because we would have lost track of deleted
files before -- but we don't delete files immediately anymore.
* src/util.c (create_backup_copy): No longer remember backup files.
(create_backup): Likewise; update comment.
(move_file): Update create_backup() call.
* src/util.h (create_backup): Update prototype.
* src/patch.c (output_file): Update create_backup() call.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
3b4824fb33 Do not delete files immediately
Fixes the bug that more than one numbered backup would be created when a patch
file deletes and recreates a file.
* bootstrap.conf (gnulib_modules): Add linked-list and xlist modules.
* src/util.h (file_id_type): Add DELETE_LATER and OVERWRITTEN types.
(create_backup, set_file_attributes): Update prototype.
(insert_file_id): Add prototype.
* src/util.c (insert_file_id): Export.
(set_file_attributes, create_backup_copy): Make the st argument const.
(create_backup): Pass in to_st instead of returning it from create_backup().
This obsoletes the to_errno argument.
(move_file): Determine to_st here and pass it to create_backup().  Remember
when a file is overwritten.
* src/patch.c (output_file): Add to_st parameter.  Remember files to delete
instead of deleting them immediately.  Pass from-st to create_backup().
(file_to_delete): New struct.
(init_files_to_delete, delete_file_later, delete_files): New functions.
(main): Use init_files_to_delete() and delete_files().  Pass to_st to
output_file() where we already have it.
* src/pch.c (intuit_diff_type): Assume that files which are marked for deletion
don't exist.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
73184a17e2 Create and delete output files in a single function
* src/patch.c (output_file): New function for creating or deleting an output
file and backing the old file up as needed.
(main): Use the new function.
* src/util.c (move_file): Allow FROM_NEEDS_REMOVAL to be NULL.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
02548c1549 Add a type field to entries in the file id cache
* src/util.h (file_id_type): New enum.
* src/util.c (file_id): Add a file_id_type field.
(insert_file_id): Rename from insert_file(); specify a type when inserting a
file id.
(lookup_file_id): Rename from file_id_exists(); return a file id type.
(create_backup_copy, create_backup, move_file): Use insert_file_id() instead of
insert_file(), and lookup_file_id() instead of file_already_seen().
* src/patch.c (main): Use lookup_file_id() instead of file_already_seen().
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
8de9b7b036 Switch from the `old' gnu quoting style to the 'new' one
* src/common.h, src/patch.c, src/pch.c, src/util.c, src/util.h: Switch from the
`old' gnu quoting style to the 'new' one in messages and comments.
2012-04-17 16:48:19 +02:00
Andreas Gruenbacher
ed081db4b1 Fix use-after-free bug in name_is_valid()
Reported by Steffen Sledz in
https://bugzilla.novell.com/show_bug.cgi?id=755136 via Jean Delvare.
Bug introduced in commit v2.6.1-115-ge0f7075; fixed with help from Jim
Meyering <meyering@redhat.com>.
* src/common.h (ARRAY_SIZE): New macro.
* src/pch.c (invalid_names): New global variable for remembering bad names.
(intuit_diff_type): Reset invalid_names for each new patch; the names from the
previous patch have already been freed.
(name_is_valid): Use invalid_names.  Make the code "safer" and avoid
duplication.
2012-04-06 20:29:47 +02:00
Andreas Gruenbacher
a8699f834b Require automake-1.11.2
* configure.ac (AM_INIT_AUTOMAKE): Require version 1.11.2 which introduced the
AM_PROG_AR macro, used since commit 297f9e7d.
2012-04-06 13:29:46 +02:00
Jim Meyering
f4accb062b build: update gnulib submodule to latest 2012-02-25 20:28:56 +01:00
Jim Meyering
297f9e7dd6 build: update bootstrap from gnulib and adapt
* bootstrap: Update from gnulib.
* bootstrap.conf (gnulib_tool_option_extras): Define.
* lib/Makefile.am: Initialize numerous automake variables so that
generated code in gnulib.mk may use += to append to them.
* configure.ac: Add AM_PROG_AR, to placate newer automake.
2012-02-16 14:36:11 +01:00
Jim Meyering
d0745f417c maint: enable the sc_space_tab syntax-check rule
* cfg.mk (local-checks-to-skip): Remove sc_space_tab,
thus enabling this syntax-check rule.
* tests/quoted-filenames: Use TAB-space, not space-TAB.
2012-01-01 11:26:31 +01:00
Jim Meyering
d504183866 maint: enable the useless_cpp_parens syntax-check rule
* cfg.mk (local-checks-to-skip): Remove sc_useless_cpp_parens,
thus enabling this syntax-check rule.
* src/patch.c: Remove unneeded parentheses.
2012-01-01 11:12:43 +01:00
Jim Meyering
2d38b11799 maint: update all copyright year number ranges
Run "make update-copyright".
2012-01-01 10:26:02 +01:00
Jim Meyering
5cb38ce390 build: update to latest gnulib and adapt
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.
2011-12-14 16:34:45 +01:00
Andreas Gruenbacher
5ca55b8414 Timestamp not set when creating files with --set-time or --set-utc
* 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.
2011-12-09 00:53:38 +01:00
Stefano Lattarini
17086c5cf2 tests: specify test runner in LOG_COMPILER, not in TEST_ENVIRONMENT
* tests/Makefile.am (TESTS_ENVIRONMENT): Don't use $(SHELL) here
to ensure the test scripts are run through it; instead, ...
(LOG_COMPILER): ... use it here.
2011-10-12 00:34:19 +02:00
Jim Meyering
4e595c3b6d give a diagnostic rather than a failed assertion for a mangled patch
* src/pch.c (another_hunk): Rather than asserting(C), issue the
"replacement text or line numbers mangled ..." diagnostic when !C.
* tests/mangled-numbers-abort: New test for the above.
* tests/Makefile.am (TESTS): Add it.
* NEWS: Mention it.
Reported by Gabriel Vlasiu via Tim Waugh.
See also http://bugzilla.redhat.com/738959
2011-10-11 03:31:57 +02:00
Jim Meyering
46ad06707c build: use largefile module and update to latest gnulib
* configure.ac: Remove AC_SYS_LARGEFILE, subsumed by ...
* bootstrap.conf (gnulib_modules): ...this.  Use largefile module.
* gnulib: Update to latest.
This is useful to Mac OS X 10.5 users if/when configure
is generated using autoconf prior to v2.68-80-gdb2f2e0.
2011-08-11 14:18:57 +02:00
Jim Meyering
2231959c18 build: include .version in tarball to avoid distcheck failure
* Makefile.am (EXTRA_DIST): Append .version, to avoid "make distcheck"
failure when run from an unpacked tarball.
Reported by Iain Nicol.
2011-08-11 13:13:22 +02:00
Andreas Gruenbacher
b083f881f1 README: Describe where to go from a "git clone"
* README: Refer users to README-hacking after a "git clone".
2011-08-11 00:05:55 +02:00
Jim Meyering
586239e353 don't call fdopen with a negative FD upon dup failure
* src/patch.c (open_outfile): If dup fails, don't clobber its
errno value by calling fdopen with -1.
2011-05-25 16:47:33 +02:00
Jim Meyering
5853a727de plug a leak in inp.c's plan_a
* src/inp.c (plan_a): Don't leak "buffer" upon early return.
2011-05-25 16:47:33 +02:00
Jim Meyering
0649fbf212 emit one more diagnostic with the required "program_name: " prefix
* src/util.c: Include "error.h".
(ask): Use error, not perror.  The latter would not have included
the usual "program name: " prefix.
2011-05-25 16:47:33 +02:00
Jim Meyering
209af7ee4b remove side effect from assert
* src/util.c (parse_c_string): Don't increment "s" in assert.
2011-05-25 16:47:33 +02:00
Jim Meyering
bb2fef06eb explicitly ignore close return value to placate static analyzers
* 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.
2011-05-25 16:47:33 +02:00
Jim Meyering
6526aec61f plug a leak in fetchname
* src/util.c (fetchname): Don't leak "timestr" when returning early.
2011-05-25 16:47:32 +02:00
Andreas Gruenbacher
b4c6b7086b avoid a used-uninitialized error in fetchname
* 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.
2011-05-25 16:47:00 +02:00
Jim Meyering
5a634c3834 plug a leak in bestmatch
* src/bestmatch.h (bestmatch): Don't leak V when returning early.
2011-05-25 16:20:10 +02:00
Jim Meyering
aa85679b9a maint: ignore more build artifacts 2011-03-27 09:19:55 +02:00
Jim Meyering
c9f9680fd1 build: don't turn off -Wmissing-declarations
* configure.ac (WERROR_CFLAGS): Don't turn off -Wmissing-declarations
and admit that it's not worth fixing the few warnings triggered
by -Wmissing-format-attribute.
2011-03-27 09:19:55 +02:00
Jim Meyering
d08c6262c7 build: don't turn off -Wmissing-prototypes
* configure.ac (WERROR_CFLAGS): Don't turn off -Wmissing-prototypes.
* src/pch.c (skip_hex_digits): Declare static.
* src/bestmatch.h (bestmatch): Likewise.
2011-03-27 09:19:55 +02:00
Jim Meyering
df2831fbdf maint: remove now-unneeded macro definitions
* 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.
2011-03-27 09:19:46 +02:00
Jim Meyering
8b78759a8b maint: use gnulib's progname module
* src/patch.c (main): Call set_program_name rather than
initializing program_name explicitly.
* src/common.h: Include progname.h rather than declaring the extern,
program_name.
* bootstrap.conf (gnulib_modules): Add progname.
* cfg.mk (local-checks-to-skip): Remove sc_program_name,
thus enabling this test.
2011-03-27 09:16:46 +02:00
Jim Meyering
4a7efc3791 maint: update bootstrap and gnulib submodule
* bootstrap: Update from gnulib.
* cfg.mk (local-checks-to-skip): Remove (thus, enable)
sc_copyright_check, now that the gnulib submodule is up to date.
2011-03-27 09:16:46 +02:00
Jim Meyering
db2fb7cdba maint: update copyright date year ranges to include 2011
* bootstrap.conf (gnulib_modules): Add update-copyright.
Run "make update-copyright".
2011-03-27 09:16:46 +02:00
Jim Meyering
d8fdb88440 build: avoid three gcc warnings
* src/patch.c (mangled_patch): Add "noreturn" attribute.
* src/pch.h (pch_timestamp): Remove ignored "const" attribute.
* src/version.c (XTERN): Remove unused #undef and #define.
2011-03-27 09:16:45 +02:00
Jim Meyering
38cecf52b6 tests: temporarily disable failing syntax-check rules
* cfg.mk (local-checks-to-skip): Define, to skip all of the
currently-failing syntax-check rules.  We'll reenable them
one by one, as problems are addressed.
2011-03-27 09:16:42 +02:00
Jim Meyering
7db2653124 build: accept new configure-time option --enable-gcc-warnings
* configure.ac: Enable many options.
* bootstrap.conf (gnulib_modules): Add manywarnings.
* src/Makefile.am (AM_CFLAGS): Use $(WARN_CFLAGS) and $(WERROR_CFLAGS).
2011-03-26 14:20:28 +01:00
Jim Meyering
2876ed918f maint: avoid non-portable use of test -a
With these changes, "make sc_prohibit_test_minus_ao" almost passes.
Uses of "test -o" remain.
Note: unchecked uses of test -ot/-nt also remain.
* tests/empty-files: Use "test C1 && test C2", not "test C1 -a C2"
* tests/merge: Likewise.
* tests/symlinks: Likewise.
* tests/test-lib.sh: Likewise.
2011-03-26 14:20:28 +01:00
Jim Meyering
02e3376350 maint: allow the sc_prohibit_empty_lines_at_EOF test to pass
* tests/test-lib.sh: Remove empty line at end of file.
2011-03-26 14:20:28 +01:00
Jim Meyering
07d4792620 maint: remove trailing blanks
* bootstrap.conf: Remove trailing blanks.
* tests/reject-format: Define a dummy, empty variable, and use it in
here-doc to protect required trailing blanks from accidental removal.
* tests/no-newline-triggers-assert: Likewise.
* tests/preserve-c-function-names: Likewise.
* tests/create-delete: Likewise.
* tests/global-reject-files: Complete a sentence that ended in a space.
2011-03-26 14:20:28 +01:00
Jim Meyering
8d6290df9f maint: add some m4 quoting
* m4/setmode.m4 (AC_FUNC_SETMODE_DOS): Use proper M4 quoting.
2011-03-26 14:20:28 +01:00
Jim Meyering
f266434caf maint: arrange for the sc_require_config_h_first test to pass
* cfg.mk: New file, to configure maint.mk.
* Makefile.am (EXTRA_DIST): Add, so the new file is distributed.
(config_h_header): Define, to make the sc_require_config_h_first
syntax-check test pass.
* pc/chdirsaf.c: Include <config.h>.
2011-03-26 14:20:28 +01:00
Jim Meyering
94e032f941 maint: use gnulib's maintainer-makefile module
* bootstrap.conf (gnulib_modules): Add maintainer-makefile.
2011-03-26 14:17:36 +01:00
Jim Meyering
7d41c04e7b doc: update README-hacking
* README-hacking: Update from coreutils, including mention of
how to use vc-dwim to git-commit efficiently and safely using
a non-VC'd ChangeLog file.
2011-03-21 18:40:39 +01:00
Jim Meyering
d96503d66a build: update gnulib submodule to latest 2011-03-21 18:26:46 +01:00
Jim Meyering
764d0ea12e do not version-control ChangeLog; instead, generate it from git log
With this change, all ChangeLog entries going forward are generated
into a file named ChangeLog in each distribution tarball.
ChangeLog entries prior to today's date are in ChangeLog-2011.
* Makefile.am (gen-ChangeLog): New rule.
(dist-hook): Depend on it.
(EXTRA_DIST): Add ChangeLog-2011.
* ChangeLog-2011: Renamed from ChangeLog
* ChangeLog: Remove file.
* .gitignore: Ignore ChangeLog.
* bootstrap.conf: Ensure that ChangeLog exists.
(gnulib_modules): Add gitlog-to-changelog.
2011-03-17 11:12:37 +01:00
Jim Meyering
8678ae92ea maint: remove unnecessary tests before free
There is no longer any need to avoid "free(NULL)" (since SunOS 4),
so replace each "if (P) free (P);" with "free (P);".
* src/inp.c (get_input_file): Remove unnecessary test-before-free.
* src/patch.c (get_some_switches): Likewise.
* src/pch.c (intuit_diff_type, pch_swap): Likewise.
2011-02-21 00:29:54 +01:00
Jim Meyering
e0f707523c don't warn twice about the same invalid file name
* src/pch.c (name_is_valid): Don't warn about the same name twice.
* tests/bad-filenames (emit_patch): Exercise the new code.
2011-02-17 10:00:57 +01:00
Andreas Gruenbacher
f663762bf0 Ignore dangerous filenames instead of failing immediately
* 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.
2011-02-16 12:01:19 +01:00
Andreas Gruenbacher
dcfb493578 Fix use of uninitialized outst
* src/patch.c (main): Fix use of initialized outst and add an
additional assert.  Reported by Jim Meyering.
2011-02-15 11:23:44 +01:00
Ozan Çağlayan
3fc5b24073 Create directory test case
* tests/create-delete: New test case creating a file in a new
sub-directory (bug fixed on 2010-12-04).
2011-02-04 00:10:28 +01:00
Andreas Gruenbacher
3c776b0844 Also check if the input file is seekable if a filename is given (-i)
* src/pch.c (open_patch_file): Also check if the input file is
seekable if a filename is given (-i).
* tests/pipe: New file.  Test this.
* tests/Makefile.am (TESTS): Add it.
2011-02-03 23:22:56 +01:00
Jim Meyering
4c3004c17f doc: mention the fix for CVE-2010-4651
* NEWS: Mention the fix.
2011-02-03 23:08:03 +01:00
Jim Meyering
685a78b605 Do not let a malicious patch create files above current directory
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.
2011-02-03 22:00:50 +01:00
Andreas Gruenbacher
7fae6755f4 Create missing parent directories of temporary files
* src/util.c (make_tempfile): Create missing directories when
necessary.
2010-12-04 23:05:00 +01:00
Andreas Gruenbacher
77e15c7286 Fix the USE_XATTR checks
* src/util.c: USE_XATTR is defined to 0 or 1, so we need to use #if
instead of #ifdef.
2010-10-29 14:32:51 +02:00
Andreas Gruenbacher
76d0e43140 Preserve extended attributes of patched files when possible
* 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.
2010-10-27 02:53:42 +02:00
Andreas Gruenbacher
28113637f5 A minor set_file_attributes() cleanup
* src/util.c (set_file_attributes): Always expect the mode
argument to be set when FA_MODE is specified.
(create_backup_copy): Update accordingly.
2010-10-27 02:36:42 +02:00
Andreas Gruenbacher
03f337dabc Remove obsolete checks for mktemp
* configure.ac: Remove obsolete checks for mktemp.
2010-10-26 14:08:50 +02:00
Andreas Gruenbacher
1119764035 Remove obsolete comment
* src/patch.c (print_header_line): Remove obsolete comment.
2010-10-26 14:07:46 +02:00
Andreas Gruenbacher
5b460672d7 Fix the --binary option when used together with --silent
* src/pch.c (there_is_another_patch): Set p_strip_trailing_cr
to false if no_strip_trailing_cr is set independent of the verbosity.
This broke the --binary option in combination with --silent.
2010-10-14 00:11:11 +02:00
Andreas Gruenbacher
3e234c40d2 Only recognize quited filename in the "diff --git" format
* 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.
2010-10-05 19:21:35 +02:00
Andreas Gruenbacher
86e12910c6 Add copy-after-modify test case
* tests/criss-cross: Add copy-after-modify test case.
2010-09-17 13:35:58 +02:00
Andreas Gruenbacher
7e6d1e6718 Document that "diff --git" criss-cross renames don't work
* NEWS: Document that "diff --git" criss-cross renames are broken
still.
* tests/criss-cross: Test case currently expected to fail.
2010-09-17 13:16:08 +02:00
Andreas Gruenbacher
19aecf8108 Fix the "patching file" message for renames and copies
* src/patch.c (main): Generate the "patching file" message here.  When
the input and output file name is not he same, include both names in
the message.
* src/inp.c (scan_input): Previously the "patching file" message was
generated here.
* tests/unmodified-files, tests/copy-rename: Update.
2010-09-17 12:19:43 +02:00
Andreas Gruenbacher
b73bec8e45 Remove double quotearg()
* src/inp.c (scan_input): Remove double quotearg().
2010-09-17 11:04:58 +02:00
Andreas Gruenbacher
fdafb60cc0 Stop using mktemp() for TMPOUTNAME
* src/patch.c (main): Compute TMPOUTNAME with make_tempfile().
(make_temp): Remove obsolete function.
2010-09-17 02:06:25 +02:00
Andreas Gruenbacher
a1a66e6032 Stop using mktemp() for TMPREJNAME
* src/patch.c (main): Compute TMPREJNAME with make_tempfile() only if
needed.
(abort_hunk, init_reject): Pass through the output file name, and base
TMPREJNAME on it.
2010-09-17 02:03:26 +02:00
Andreas Gruenbacher
93129f45a1 Replace unnecessary local variable
* src/patch.c (abort_hunk_unified): Replace unnecessary local variable.
2010-09-17 01:57:22 +02:00
Andreas Gruenbacher
76649aba9e Stop using mktemp() for TMPPATNAME
* src/pch.c (open_patch_file): Compute TMPPATNAME with make_tempfile()
if needed instead of precomputing it in src/patch.c (main).
2010-09-17 01:51:50 +02:00
Andreas Gruenbacher
51147ca57d Stop using mktemp() for TMPINNAME
* src/inp.c (plan_b): Compute TMPINNAME with make_tempfile() if needed
instead of precomputing it in src/patch.c (main).
2010-09-17 01:46:02 +02:00
Andreas Gruenbacher
4b6267d62f Add function make_tempfile()
* bootstrap.conf: Use the gnulib tempname module.
* src/util.c (make_tempfile): New function.
2010-09-17 01:36:53 +02:00
Andreas Gruenbacher
0eef74e981 do_ed_script(): Pass in the filenames to use
* src/pch.c (do_ed_script): Add inname, outname, and
outname_needs_removal arguments.  This isolates TMPOUTNAME and
TMPOUTNAME_needs_removal to patch.c.
* src/patch.c (main): Update do_ed_script() call.
2010-09-17 01:33:45 +02:00
Andreas Gruenbacher
206e87000c Split up init_output()
* src/patch.c (open_outfile): New function.
(init_output): Split into open_outfile() and the rest.
2010-09-17 01:33:42 +02:00
Andreas Gruenbacher
9f1beb577a A lot of years in the ChangeLog are wrong (2009 -> 2010) 2010-09-17 01:32:20 +02:00
Tim Waugh
94d856cfd3 Stop "patch --get 1" from segfaulting
* src/patch.c: Stop "patch --get 1" from segfaulting.
2010-07-27 19:33:01 +02:00
Andreas Gruenbacher
2475341173 Fix read-only file check for ed scripts
* src/patch.c: The read-only file check was not done for ed scripts;
fix this.
2010-05-11 02:08:34 +02:00
Andreas Gruenbacher
423d17d562 test suite: Another Solaris portability fix
* tests/corrupt-reject-files, tests/crlf-handling: On Solaris, cat's
-e option is only effective if -v is specified as well.
2010-05-06 18:48:02 +02:00
Andreas Gruenbacher
d94b00785d test suite: Ignore error messages during cleanup
* tests/test-lib.sh: Ignore error messages when cleaning up after a
test has finished.
2010-05-06 18:44:24 +02:00
Andreas Gruenbacher
7e9296614a test library: Only use GNU diff when available
* tests/test-lib.sh: Only use GNU diff when available.
* tests/dash-o-append: Fix the expected result.
2010-05-05 13:09:18 +02:00
Andreas Gruenbacher
99d75edf46 More test suite fixes
* tests/create-delete: Do not use 'diff' here.
* tests/merge: Require GNU diff.
2010-05-05 12:18:41 +02:00
Andreas Gruenbacher
5b68db86ce Use the gnulib unistd module
* bootstrap.conf: Use the gnulib unistd module.
2010-05-05 01:03:57 +02:00
Andreas Gruenbacher
a78d3c405b Use the gnulib mkdir module
* bootstrap.conf: Use the gnulib mkdir module.
* m4/mkdir.m4: Delete.
2010-05-05 01:00:39 +02:00
Andreas Gruenbacher
ad76f67285 tests/read-only-files: Replace the superuser test
* tests/read-only-files: Remove the superuser test, and instead try
out if a read-only file can be written to.
2010-05-04 22:12:00 +02:00
Andreas Gruenbacher
9dbdc0e748 Create temporary test directories in builddir
* tests/test-lib.sh: Create temporary directories in builddir; this
removes the need to do it safely: some systems do not have mktemp -d.
2010-05-04 21:46:12 +02:00
Andreas Gruenbacher
80cfee88e6 Remove $(TEST_SHELL) and use $(SHELL) instead.
* configure.ac, tests/Makefile: Remove $(TEST_SHELL) and use $(SHELL)
instead.
2010-05-04 18:58:13 +02:00
Andreas Gruenbacher
4ded52f912 Additional minor fixes based on Eric Blake's suggestions
* src/version.c: Put the Free Software Foundation copyright first.
* tests/read-only-files: Skip when run as superuser: even files
without write permissions would be writable.
2010-05-04 18:37:06 +02:00
Eric Blake
bcf08ba042 build: silence some cygwin warnings
* 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>
2010-05-04 18:36:56 +02:00
Andreas Gruenbacher
481768b9d7 Fix backup file detection for deleted files
* 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.
2010-05-04 18:08:53 +02:00
Andreas Gruenbacher
dbb26b7e99 Some test suite fixes and improvements
* tests/test-lib.sh: Flag tests with missing pre-requirements as
SKIPped instead of PASSed.  Do not use GNU diff extensions, but
still require a diff that understands "-u".
* tests: Do not unnecessarily require GNU diff in a lot of tests.
Make the sed utility optional.
2010-05-04 04:07:45 +02:00
Andreas Gruenbacher
1b2ed3de07 Remove left-over debugging code
* src/pch.c (intuit_diff_type): Remove left-over debugging code.
2010-05-04 03:03:23 +02:00
Andreas Gruenbacher
4e1404fe82 Allow to create and delete empty files
* src/pch.c (maybe_reverse): Allow to create and delete empty files.
(sha1_says_nonexistent): New function for recognizing the sha1
checksums of nonexistent and empty files.
(skip_hex_digits): New helper function for skipping [0-9a-z].
(intuit_diff_type): Parse the sha1 checksums in index lines.
* tests/Makefile.am (XFAIL_TESTS): Remove empty-files.
2010-05-04 00:02:03 +02:00
Andreas Gruenbacher
8462be2ed0 Minor cosmetic changes 2010-05-03 22:04:13 +02:00
Andreas Gruenbacher
a93dea1dce Stick to the best name in the reversed-patch check
* src/pch.c (intuit_diff_type): Fix a bug where the reversed-patch
check would wrongly pick the last name instead of the best name.
* src/create-delete: Add test cases for that.
2010-05-03 21:58:40 +02:00
Andreas Gruenbacher
76aa1070c8 Do not try to set file permissions of symlinks
* 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.
2010-05-03 12:20:00 +02:00
Andreas Gruenbacher
0e952c6d34 Improve the symlink backup file tests
* tests/symlinks: Improve the backup file tests.
2010-05-03 11:06:35 +02:00
Andreas Gruenbacher
0403787317 Add two test cases which are currently broken
* Removing an empty file does not work as expected.
* Deleted files are not being remembered correctly.
* Symlinks are not being remembered, either.
2010-05-03 00:15:32 +02:00
Andreas Gruenbacher
0c837fd075 Fix the linker library order
* src/Makefile.am (patch_LDADD): Add $(LIB_CLOCK_GETTIME) here, after
libpatch.a, so that clock_gettime is properly resolved on systems on
which the library order matters.
2010-05-02 15:52:21 +02:00
Andreas Gruenbacher
47622c1e46 * NEWS: Update.
* gnulib: Update to latest.
* bootstrap: Update from gnulib.
2010-05-02 12:43:45 +02:00
Andreas Gruenbacher
cabd1add57 Refuse to patch read-only files
* src/patch.c (main): Refuse to patch read-only files, or at least warn
when patching such files with --force or --batch.
* patch.man: Document the changed behavior.
* tests/read-only-files: Split read-only file test case off from
tests/remember-backup-files.
* tests/Makefile.am: Add new test case.
2010-05-02 12:40:35 +02:00
Andreas Gruenbacher
9e39d9c995 git diffs: Support file copies and renames
* src/patch.c (main): Support git diffs which copy or rename files.
* tests/copy-rename: New test case.
* tests/Makefile.am (TESTS): Add test case.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
502d77b81b Do not modify the string arguments of makedirs and removedirs
* 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.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
5f3b6a06a1 git diffs: Parse copy and rename headers
* 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.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
b68294e3e1 git diffs: Support file mode changes
* 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.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
f9db7450fa git diffs: Support symlinks
* src/patch.c (main): Support git symlink diffs.
* tests/symlinks: Add git symlink diff test cases.
2010-05-02 11:44:00 +02:00
Andreas Gruenbacher
12fdbd5cec Pass up the file type and check for consistent types
* src/pch.c (intuit_diff_type, there_is_another_patch): Pass up the
file type.
* src/patch.c (main): Check for consistent file types.
2010-05-02 11:42:28 +02:00
Andreas Gruenbacher
a41a918fe7 Skip reversed patches check when file types are inconsistent
* src/pch.c (intuit_diff_type): Only check for reversed patches when
the input file type matches the patch file type.
2010-05-02 11:42:28 +02:00
Andreas Gruenbacher
53fdc8e340 git diffs: Parse file modes
* src/pch.c (p_mode): New variable.
(fetchmode, pch_mode): New functions.
(intuit_diff_type): Recognize git diffs which contain no hunks.
Parse and store the file modes in the "index", "old mode",
"new mode", "deleted file mode", and "new file mode" headers.
2010-05-02 11:42:28 +02:00
Andreas Gruenbacher
dc0a3e09a8 Add support for writing symlinks
* 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.
2010-05-02 11:42:24 +02:00
Andreas Gruenbacher
7f35c90cf7 Add support for reading symlinks
* src/inp.c (get_input_file): Add a mode parameter specifying the
input file type (which can be either S_IFREG or S_IFLNK).  The file
type must match this mode parameter; for symbolic links, the --get
option is not supported.
(scan_input): Abort when plan_a() cannot handle a symbolic link.
Say when patching a symbolic link instead of a regular file.
(plan_a): Add support for reading symbolic links.
* src/patch.c: For now, always tell get_input_file() to read regular
files.
* bootstrap.conf: Use the gnulib readlink module.
2010-05-02 11:38:31 +02:00
Andreas Gruenbacher
ba67864c2a Set file attributes only in a single place
* 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.
2010-04-29 02:20:43 +02:00
Andreas Gruenbacher
cd0ea8e786 Remove test which is always true
* src/util.c (move_file): Remove test which is always true.
2010-04-29 02:17:22 +02:00
Andreas Gruenbacher
b610c25e84 Update bootstrap script
* bootstrap: Update from gnulib.
2010-04-27 23:09:13 +02:00
Andreas Gruenbacher
baaa92c25d TESTS_ENVIRONMENT portability fix
* tests/Makefile.am (TESTS_ENVIRONMENT): Portability fix.
2010-04-27 23:07:01 +02:00
Andreas Gruenbacher
444decd3f2 Fix an off-by-one error causing an out-of-bounds array access
* src/bestmatch.h (bestmatch): Fix an off-by-one error causing an
out-of-bounds array access.
2010-04-27 12:38:16 +02:00
Andreas Gruenbacher
cfe068672d Remove leftovers from when patch was still using utimbuf()
* configure.ac (gl_CHECK_TYPE_STRUCT_UTIMBUF), m4/utimbuf.m4: Remove;
utimbuf is no longer used.
2010-04-27 12:38:16 +02:00
Andreas Gruenbacher
9807e6160f Include backupfile.h in util.h
* src/util.h: Include <backupfile.h> here and not in each C file
individually; this avoids a warning in merge.c with some compilers.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
133f2820b3 Do not redefine __attribute__ when it is already defined
* src/common.h: Do not redefine __attribute__ when it is already
defined.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
69f5ebc2d2 Do not use grep -q 2010-04-27 12:38:15 +02:00
Daniel Richard G
7e98397ab2 Portability fixes
* src/common.h (enum diff): Remove the trailing comma.
* src/patch.c (main): Do not use non-constant expressions in an array
initializer.
2010-04-27 12:38:15 +02:00
Daniel Richard G
d7020ed1a9 Portability: do not use variable-length arrays
* src/bestmatch.h: Do not use variable-length arrays.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
e3cfef7f99 Refuse to patch symlinks
* 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.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
f558fff533 Only check for reversed patches when the input file is patchable
* src/pch.c (intuit_diff_type): Only check for reversed patches when
the input file is patchable in the first place.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
3aceaac307 If an input file is not a regular file, only skip the patch
* src/pch.c (get_input_file): If an input file is not a regular file,
only skip the patch instead of aborting.
* src/patch.c (main): If get_input_file() fails, skip the patch.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
a11bfc85e5 Use the gnulib fcntl-h and sys_stat modules
* bootstrap.conf: Use the gnulib fcntl-h and sys_stat modules.
* src/common.h: Remove the declarations provided by gnulib sys_stat.
Always include fcntl.h (and depend on gnulib fcntl-h).
* src/util.h: Remove duplicate include of <timespec.h>.
* configure.ac: Remove obsolete checks for fcntl.h and utime.h.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
37f7c8faec Do not declare variables as "volatile" unnecessarily
* src/common.h, src/patch.c, src/util.c, src/util.h: Do not declare
variables as "volatile" unnecessarily.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
de38f4acfb Do no declare local variables as "register" unnecessarily
* 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.
2010-04-27 12:38:02 +02:00
Andreas Gruenbacher
3288f660a0 Document the recent changes
* patch.man: Describe the fixed behavior of --set-time and --set-utc
for timestamps that include time zones.
* NEWS: Update.
2010-04-23 21:43:45 +02:00
Andreas Gruenbacher
310f4c406a Complain when fed git binary patches
* src/common.h (enum diff): New enumeration GIT_BINARY_DIFF.
* src/pch.c (intuit_diff_type): Recognize git binary patches.
* src/patch.c (main): Complain when fed git binary patches.
* tests/git-binary-diff: New test case.
* tests/Makefile.am (TESTS): Add test case.
2010-04-23 21:43:45 +02:00
Andreas Gruenbacher
30a7405dfb Parse filenames in "diff --git" lines
* 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.
2010-04-23 21:43:40 +02:00
Andreas Gruenbacher
3bccc730eb Fix minor potential memory leaks
* src/pch.c (intuit_diff_type): Make sure we don't leak file names
even when fed weird input.
2010-04-23 09:10:43 +02:00
Andreas Gruenbacher
a64a20d0ab Add support for quoted filenames
* 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.
2010-04-23 09:10:35 +02:00
Andreas Gruenbacher
c4f28f6efb Untangle the name and timestamp parsing
* src/util.c (fetchname): Untangle the name and timestamp parsing.
2010-04-22 19:28:19 +02:00
Andreas Gruenbacher
05400c5689 Strip leading slashes in a separate function
* src/util.c (strip_leading_slashes): Make this a separate function.
(fetchname): Use strip_leading_slashes() here.
2010-04-22 19:04:06 +02:00
Andreas Gruenbacher
d909eee7c9 Support for nanosecond timestamps
* 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.
2010-04-22 01:41:51 +02:00
Andreas Gruenbacher
f81fe080e5 Replace timestamp parsing code with gnulib getdate
* 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.
2010-04-22 01:32:55 +02:00
Andreas Gruenbacher
3693996297 Use struct timespec instead of time_t internally
* 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.
2010-04-22 00:43:29 +02:00
Andreas Gruenbacher
68e9980cce Replace quote_system_arg() with quotearg
* 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.
2010-04-21 23:51:45 +02:00
Andreas Gruenbacher
9486a75e1a Cosmetic fix
* src/util.c (fetchname): Cosmetic fix.
2010-04-21 23:50:49 +02:00
Ludovic Courtès
3b60c20c17 Fix "make dist"
* src/Makefile.am (patch_SOURCES): Remove the obsolete diffseq.h to
fix "make dist".
2010-04-19 23:35:22 +02:00
Andreas Gruenbacher
02ee1d4e01 Globally rename type LINENUM to lin (as in diffutils)
* Globally rename type LINENUM to lin (as in diffutils).
2010-04-19 01:38:28 +02:00
Andreas Gruenbacher
3bde83e95e Fix two compiler warnings
* src/patch.c (Argv): Change type to char ** so that we can pass Argv
to getopt_long without warning.
* src/maketime.c (maketime): Fix year overflow check.
2010-04-19 01:37:09 +02:00
Andreas Gruenbacher
f97abc39d2 diffseq: Use the gnulib version instead of a private copy
* diffseq: Use the gnulib version instead of a private copy.
2010-04-19 01:35:28 +02:00
Andreas Gruenbacher
130f11008d Update to latest gnulib
* gnulib: Update to latest.
2010-04-18 14:48:56 +02:00
Andreas Gruenbacher
b1c58bd212 Portability fixes in the test suite
* tests/merge: Use the sed commands i, a, and c in their standard form
instead of relying on a GNU extension, and pass sed a script (-f)
instead of a list of commands via -e.
Some versions of sed don't support expressions like /^\(\|foo\)$/.
* tests/corrupt-reject-files: Use the more widely available -e switch
instead of -A.
* tests/crlf-handling: Likewise.
* tests/preserve-mode-and-timestamp: Use touch -t instead of touch -d.
Some non-GNU versions of date can't show a file's timestamp.
2010-04-15 16:24:09 +02:00
Andreas Gruenbacher
57d468b7a4 Add rules for generating .version and for including .tarball-version in dist tarballs
* Makefile.am: Add rules for generating .version and for
including .tarball-version in dist tarballs.
2010-04-15 12:21:45 +02:00
Andreas Gruenbacher
65a8f0f278 Minimum versions required: automake-1.11.1, autoconf-2.65
* configure.ac: Minimum versions required: automake-1.11.1,
autoconf-2.65.
2010-04-12 19:13:53 +02:00
Andreas Gruenbacher
c86f4a2c80 Portability fixes
* tests/test-lib.sh: Some versions of mktemp require a filename
template; use one.  Provide a seq replacement on platforms which don't
have seq.
2010-04-12 17:19:33 +02:00
Andreas Gruenbacher
7fa8417c05 Convert to automake and use a git submodule for gnulib
* configure.ac: Add automake and gnulib macros, replace several
obsolete macros.
* Makefile.am, lib/Makefile.am, src/Makefile.am, tests/Makefile.am:
Add for automake.
* autogen.sh, INSTALL, Makefile.in, mkinstalldirs, update-version.sh:
Obsolete; remove.
* README-hacking: Import from diffutils, replace cvs with git.
* build-aux: Move gnulib auxiliary files here from the top-level
directory.
* gnulib: Add gnulib git submodule.
* bootstrap, bootstrap.conf: Import from gnulib and adjust.
* gl/lib: Remove gnulib files from the repository; they are now
imported into lib/ from gnulib as needed.
* tests/test-lib.sh: Use $abs_top_builddir exported from
tests/Makefile.am here instead of $PWD.
* m4/utimbuf.m4: This macro has been removed from gnulib. Add it here
for now; this will be replaced by gnulib's utimens module soon.
2010-04-12 16:27:55 +02:00
Andreas Gruenbacher
8d5ea52c7a Rename ed_PROGRAM to EDITOR_PROGRAM
* src/pch.c (EDITOR_PROGRAM): Rename from ed_PROGRAM.
* configure.ac (EDITOR_PROGRAM): Likewise.
2010-04-12 16:27:55 +02:00
Andreas Gruenbacher
231e52e985 Fix the use of HAVE_UTIME_H
* src/util.c: Fix the use of HAVE_UTIME_H.
2010-04-12 16:27:55 +02:00
Andreas Gruenbacher
d300ec9bb8 Merge: detect already-applied inserts at the end of files
* src/merge.c: When a hunk has fewer suffix than prefix context lines,
try matching to the end of the file instead of doing a "greedy match":
this allows to detect already-applied inserts at the end of the file.
* tests/merge: Add test cases for this.
2010-02-21 00:37:40 +01:00
Andreas Gruenbacher
70c5b3126f Clarify the description of the -N option
* patch.man: Clarify the description of the -N option.
2010-02-17 16:49:12 +01:00
Andreas Gruenbacher
f376c5db4a Fix HAVE_DECL_STRNLEN and HAVE_DECL_STRNDUP checks
* gl/lib/strndup.c: HAVE_DECL_STRNLEN is either 0 or 1 so we need
to test for it with #if, not #ifdef.
* gl/lib/xstrndup.c: Likewise for HAVE_DECL_STRNDUP.
2010-01-15 19:24:59 +01:00
Andreas Gruenbacher
91e027ab1a No longer use "continue" as the only instruction in a loop body
* 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.
2010-01-15 19:20:57 +01:00
Andreas Gruenbacher
819b4a5c1f Do not allow timestamps in Index lines
*  src/util.c (fetchname): Do not allow timestamps in Index lines.
2010-01-11 19:13:54 +01:00
Andreas Gruenbacher
3473a896bb Try to preserve the owning group in backup files
* src/util.c (create_backup_copy): Try to preserve the owning group
in backup files.
2010-01-04 17:55:22 +01:00
Matthew Burgess
d868be8cdf * tests/crlf-handling: Skip another ed-dependent test. 2010-01-04 11:18:37 +01:00
Andreas Gruenbacher
c3052e896b * src/patch.c (main): Compare the input file's group ID with the
effective group ID to determine if a chown() is necessary, not the
effective user ID.
2010-01-02 17:49:29 +01:00
Andreas Gruenbacher
fcdaaaac28 * src/bestmatch.h, src/common.h, src/diffseq.h, src/inp.c, src/inp.h,
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.
2010-01-02 13:36:55 +01:00
Andreas Gruenbacher
2c4e3ecdde * Makefile.in (LIBSRCS, LIBM4FILES): Add the missing files strnlen.c,
strnlen.m4, and safe-read.m4.
2010-01-01 16:06:45 +01:00
Andreas Gruenbacher
aa7ae95324 * src/pch.c: coding style fix (syntactic). 2009-12-30 19:44:49 +01:00
181 changed files with 10592 additions and 20046 deletions

7
.gitattributes vendored Normal file
View File

@ -0,0 +1,7 @@
# Run this to make 'git diff' on texinfo files give nicer hunk context:
# git config diff.texinfo.funcname '^@node[ ][ ]*\\([^,][^,]*\\)'
*.texi* diff=texinfo
# Run this to make 'git diff' on .m4 files give nicer hunk context:
# git config diff.m4.xfuncname '^((AC_DEFUN|m4_define)[^,)]*)'
*.m4 diff=m4

37
.gitignore vendored
View File

@ -1,19 +1,36 @@
*.log
*.o
/Makefile
*.trs
*~
.deps/
/.pc/
/.version
/ChangeLog
/GNUmakefile
/ID
/INSTALL
/VERSION
/[0-9]*.patch
/aclocal.m4
/autom4te.cache/
/build-aux/
/config.cache
/config.h
/config.hin
/config.hin~
/config.log
/config.status
/configure
/doc/
/lib/
!/lib/Makefile.am
/m4/*.m4
/m4/.gitignore
!/m4/setmode.m4
!/m4/xattr.m4
/maint.mk
/patch-*.tar.*
/src/patch
/.pc/
/VERSION
/patch-*.tar.bz2
/patch-*.tar.bz2.sig
/patch-*.tar.gz
/patch-*.tar.gz.sig
/patch-*.tar.xz
/patch-*.tar.xz.sig
/stamp-h1
Makefile
Makefile.in
TAGS

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "gnulib"]
path = gnulib
url = git://git.sv.gnu.org/gnulib.git

View File

@ -1,9 +1,618 @@
2011-03-17 Jim Meyering <meyering@redhat.com>
don't version-control ChangeLog; instead, generate it from git log
* Makefile.am (gen-ChangeLog): New rule.
* .gitignore: List ChangeLog.
2011-02-20 Jim Meyering <meyering@redhat.com>
maint: remove unnecessary tests before free
There is no longer any need to avoid "free(NULL)" (since SunOS 4),
so replace each "if (P) free (P);" with "free (P);".
* src/inp.c (get_input_file): Remove unnecessary test-before-free.
* src/patch.c (get_some_switches): Likewise.
* src/pch.c (intuit_diff_type, pch_swap): Likewise.
2011-02-17 Jim Meyering <meyering@redhat.com>
and Andreas Gruenbacher <agruen@linbit.com>
don't warn twice about the same invalid file name
* src/pch.c (name_is_valid): Don't warn about the same name twice.
* tests/bad-filenames (emit_patch): Exercise the new code.
2011-02-16 Andreas Gruenbacher <agruen@linbit.com>
* 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.
2011-02-15 Andreas Gruenbacher <agruen@linbit.com>
* src/patch.c (main): Fix use of initialized outst and add an
additional assert. Reported by Jim Meyering.
2011-02-03 Ozan Çağlayan <ozan@pardus.org.tr>
Create directory test case
* tests/create-delete: New test case creating a file in a new
sub-directory (bug fixed on 2010-12-04).
2011-02-03 Andreas Gruenbacher <agruen@linbit.com>
Also check if the input file is seekable if a filename is given (-i)
* src/pch.c (open_patch_file): Also check if the input file is
seekable if a filename is given (-i).
* tests/pipe: New file. Test this.
* tests/Makefile.am (TESTS): Add it.
2011-02-03 Jim Meyering <meyering@redhat.com>
doc: mention the fix for CVE-2010-4651
* NEWS: Mention the fix.
2011-02-01 Jim Meyering <meyering@redhat.com>
and Andreas Gruenbacher <agruen@linbit.com>
Do not let a malicious patch create files above current directory
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.
2010-12-04 Andreas Gruenbacher <agruen@linbit.com>
* src/util.c (make_tempfile): Create missing directories when
necessary.
2010-10-29 Andreas Gruenbacher <agruen@suse.de>
* src/util.c: USE_XATTR is defined to 0 or 1, so we need to use #if
instead of #ifdef.
2010-10-27 Andreas Gruenbacher <agruen@suse.de>
* src/util.c (set_file_attributes): Always expect the mode argument to
be set when FA_MODE is specified.
(create_backup_copy): Update accordingly.
* 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.
2010-10-26 Andreas Gruenbacher <agruen@suse.de>
* configure.ac: Remove obsolete checks for mktemp.
2010-10-20 Andreas Gruenbacher <agruen@suse.de>
* src/patch.c (print_header_line): Remove obsolete comment.
2010-10-14 Andreas Gruenbacher <agruen@suse.de>
* src/pch.c (there_is_another_patch): Set p_strip_trailing_cr
to false if no_strip_trailing_cr is set independent of the verbosity.
This broke the --binary option in combination with --silent.
2010-10-05 Andreas Gruenbacher <agruen@suse.de>
* 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.
2010-09-17 Andreas Gruenbacher <agruen@suse.de>
* src/inp.c (scan_input): Remove double quotearg().
* src/patch.c (main): Generate the "patching file" message here. When
the input and output file name is not he same, include both names in
the message.
* src/inp.c (scan_input): Previously the "patching file" message was
generated here.
* tests/unmodified-files, tests/copy-rename: Update.
* NEWS: Document that "diff --git" criss-cross renames are broken
still.
* tests/criss-cross: Test case currently expected to fail.
* tests/criss-cross: Add copy-after-modify test case.
2010-09-16 Andreas Gruenbacher <agruen@suse.de>
* src/patch.c (open_outfile): New function.
(init_output): Split into open_outfile() and the rest.
* src/pch.c (do_ed_script): Add inname, outname, and
outname_needs_removal arguments. This isolates TMPOUTNAME and
TMPOUTNAME_needs_removal to patch.c.
* src/patch.c (main): Update do_ed_script() call.
* bootstrap.conf: Use the gnulib tempname module.
* src/util.c (make_tempfile): New function.
* src/inp.c (plan_b): Compute TMPINNAME with make_tempfile() if needed
instead of precomputing it in src/patch.c (main).
* src/pch.c (open_patch_file): Compute TMPPATNAME with make_tempfile()
if needed instead of precomputing it in src/patch.c (main).
* src/patch.c (abort_hunk_unified): Replace unnecessary local variable.
* src/patch.c (main): Compute TMPREJNAME with make_tempfile() only if
needed.
(abort_hunk, init_reject): Pass through the output file name, and base
TMPREJNAME on it.
* src/patch.c (main): Compute TMPOUTNAME with make_tempfile().
(make_temp): Remove obsolete function.
2010-07-27 Tim Waugh <twaugh@redhat.com>
* src/patch.c: Stops "patch --get 1" from segfaulting.
2010-05-11 Andreas Gruenbacher <agruen@suse.de>
* src/patch.c: The read-only file check was not done for ed scripts;
fix this.
2010-05-06 Andreas Gruenbacher <agruen@suse.de>
* tests/corrupt-reject-files, tests/crlf-handling: On Solaris, cat's
-e option is only effective if -v is specified as well.
* tests/test-lib.sh: Ignore error messages when cleaning up after a
test has finished.
2010-05-05 Andreas Gruenbacher <agruen@suse.de>
* tests/test-lib.sh: Only use GNU diff when available.
* tests/dash-o-append: Fix the expected result.
* tests/create-delete: Do not use 'diff' here.
* tests/merge: Require GNU diff.
* bootstrap.conf: Use the gnulib unistd module.
* bootstrap.conf: Use the gnulib mkdir module.
* m4/mkdir.m4: Delete.
2010-05-04 Eric Blake <eblake@redhat.com>
* 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.
2010-05-04 Andreas Gruenbacher <agruen@suse.de>
* tests/read-only-files: Remove the superuser test, and instead try
out if a read-only file can be written to.
* tests/test-lib.sh: Create temporary directories in builddir; this
removes the need to do it safely: some systems do not have mktemp -d.
* configure.ac, tests/Makefile: Remove $(TEST_SHELL) and use $(SHELL)
instead.
* src/version.c: Put the Free Software Foundation copyright first.
* tests/read-only-files: Skip when run as superuser: even files
without write permissions would be writable.
* 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.
* tests/test-lib.sh: Flag tests with missing pre-requirements as
SKIPped instead of PASSed. Do not use GNU diff extensions, but
still require a diff that understands "-u".
* tests: Do not unnecessarily require GNU diff in a lot of tests.
Make the sed utility optional.
* src/pch.c (intuit_diff_type): Remove left-over debugging code.
* src/pch.c (maybe_reverse): Allow to create and delete empty files.
(sha1_says_nonexistent): New function for recognizing the sha1
checksums of nonexistent and empty files.
(skip_hex_digits): New helper function for skipping [0-9a-z].
(intuit_diff_type): Parse the sha1 checksums in index lines.
* tests/Makefile.am (XFAIL_TESTS): Remove empty-files.
2010-05-03 Andreas Gruenbacher <agruen@suse.de>
* src/pch.c (intuit_diff_type): Fix a bug where the reversed-patch
check would wrongly pick the last name instead of the best name.
* src/create-delete: Add test cases for that.
2010-05-02 Andreas Gruenbacher <agruen@suse.de>
* 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.
* tests/symlinks: Improve the backup file tests.
2010-05-02 Andreas Gruenbacher <agruen@suse.de>
* src/Makefile.am (patch_LDADD): Add $(LIB_CLOCK_GETTIME) here, after
libpatch.a, so that clock_gettime is properly resolved on systems on
which the library order matters.
* NEWS: Update.
* gnulib: Update to latest.
* bootstrap: Update from gnulib.
* src/patch.c (main): Refuse to patch read-only files, or at least warn
when patching such files with --force or --batch.
* patch.man: Document the changed behavior.
* tests/read-only-files: Split read-only file test case off from
tests/remember-backup-files.
* tests/Makefile.am: Add new test case.
2010-04-29 Andreas Gruenbacher <agruen@suse.de>
* src/patch.c (main): Support git diffs which copy or rename files.
* tests/copy-rename: New test case.
* tests/Makefile.am (TESTS): Add test case.
* 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.
* 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.
* 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.
* src/patch.c (main): Support git symlink diffs.
* tests/symlinks: Add git symlink diff test cases.
* src/pch.c (intuit_diff_type, there_is_another_patch): Pass up the
file type.
* src/patch.c (main): Check for consistent file types.
* src/pch.c (intuit_diff_type): Only check for reversed patches when
the input file type matches the patch file type.
* src/util.c (move_file): Remove test which is always true.
2010-04-28 Andreas Gruenbacher <agruen@suse.de>
* src/pch.c (p_mode): New variable.
(fetchmode, pch_mode): New functions.
(intuit_diff_type): Recognize git diffs which contain no hunks.
Parse and store the file modes in the "index", "old mode",
"new mode", "deleted file mode", and "new file mode" headers.
* 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.
* src/inp.c (get_input_file): Add a mode parameter specifying the
input file type (which can be either S_IFREG or S_IFLNK). The file
type must match this mode parameter; for symbolic links, the --get
option is not supported.
(scan_input): Abort when plan_a() cannot handle a symbolic link.
Say when patching a symbolic link instead of a regular file.
(plan_a): Add support for reading symbolic links.
* src/patch.c: For now, always tell get_input_file() to read regular
files.
* bootstrap.conf: Use the gnulib readlink module.
* 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.
2010-04-27 Andreas Gruenbacher <agruen@suse.de>
* bootstrap: Update from gnulib.
* tests/Makefile.am (TESTS_ENVIRONMENT): Portability fix.
* src/bestmatch.h (bestmatch): Fix an off-by-one error causing an
out-of-bounds array access.
* configure.ac (gl_CHECK_TYPE_STRUCT_UTIMBUF), m4/utimbuf.m4: Remove;
utimbuf is no longer used.
* src/util.h: Include <backupfile.h> here and not in each C file
individually; this avoids a warning in merge.c with some compilers.
* src/common.h: Do not redefine __attribute__ when it is already
defined.
* configure.ac: Do not use grep -q.
2010-04-27 Daniel Richard G. <skunk@iskunk.org>
* src/common.h (enum diff): Remove the trailing comma.
* src/patch.c (main): Do not use non-constant expressions in an array
initializer.
* src/bestmatch.h: Do not use variable-length arrays.
2010-04-26 Andreas Gruenbacher <agruen@suse.de>
* 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.
* src/pch.c (intuit_diff_type): Only check for reversed patches when
the input file is patchable in the first place.
* src/pch.c (get_input_file): If an input file is not a regular file,
only skip the patch instead of aborting.
* src/patch.c (main): If get_input_file() fails, skip the patch.
2010-04-25 Andreas Gruenbacher <agruen@suse.de>
* bootstrap.conf: Use the gnulib fcntl-h and sys_stat modules.
* src/common.h: Remove the declarations provided by gnulib sys_stat.
Always include fcntl.h (and depend on gnulib fcntl-h).
* src/util.h: Remove duplicate include of <timespec.h>.
* configure.ac: Remove obsolete checks for fcntl.h and utime.h.
* src/common.h, src/patch.c, src/util.c, src/util.h: Do not declare
variables as "volatile" unnecessarily.
2010-04-24 Andreas Gruenbacher <agruen@suse.de>
* 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.
2010-04-23 Andreas Gruenbacher <agruen@suse.de>
* patch.man: Describe the fixed behavior of --set-time and --set-utc
for timestamps that include time zones.
* NEWS: Update.
2010-04-22 Andreas Gruenbacher <agruen@suse.de>
* src/common.h (enum diff): New enumeration GIT_BINARY_DIFF.
* src/pch.c (intuit_diff_type): Recognize git binary patches.
* src/patch.c (main): Complain when fed git binary patches.
* tests/git-binary-diff: New test case.
* tests/Makefile.am (TESTS): Add test case.
* 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.
* src/pch.c (intuit_diff_type): Make sure we don't leak file names
even when fed weird input.
* 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.
* src/util.c (fetchname): Untangle the name and timestamp parsing.
* src/util.c (strip_leading_slashes): Make this a separate function.
(fetchname): Use strip_leading_slashes() here.
2010-04-21 Andreas Gruenbacher <agruen@suse.de>
* 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.
* 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.
2010-04-20 Andreas Gruenbacher <agruen@suse.de>
* 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.
* 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.
* src/util.c (fetchname): Cosmetic fix.
2010-04-19 Ludovic Courtès <ludo@gnu.org>
* src/Makefile.am (patch_SOURCES): Remove the obsolete diffseq.h to
fix "make dist".
2010-04-18 Andreas Gruenbacher <agruen@suse.de>
* Globally rename type LINENUM to lin (as in diffutils).
* src/patch.c (Argv): Change type to char ** so that we can pass Argv
to getopt_long without warning.
* src/maketime.c (maketime): Fix year overflow check.
* diffseq: Use the gnulib version instead of a private copy.
* gnulib: Update to latest.
2010-04-15 Andreas Gruenbacher <agruen@suse.de>
* tests/merge: Use the sed commands i, a, and c in their standard form
instead of relying on a GNU extension, and pass sed a script (-f)
instead of a list of commands via -e.
Some versions of sed don't support expressions like /^\(\|foo\)$/.
* tests/corrupt-reject-files: Use the more widely available -e switch
instead of -A.
* tests/crlf-handling: Likewise.
* tests/preserve-mode-and-timestamp: Use touch -t instead of touch -d.
Some non-GNU versions of date can't show a file's timestamp.
* Makefile.am: Add rules for generating .version and for including
.tarball-version in dist tarballs.
2010-04-12 Andreas Gruenbacher <agruen@suse.de>
* src/util.c: Fix the use of HAVE_UTIME_H.
* src/pch.c (EDITOR_PROGRAM): Rename from ed_PROGRAM.
* configure.ac (EDITOR_PROGRAM): Rename from ed_PROGRAM.
* configure.ac: Add automake and gnulib macros, replace several
obsolete macros.
* Makefile.am, lib/Makefile.am, src/Makefile.am, tests/Makefile.am:
Add for automake.
* autogen.sh, INSTALL, Makefile.in, mkinstalldirs, update-version.sh:
Obsolete; remove.
* README-hacking: Import from diffutils, replace cvs with git.
* build-aux: Move gnulib auxiliary files here from the top-level
directory.
* gnulib: Add gnulib git submodule.
* bootstrap, bootstrap.conf: Import from gnulib and adjust.
* gl/lib: Remove gnulib files from the repository; they are now
imported into lib/ from gnulib as needed.
* tests/test-lib.sh: Use $abs_top_builddir exported from
tests/Makefile.am here instead of $PWD.
* m4/utimbuf.m4: This macro has been removed from gnulib. Add it here
for now; this will be replaced by gnulib's utimens module soon.
* tests/test-lib.sh: Some versions of mktemp require a filename
template; use one. Provide a seq replacement on platforms which don't
have seq.
* configure.ac: Minimum versions required: automake-1.11.1,
autoconf-2.65.
2010-02-21 Andreas Gruenbacher <agruen@suse.de>
* src/merge.c: When a hunk has fewer suffix than prefix context lines,
try matching to the end of the file instead of doing a "greedy match":
this allows to detect already-applied inserts at the end of the file.
* tests/merge: Add test cases for this.
2010-02-17 Andreas Gruenbacher <agruen@suse.de>
* patch.man: Clarify the description of the -N option.
2010-01-15 Andreas Gruenbacher <agruen@suse.de>
* 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.
* gl/lib/strndup.c: HAVE_DECL_STRNLEN is either 0 or 1 so we need
to test for it with #if, not #ifdef.
* gl/lib/xstrndup.c: Likewise for HAVE_DECL_STRNDUP.
2010-01-11 Andreas Gruenbacher <agruen@suse.de>
* src/util.c (fetchname): Do not allow timestamps in Index lines.
2010-01-04 Andreas Gruenbacher <agruen@suse.de>
* src/util.c (create_backup_copy): Try to preserve the owning group
in backup files.
2010-01-03 Matthew Burgess <matthew@linuxfromscratch.org>
* tests/crlf-handling: Skip another ed-dependent test.
2010-01-02 Andreas Gruenbacher <agruen@suse.de>
* src/bestmatch.h, src/common.h, src/diffseq.h, src/inp.c, src/inp.h,
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.
* src/patch.c (main): Compare the input file's group ID with the
effective group ID to determine if a chown() is necessary, not the
effective user ID.
2010-01-01 Andreas Gruenbacher <agruen@suse.de>
* Makefile.in (LIBSRCS, LIBM4FILES): Add the missing files strnlen.c,
strnlen.m4, and safe-read.m4.
2009-12-30 Andreas Gruenbacher <agruen@suse.de>
* patch.man: Clarify the description of the -F / --fuzz option.
* NEWS: Version 2.6.1 released.
* src/pch.c: coding style fix (syntactic).
2009-12-29 Andreas Gruenbacher <agruen@suse.de>
* src/patch.c (longopts, get_some_switches): Add an optional argument
@ -430,7 +1039,7 @@
* tests/asymmetric-hunks: New test case.
* Makefile.in (TESTS): Add test case.
* util.c (move_file): Create backup files of nonexisting files with
* util.c (move_file): Create backup files of nonexistent files with
the default mode instead of mode 0: files with mode 0 cause too many
problems with applications which do not expect unreadable files.
* tests/create-delete: Test for this.
@ -1421,7 +2030,7 @@
* util.c (move_file): Don't assume that ENOENT is reported when both
ENOENT and EXDEV apply; this isn't true with DJGPP, and
Posix doesn't require it.
POSIX doesn't require it.
* pch.c (there_is_another_patch):
Suggest -p when we can't intuit a file.
@ -1576,7 +2185,7 @@
verbosity.
(fetchname): Change argument head_says_nonexistent to pstamp, and
store header timestamp into *pstamp.
If -T or -Z option is given, match time stamps more precisely.
If -T or -Z option is given, match timestamps more precisely.
(ask): Remove unnecessary close of ttyfd.
When there is no terminal at all, output a newline to make the
output look nicer. After reporting EOF, flush stdout;
@ -3049,24 +3658,20 @@ Sun Dec 17 17:29:48 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu)
* patch.c: Initial revision
Copyright (C) 1984, 1985, 1986, 1987, 1988 Larry Wall.
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
2002, 2009 Free Software Foundation, Inc.
Copyright 1989-2025 Free Software Foundation, Inc.
Copyright 1984-1988 Larry Wall.
This file is part of GNU Patch.
This program is free software; you can redistribute it and/or modify
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 Free Software Foundation; either version 2, or (at your option)
any later version.
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that they will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
along with this program. If not, see <http://www.gnu.org/licenses/>.

228
INSTALL
View File

@ -1,228 +0,0 @@
Copyright 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. (Caching is
disabled by default to prevent problems with accidental use of stale
cache files.)
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You only need
`configure.ac' if you want to change it or regenerate `configure' using
a newer version of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for variables by setting
them in the environment. You can do that on the command line like this:
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not support the `VPATH'
variable, you have to compile the package for one architecture at a
time in the source code directory. After you have installed the
package for one architecture, use `make distclean' before reconfiguring
for another architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
option `--prefix=PATH'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=PATH' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the `--target=TYPE' option to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
will cause the specified gcc to be used as the C compiler (unless it is
overridden in the site shell script).
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of the options to `configure', and exit.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

55
Makefile.am Normal file
View File

@ -0,0 +1,55 @@
# Copyright 1989-2025 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 Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## Process this file with automake to produce Makefile.in.
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = lib src tests
dist_man1_MANS = patch.man
EXTRA_DIST = \
ChangeLog-2011 \
cfg.mk \
m4/gnulib-cache.m4 \
m4/mkdir.m4 \
m4/setmode.m4 \
bootstrap \
pc
if ALPHA_VERSION
EXTRA_DIST += README-alpha
GNU_SERVER = alpha.gnu.org
RELEASE_TYPE = alpha
else
GNU_SERVER = ftp.gnu.org
RELEASE_TYPE = stable
endif
EXTRA_DIST += $(top_srcdir)/.version
BUILT_SOURCES = $(top_srcdir)/.version
$(top_srcdir)/.version:
echo $(VERSION) > $@-t && mv $@-t $@
dist-hook: gen-ChangeLog
echo $(VERSION) > $(distdir)/.tarball-version
gen_start_date = 2011-02-22
.PHONY: gen-ChangeLog
gen-ChangeLog:
$(AM_V_GEN)if test -d .git; then \
$(top_srcdir)/build-aux/gitlog-to-changelog \
--since=$(gen_start_date) > $(distdir)/cl-t; \
rm -f $(distdir)/ChangeLog; \
mv $(distdir)/cl-t $(distdir)/ChangeLog; \
fi

View File

@ -1,406 +0,0 @@
# Makefile for GNU patch.
# Copyright (C) 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2009
# 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 Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#### Start of system configuration section. ####
srcdir = @srcdir@
VPATH = @srcdir@
@SET_MAKE@
CC = @CC@
ed_PROGRAM = @ed_PROGRAM@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
TEST_SHELL = @TEST_SHELL@
transform = @program_transform_name@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
DEFS = @DEFS@
EXEEXT = @EXEEXT@
LDFLAGS = @LDFLAGS@
LIBOBJDIR = gl/lib/
LIBOBJS = @LIBOBJS@ ${LIBOBJDIR}full-write$U.o
LIBS = @LIBS@
OBJEXT = @OBJEXT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
STDBOOL_H = @STDBOOL_H@
GETOPT_H = @GETOPT_H@
HAVE__BOOL = @HAVE__BOOL@
ENABLE_MERGE = @ENABLE_MERGE@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
# Where to put the manual pages.
datarootdir = @datarootdir@
mandir = @mandir@
man1dir = $(mandir)/man1
# Extension (including `.') for the manual page filenames.
man1ext = .1
# Hook for nonstandard builds.
CONFIG_STATUS = config.status
#### End of system configuration section. ####
SHELL = /bin/sh
LIBSRCS = \
gl/lib/argmatch.c \
gl/lib/backupfile.c \
gl/lib/basename.c \
gl/lib/dirname.c \
gl/lib/error.c \
gl/lib/exitfail.c \
gl/lib/full-write.c \
gl/lib/getopt1.c \
gl/lib/getopt.c \
gl/lib/hash.c \
gl/lib/malloc.c \
gl/lib/mbrtowc.c \
gl/lib/memchr.c \
gl/lib/quotearg.c \
gl/lib/quote.c \
gl/lib/realloc.c \
gl/lib/rename.c \
gl/lib/safe-read.c \
gl/lib/safe-write.c \
gl/lib/strcasecmp.c \
gl/lib/stripslash.c \
gl/lib/strncasecmp.c \
gl/lib/strndup.c \
gl/lib/xmalloc.c \
gl/lib/xstrndup.c
SRCS = $(LIBSRCS) \
src/inp.c \
src/maketime.c \
src/merge.c \
src/partime.c \
src/patch.c \
src/pch.c \
src/quotesys.c \
src/util.c \
src/version.c
ifeq ($(ENABLE_MERGE),1)
MERGEOBJ = src/merge.$(OBJEXT)
endif
OBJS = $(LIBOBJS) $(MERGEOBJ) \
src/inp.$(OBJEXT) \
src/maketime.$(OBJEXT) \
src/partime.$(OBJEXT) \
src/patch.$(OBJEXT) \
src/pch.$(OBJEXT) \
src/quotesys.$(OBJEXT) \
src/util.$(OBJEXT) \
src/version.$(OBJEXT)
LIBHDRS = \
gl/lib/argmatch.h \
gl/lib/backupfile.h \
gl/lib/dirname.h \
gl/lib/error.h \
gl/lib/exitfail.h \
gl/lib/full-write.h \
gl/lib/getopt.hin \
gl/lib/getopt_int.h \
gl/lib/gettext.h \
gl/lib/hash.h \
gl/lib/minmax.h \
gl/lib/quotearg.h \
gl/lib/quote.h \
gl/lib/safe-write.h \
gl/lib/stdbool.hin \
gl/lib/unlocked-io.h \
gl/lib/verify.h \
gl/lib/xalloc.h \
gl/lib/xstrndup.h
HDRS = $(LIBHDRS) \
src/bestmatch.h \
src/common.h \
src/diffseq.h \
src/inp.h \
src/maketime.h \
src/partime.h \
src/pch.h \
src/quotesys.h \
src/util.h \
src/version.h
MISC = \
AUTHORS \
COPYING \
ChangeLog \
INSTALL \
Makefile.in \
NEWS \
README \
VERSION \
aclocal.m4 \
config.guess\
config.hin \
config.sub \
configure \
configure.ac \
install-sh \
mkinstalldirs \
patch.man \
tests/test-lib.sh \
update-version.sh
DISTFILES = $(MISC) $(SRCS) $(HDRS) $(M4FILES) \
pc/chdirsaf.c \
pc/djgpp/config.sed \
pc/djgpp/configure.bat \
pc/djgpp/configure.sed \
pc/djgpp/README
MORE_DISTFILES = $(TESTS) $(BROKEN_TESTS)
patch_name = `echo patch | sed '$(transform)'`
all:: src/patch$(EXEEXT)
info::
installcheck::
TESTS = \
tests/asymmetric-hunks \
tests/backup-prefix-suffix \
tests/corrupt-reject-files \
tests/create-delete \
tests/crlf-handling \
tests/filename-choice \
tests/global-reject-files \
tests/inname \
tests/line-numbers \
tests/merge \
tests/munged-context-format \
tests/need-filename \
tests/no-newline-triggers-assert \
tests/preserve-c-function-names \
tests/preserve-mode-and-timestamp \
tests/reject-format \
tests/remember-backup-files \
tests/remember-reject-files \
tests/unmodified-files
BROKEN_TESTS = \
tests/dash-o-append
check:: $(TESTS)
@echo All tests succeeded!
.PHONY: $(TESTS) $(BROKEN_TESTS)
$(TESTS) $(BROKEN_TESTS): all
@echo "[$@]"
@srcdir=$(srcdir)/tests $(TEST_SHELL) $(srcdir)/$@
ifeq ($(ENABLE_MERGE),1)
DEFINE_ENABLE_MERGE = -DENABLE_MERGE
endif
COMPILE = $(CC) -c $(CPPFLAGS) $(DEFS) -Ded_PROGRAM=\"$(ed_PROGRAM)\" \
$(DEFINE_ENABLE_MERGE) -I. -I$(srcdir)/src -I$(srcdir)/gl/lib $(CFLAGS)
.c.$(OBJEXT):
@mkdir -p $(@D)
$(COMPILE) -o $@ $<
src/patch$(EXEEXT): $(OBJS)
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS)
install:: all
$(SHELL) $(srcdir)/mkinstalldirs $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir)
$(INSTALL_PROGRAM) src/patch$(EXEEXT) $(DESTDIR)$(bindir)/$(patch_name)$(EXEEXT)
$(INSTALL_DATA) $(srcdir)/patch.man $(DESTDIR)$(man1dir)/$(patch_name)$(man1ext)
install-strip::
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
uninstall::
rm -f $(DESTDIR)$(bindir)/$(patch_name)$(EXEEXT) \
$(DESTDIR)$(man1dir)/$(patch_name)$(man1ext)
Makefile: Makefile.in $(CONFIG_STATUS)
$(SHELL) $(CONFIG_STATUS)
FORCE:
VERSION: FORCE
@cd $(srcdir) && $(SHELL) ./update-version.sh VERSION
config.status: configure
$(SHELL) $(CONFIG_STATUS) --recheck
configure: configure.ac $(srcdir)/aclocal.m4 $(srcdir)/VERSION
cd $(srcdir) && autoconf --force
config.hin: configure.ac $(srcdir)/aclocal.m4
cd $(srcdir) && autoheader --force
# We need the following in order to create <getopt.h> when the system
# doesn't have one that works with the given compiler.
getopt.h: gl/lib/getopt.hin
rm -f $@-t $@
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
cat $(srcdir)/gl/lib/getopt.hin; \
} > $@-t
mv -f $@-t $@
# We need the following in order to create <stdbool.h> when the system
# doesn't have one that works.
#gl/lib/stdbool.h: gl/lib/stdbool.hin
stdbool.h: gl/lib/stdbool.hin
rm -f $@-t $@
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' \
< $(srcdir)/gl/lib/stdbool.hin; \
} > $@-t
mv $@-t $@
LIBM4FILES = \
gl/m4/argmatch.m4 \
gl/m4/backupfile.m4 \
gl/m4/d-ino.m4 \
gl/m4/dirname.m4 \
gl/m4/dos.m4 \
gl/m4/double-slash-root.m4 \
gl/m4/error.m4 \
gl/m4/exitfail.m4 \
gl/m4/extensions.m4 \
gl/m4/getopt.m4 \
gl/m4/gettext.m4 \
gl/m4/hash.m4 \
gl/m4/inline.m4 \
gl/m4/malloc.m4 \
gl/m4/mbrtowc.m4 \
gl/m4/mbstate_t.m4 \
gl/m4/memchr.m4 \
gl/m4/minmax.m4 \
gl/m4/onceonly.m4 \
gl/m4/quotearg.m4 \
gl/m4/quote.m4 \
gl/m4/realloc.m4 \
gl/m4/rename.m4 \
gl/m4/safe-write.m4 \
gl/m4/ssize_t.m4 \
gl/m4/stdbool.m4 \
gl/m4/strcase.m4 \
gl/m4/strndup.m4 \
gl/m4/unlocked-io.m4 \
gl/m4/utimbuf.m4 \
gl/m4/xalloc.m4 \
gl/m4/xstrndup.m4
M4FILES = $(LIBM4FILES) \
m4/mkdir.m4 \
m4/setmode.m4
$(srcdir)/aclocal.m4: $(M4FILES)
aclocal -I m4 -I gl/m4
TAGS: $(HDRS) $(SRCS)
etags $(HDRS) $(SRCS)
mostlyclean::
rm -f core* *core src/*.$(OBJEXT) gl/lib/*.$(OBJEXT) \
stdbool.h getopt.h gl/lib/*.h-t
clean:: mostlyclean
rm -f src/patch$(EXEEXT)
distclean:: clean
rm -f Makefile config.cache config.hin~ config.log config.status \
config.h
rm -rf autom4te.cache/
maintainer-clean::
@echo "This command is intended for maintainers to use;"
@echo "rebuilding the deleted files requires special tools."
$(MAKE) distclean
rm -f TAGS VERSION aclocal.m4 config.hin configure \
patch-*.tar.gz patch-*.tar.gz.sig
PV = $(PACKAGE_NAME)-$(PACKAGE_VERSION)
dist:: $(DISTFILES)
@rm -rf $(PV)
@ln -s . $(PV)
@tar -cf - `( printf "%s\n" $(DISTFILES) $(MORE_DISTFILES); \
grep -q -E -- '-[0-9]+-[0-9a-z]+(-dirty)?$$' VERSION \
&& echo README-alpha \
) | sed -e 's,^$(srcdir)/,,' -e "s,^,$(PV)/," \
| LC_ALL=C sort` \
| gzip -9 > $(PV).tar.gz
@if which bzip2 >/dev/null 2>/dev/null; then \
gzip -d < $(PV).tar.gz | bzip2 -9 > $(PV).tar.bz2; fi
@if which xz >/dev/null 2>/dev/null; then \
gzip -d < $(PV).tar.gz | xz -9 > $(PV).tar.xz; fi
@rm -rf $(PV)
@whereto=$$(if grep -q -E -- '-[0-9]+-[0-9a-z]+(-dirty)?$$' VERSION; \
then echo alpha; else echo ftp; fi); \
echo; \
echo "# gnupload --to $$whereto.gnu.org:patch $(PV).tar.gz"; \
test ! -e $(PV).tar.bz2 || echo "# gnupload" \
"--to $$whereto.gnu.org:patch $(PV).tar.bz2"; \
test ! -e $(PV).tar.xz || echo "# gnupload" \
"--to $$whereto.gnu.org:patch $(PV).tar.xz"; \
echo
$(OBJS): config.h
COMMON = src/common.h $(STDBOOL_H)
gl/lib/addext.$(OBJEXT): gl/lib/backupfile.h gl/lib/dirname.h
gl/lib/argmatch.$(OBJEXT): $(STDBOOL_H) gl/lib/argmatch.h gl/lib/gettext.h \
gl/lib/error.h gl/lib/quote.h gl/lib/quotearg.h gl/lib/unlocked-io.h
gl/lib/backupfile.$(OBJEXT): gl/lib/argmatch.h gl/lib/backupfile.h \
gl/lib/dirname.h
gl/lib/basename.$(OBJEXT): gl/lib/dirname.h
gl/lib/dirname.$(OBJEXT): gl/lib/dirname.h gl/lib/xalloc.h
gl/lib/error.$(OBJEXT): gl/lib/error.h gl/lib/gettext.h gl/lib/unlocked-io.h
gl/lib/exitfail.$(OBJEXT): gl/lib/exitfail.h
gl/lib/full-write.$(OBJEXT): gl/lib/full-write.h gl/lib/safe-write.h
gl/lib/getopt.$(OBJEXT) gl/lib/getopt1.$(OBJEXT): getopt.h
gl/lib/hash.$(OBJEXT): $(STDBOOL_H) gl/lib/hash.h
gl/lib/safe-read.$(OBJEXT): gl/lib/safe-write.h
gl/lib/safe-write.$(OBJEXT): gl/lib/safe-read.c
src/inp.$(OBJEXT): gl/lib/backupfile.h $(COMMON) src/inp.h src/pch.h \
gl/lib/quotearg.h src/util.h gl/lib/xalloc.h
src/maketime.$(OBJEXT): src/maketime.h src/partime.h
src/partime.$(OBJEXT): src/partime.h
src/patch.$(OBJEXT): gl/lib/argmatch.h gl/lib/backupfile.h $(COMMON) \
gl/lib/exitfail.h $(GETOPT_H) src/inp.h src/pch.h \
gl/lib/quotearg.h src/util.h src/version.h gl/lib/xalloc.h
src/pch.$(OBJEXT): gl/lib/backupfile.h $(COMMON) gl/lib/dirname.h src/inp.h \
src/pch.h gl/lib/quotearg.h src/util.h
gl/lib/quote.$(OBJECT): gl/lib/quote.h gl/lib/quotearg.h
gl/lib/quotearg.$(OBJEXT): gl/lib/gettext.h gl/lib/quotearg.h gl/lib/xalloc.h
src/quotesys.$(OBJEXT): src/quotesys.h
gl/lib/strncasecmp.$(OBJEXT): gl/lib/strcasecmp.c
src/util.$(OBJEXT): gl/lib/backupfile.h $(COMMON) gl/lib/dirname.h gl/lib/full-write.h \
gl/lib/hash.h src/maketime.h src/partime.h gl/lib/quotearg.h \
src/quotesys.h src/util.h src/version.h gl/lib/xalloc.h
src/version.$(OBJEXT): $(COMMON) src/version.h
gl/lib/xmalloc.$(OBJEXT): gl/lib/error.h gl/lib/exitfail.h gl/lib/gettext.h \
gl/lib/xalloc.h

108
NEWS
View File

@ -1,3 +1,91 @@
Unreleased changes:
Changes in version 2.8:
* The --follow-symlinks option now applies to output files as well as input.
* 'patch' now supports file timestamps after 2038 even on traditional
GNU/Linux platforms where time_t defaults to 32 bits.
* 'patch' no longer creates files with names containing newlines,
as encouraged by POSIX.1-2024.
* Patches can no longer contain NUL ('\0') bytes in diff directive lines.
These bytes would otherwise cause unpredictable behavior.
* Patches can now contain sequences of spaces and tabs around line numbers
and in other places where POSIX requires support for these sequences.
* --enable-gcc-warnings no longer uses expensive static checking.
Use --enable-gcc-warnings=expensive if you still want it.
* Fix undefined or ill-defined behavior in unusual cases, such as very
large sizes, possible stack overflow, I/O errors, memory exhaustion,
races with other processes, and signals arriving at inopportune moments.
* Remove old "Plan B" code, designed for machines with 16-bit pointers.
* Assume C99 or later; previously it assumed C89 or later.
* Port to current GCC, Autoconf, Gnulib, etc.
Changes in version 2.7.6:
* Files specified on the command line are no longer verified to be inside the
current working directory, so commands like "patch -i foo.diff ../foo" will
work again.
* Various fixes.
Changes in version 2.7.5:
* There are users which expect patch to follow symbolic links in the working
directory, so patch now again follows symbolic links as long as they do not
leave the working directory.
Changes until version 2.7.4:
* When a file isn't being deleted because the file contents don't match the
patch, the resulting message is now "Not deleting file ... as content
differs from patch" instead of "File ... is not empty after patch; not
deleting".
* Function names in hunks (from diff -p) are now preserved in reject files.
* Patch no longer follows symbolic links to input and output files. This
ensures that symbolic links created by git-style patches cannot cause
patch to write outside the working directory (CVE-2015-1196).
* Various fixes.
Changes in version 2.7.1:
* Two critical bug fixes in the "diff --git" format support.
* Clarify the message printed when a patch is expected to empty out and delete
a file, but the file does not become empty.
* Various improvements to messages when applying a patch to a file of different
type (regular file vs. symlink), when there are line ending differences (LF
vs. CRLF), and when in --dry-run mode.
* When in the root directory, allow file names that are absolute or that
contain a component of "..".
* New --follow-symlinks option to allow to treat symlinks as files: this was
patch's behavior before version 2.7.
* Ignore when extended attributes cannot be preserved because they are
unsupported or because permission to set them is denied.
* License clarifications in NEWS and README.
* Portability bug fixes.
Changes in version 2.7:
* Patch no longer gets a failed assertion for certain mangled patches.
* Ignore destination file names that are absolute or that contain a component
of "..". This addresses CVE-2010-4651.
* Support for most features of the "diff --git" format, including renames and
copies, permission changes, and symlink diffs. Binary diffs are not
supported yet; patch will complain and skip them.
* Support for double-quoted filenames: when a filename starts with a double
quote, it is interpreted as a C string literal. The escape sequences \\, \",
\a, \b, \f, \n, \r, \t, \v, and \ooo (a three-digit octal number between 0
and 255) are recognized.
* Refuse to apply a normal patch to a symlink. (Previous versions of patch
were replacing the symlink with a regular file.)
* When trying to modify a read-only file, warn about the potential problem
by default. The --read-only command line option allows to change this
behavior.
* Files to be deleted are deleted once the entire input has been processed, not
immediately. This fixes a bug with numbered backup files.
* When a timestamp specifies a time zone, honor that instead of assuming the
local time zone (--set-date) or Universal Coordinated Time (--set-utc).
* Support for nanosecond precision timestamps.
* Many portability and bug fixes.
Changes in version 2.6.1:
* Support for diff3(1) style merges which show the old, original, and new lines
@ -43,7 +131,7 @@ Changes in version 2.6:
line endings in patches. This allows to preserve CRs even in mangled
patches, or in patches generated on non-POSIX systems and without the
--binary option.
* Backup files for nonexisting files are now created with default
* Backup files for nonexistent files are now created with default
permissions rather than with mode 0: backup files with mode 0 were
causing problems with applications which do not expect unreadable
files.
@ -56,6 +144,7 @@ Changes in version 2.6:
particularly with Perforce.)
* Handle missing timestamps better.
* Various bug fixes.
* Switch to GNU General Public License version 3.
Changes in versions 2.5.8 and 2.5.9: bug fixes only.
@ -68,7 +157,7 @@ Changes in version 2.5.6:
* File names in context patches may now contain spaces, so long
as the context patch headers use a tab to separate the file name
from the time stamp.
from the timestamp.
* Perforce is now supported.
* Patch lines beginning with "#" are comments and are ignored.
@ -275,22 +364,19 @@ Changes in version 2.0.12g8:
Copyright (C) 1992, 1993, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2006, 2009
Free Software Foundation, Inc.
Copyright 1992-2025 Free Software Foundation, Inc.
This file is part of GNU Patch.
This program is free software; you can redistribute it and/or modify
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 Free Software Foundation; either version 2, or (at your option)
any later version.
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that they will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
along with this program. If not, see <http://www.gnu.org/licenses/>.

38
README
View File

@ -1,4 +1,6 @@
This version of `patch' has many changes made by the Free Software Foundation.
This is GNU patch, which applies diff files to original files.
This version of patch has many changes made by the Free Software Foundation.
They add support for:
* handling arbitrary binary data and large files
* the unified context diff format that GNU diff can produce
@ -7,13 +9,20 @@ They add support for:
* improved interaction with RCS and SCCS
* the GNU conventions for option parsing and configuring and compilation.
* better POSIX compliance
They also fix some bugs. See the NEWS and ChangeLog files for details.
They also fix some bugs.
If you obtained this file as part of a "git clone", then see the
README-hacking file. If this file came to you as part of a tar archive,
then see the file INSTALL for compilation and installation instructions.
See the file NEWS for a list of major changes in the current release.
A more detailed description of all changes can be found in the file ChangeLog
in tar archives, and with "git log" which shows the version control history.
Tutorial-style documentation for patch is included in the GNU
Diffutils package; get GNU Diffutils 2.8 or later for up-to-date
documentation for patch.
For GNU and Unix build and installation instructions, see the file INSTALL.
Use `configure --disable-largefile' to disable large file support;
this is reportedly necessary on Red Hat GNU/Linux 6.0 to avoid a C library bug.
For MS-DOS using DJGPP tools, see the file pc/djgpp/README.
@ -32,24 +41,25 @@ too busy working on other things, like Perl. He has graciously agreed
to let GNU `patch' be distributed under the terms of the GNU General
Public License.
For any copyright year range specified as YYYY-ZZZZ in this package
note that the range specifies every single year in that closed interval.
Please see the file COPYING for copying conditions.
------
Copyright (C) 1984, 1985, 1986, 1987, 1988 Larry Wall
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1997, 1999, 2002, 2009
Free Software Foundation, Inc.
Copyright 1989-2025 Free Software Foundation, Inc.
Copyright 1984-1988 Larry Wall
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 Free Software Foundation; either version 2, or (at your option)
any later version.
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this file; see the file COPYING.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
along with this program. If not, see <http://www.gnu.org/licenses/>.

117
README-hacking Normal file
View File

@ -0,0 +1,117 @@
Building from a Git repository -*- outline -*-
These notes intend to help people working on the checked-out sources.
These requirements do not apply when building from a distribution tarball.
If this package has a file HACKING, please also read that file for
more detailed contribution guidelines.
* Requirements
We've opted to keep only the highest-level sources in the Git repository.
This eases our maintenance burden (fewer merges etc.), but imposes more
requirements on anyone wishing to build from the just-checked-out sources.
(The requirements to build from a release are much less and are just
the requirements of the standard './configure && make' procedure.)
Specific development tools and versions will be checked for and listed by
the bootstrap script. See README-prereq for specific notes on obtaining
these prerequisite tools.
Valgrind <http://valgrind.org/> is also highly recommended, if
Valgrind supports your architecture. See also README-valgrind
(if present).
While building from a just-cloned source tree may require installing a
few prerequisites, later, a plain 'git pull && make' typically suffices.
* First Git checkout
You can get a copy of the source repository like this:
$ git clone git://git.sv.gnu.org/<packagename>
$ cd <packagename>
where '<packagename>' stands for 'coreutils' or whatever other package
you are building.
To use the most-recent Gnulib (as opposed to the Gnulib version that
the package last synchronized to), do this next:
$ git submodule foreach git pull origin master
$ git commit -m 'build: update gnulib submodule to latest' gnulib
As an optional step, if you already have a copy of the Gnulib Git
repository, then you can use it as a reference to reduce download
time and file system space requirements:
$ export GNULIB_SRCDIR=/path/to/gnulib
The next step is to get and check other files needed to build,
which are extracted from other source packages:
$ ./bootstrap
And there you are! Just
$ ./configure --quiet #[--disable-gcc-warnings] [*]
$ make
$ make check
At this point, there should be no difference between your local copy,
and the Git master copy:
$ git diff
should output no difference.
Enjoy!
[*] By default GCC warnings are enabled when building from Git.
If you get warnings with recent GCC and Glibc with default
configure-time options, please report the warnings to the bug
reporting address of this package instead of to bug-gnulib,
even if the problem seems to originate in a Gnulib-provided file.
If you get warnings with other configurations, you can run
'./configure --disable-gcc-warnings' or 'make WERROR_CFLAGS='
to build quietly or verbosely, respectively.
-----
* Submitting patches
If you develop a fix or a new feature, please send it to the
appropriate bug-reporting address as reported by the --help option of
each program. One way to do this is to use vc-dwim
<https://www.gnu.org/software/vc-dwim/>), as follows.
Run the command "vc-dwim --initialize" from the top-level directory
of this package's git-cloned hierarchy.
Edit the (empty) ChangeLog file that this command creates, creating a
properly-formatted entry according to the GNU coding standards
<https://www.gnu.org/prep/standards/html_node/Change-Logs.html>.
Make your changes.
Run the command "vc-dwim" and make sure its output (the diff of all
your changes) looks good.
Run "vc-dwim --commit".
Run the command "git format-patch --stdout -1", and email its output
in, using the output's subject line.
-----
Copyright 2002-2025 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 Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

36
README-prereq Normal file
View File

@ -0,0 +1,36 @@
This gives some notes on obtaining the tools required for development.
These tools can be used by the 'bootstrap' and 'configure' scripts,
as well as by 'make'. They include:
- Autoconf <https://www.gnu.org/software/autoconf/>
- Automake <https://www.gnu.org/software/automake/>
- Git <https://git-scm.com/>
- Gzip <https://www.gnu.org/software/gzip/>
- M4 <https://www.gnu.org/software/m4/>
- Make <https://www.gnu.org/software/make/>
- Tar <https://www.gnu.org/software/tar/>
- Texinfo <https://www.gnu.org/software/texinfo/>
- Wget <http://www.gnu.org/software/wget/>
- XZ Utils <https://tukaani.org/xz/>
It is generally better to use official packages for your system.
If a package is not officially available you can build it from source
and install it into a directory that you can then use to build this
package. If some packages are available but are too old, install the
too-old versions first as they may be needed to build newer versions.
Here is an example of how to build a program from source. This
example is for Autoconf; a similar approach should work for the other
developer prerequisites. This example assumes Autoconf 2.it; 72
should be OK to use a later version of Autoconf, if available.
prefix=$HOME/prefix # (or wherever else you choose)
export PATH=$prefix/bin:$PATH
wget https://ftp.gnu.org/pub/gnu/autoconf/autoconf-2.72.tar.gz
gzip -d <autoconf-2.72.tar.gz | tar xf -
cd autoconf-2.72
./configure --prefix=$prefix
make install
Once the prerequisites are installed, you can build this package as
described in README-hacking.

View File

@ -1,6 +0,0 @@
#! /bin/sh
aclocal -I m4 -I gl/m4 --force
autoheader --force
autoconf --force
echo Run ./configure now ...

1612
bootstrap Executable file

File diff suppressed because it is too large Load Diff

104
bootstrap.conf Normal file
View File

@ -0,0 +1,104 @@
# Bootstrap configuration. -*- sh -*-
# Copyright 2006-2025 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 Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# gnulib modules used by this package.
gnulib_modules="
announce-gen
argmatch
assert-h
attribute
backupfile
basename-lgpl
bool
c-ctype
closeout
diffseq
dup2
errno-h
exitfail
extensions
faccessat
fchownat
fchmodat
fcntl-h
filename
fseeko
fstatat
ftello
futimens
getopt-gnu
gettime
gitlog-to-changelog
git-version-gen
gnupload
hash
idx
ignore-value
intprops
inttypes-h
largefile
maintainer-makefile
malloc-gnu
manywarnings
memchr
mempcpy
minmax
mkdirat
nullptr
openat
parse-datetime
progname
quotearg
raise
readlinkat
realloc-posix
renameat
setenv
signal-h
ssize_t
stat-time
stdckdint-h
stdlib-h
stpcpy
symlinkat
sys_stat-h
tempname
test-xfail
unistd-h
unlinkat
update-copyright
utimensat
verror
xalloc
xstdopen
year2038-recommended
"
# Build prerequisites
buildreq="\
autoconf 2.59
automake 1.9.6
git 1.5.5
tar -
"
bootstrap_post_import_hook ()
{
# Automake requires that ChangeLog exist.
touch ChangeLog || exit 1
}

45
cfg.mk Normal file
View File

@ -0,0 +1,45 @@
# Customize maint.mk -*- makefile -*-
# Copyright 2011-2025 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 Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
config_h_header = <(common|config)\.h>
ifeq ($(RELEASE_TYPE),alpha)
news-check-regexp = "Unreleased changes"
else
news-check-regexp = '^Changes in version $(VERSION_REGEXP):'
endif
release-prep-hook =
update-copyright-env = \
UPDATE_COPYRIGHT_FORCE=1 \
UPDATE_COPYRIGHT_USE_INTERVALS=2 \
UPDATE_COPYRIGHT_MAX_LINE_LENGTH=79
local-checks-to-skip = \
sc_GPL_version \
sc_bindtextdomain \
sc_file_system \
sc_immutable_NEWS \
sc_obsolete_symbols \
sc_prohibit_always_true_header_tests \
sc_prohibit_magic_number_exit \
sc_prohibit_strcmp \
sc_prohibit_test_minus_ao \
sc_require_test_exit_idiom
exclude_file_name_regexp--sc_prohibit_doubled_word = ^src/util\.c$$
exclude_file_name_regexp--sc_unmarked_diagnostics = ^src/util\.c$$

1555
config.guess vendored

File diff suppressed because it is too large Load Diff

1685
config.sub vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,9 @@
# Configure `patch'.
# Copyright 1993-2025 Free Software Foundation, Inc.
# Copyright (C) 1993, 1997, 1998, 1999, 2002, 2003, 2006, 2009
# Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# 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 Free Software Foundation; either version 2, or (at your option)
# any later version.
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -14,88 +11,115 @@
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ(2.57)
define(AC_PACKAGE_VERSION, m4_normalize(esyscmd(
[
sh ./update-version.sh VERSION
cat VERSION
])))
AC_INIT(patch, AC_PACKAGE_VERSION, bug-patch@gnu.org)
AC_CONFIG_SRCDIR(src/patch.c)
AC_CONFIG_HEADER(config.h:config.hin)
AC_ARG_PROGRAM
AC_PREREQ([2.65])
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_MAKE_SET
# Use ed_PROGRAM, not ED_PROGRAM,
# because <errno.h> reserves symbols starting with `E'.
AC_PATH_PROG(ed_PROGRAM, ed, ed)
AC_INIT([GNU patch],
m4_esyscmd([build-aux/git-version-gen .tarball-version]),
[bug-patch@gnu.org])
AC_PATH_PROG(TEST_SHELL, [bash sh])
gl_USE_SYSTEM_EXTENSIONS
AC_PROG_CC_STDC
AC_SYS_LARGEFILE
AC_EXEEXT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h utime.h)
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AM_STDBOOL_H
gl_CHECK_TYPE_STRUCT_UTIMBUF
gl_ARGMATCH
gl_BACKUPFILE
gl_DIRNAME
gl_ERROR
gl_EXITFAIL
gl_FUNC_MEMCHR
gl_FUNC_STRNDUP
gl_FUNC_STRNLEN
gl_GETOPT
gl_HASH
gl_PREREQ_XMALLOC
gl_QUOTE
gl_QUOTEARG
gl_SAFE_WRITE
gl_STRCASE
gl_XALLOC
gl_XSTRNDUP
dnl lib/basename.c requires xstrndup.
AC_LIBOBJ([xstrndup])
dnl m4/error.m4 does not do this:
AC_LIBOBJ([error])
AC_CHECK_DECLS([mktemp])
AC_CHECK_FUNCS(geteuid getuid mktemp raise sigaction sigprocmask sigsetmask)
AC_FUNC_FSEEKO
gl_FUNC_GLIBC_UNLOCKED_IO
gl_FUNC_MALLOC_POSIX
gl_FUNC_REALLOC_POSIX
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_SETMODE_DOS
AC_FUNC_VPRINTF
PATCH_FUNC_MKDIR_TAKES_ONE_ARG
gl_AC_DOS
AC_SYS_LONG_FILE_NAMES
AC_CONFIG_SRCDIR([src/patch.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_ARG_ENABLE([merge],
[AS_HELP_STRING([--disable-merge],
[disable support for merging])])
if test "$enableval" != no ; then
AC_SUBST(ENABLE_MERGE, 1)
AM_CONDITIONAL([ENABLE_MERGE], [test "$enableval" != no])
AM_CONDITIONAL([ALPHA_VERSION],
[[echo "$PACKAGE_VERSION" | grep -- "-[0-9a-f][0-9a-f]*\\(-dirty\\)\\?$" >/dev/null]])
AM_INIT_AUTOMAKE([1.11.2 -Wall gnu dist-bzip2 dist-xz color-tests parallel-tests subdir-objects])
AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([config.h:config.hin])
AC_PROG_CC
gl_EARLY
gl_INIT
AM_PROG_AR
AC_ARG_ENABLE([gcc-warnings],
[AS_HELP_STRING([--enable-gcc-warnings@<:@=TYPE@:>@],
[control generation of GCC warnings. The TYPE 'no' disables
warnings (default for non-developer builds); 'yes' generates
cheap warnings if available;
'expensive' in addition generates expensive-to-compute warnings
if available.])],
[case $enableval in
no|yes|expensive) ;;
*) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
esac
gl_gcc_warnings=$enableval],
[gl_gcc_warnings=no]
)
if test $gl_gcc_warnings != no; then
gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
AC_SUBST([WERROR_CFLAGS])
ew=
AS_IF([test $gl_gcc_warnings != expensive],
[# -fanalyzer and related options slow GCC considerably.
ew="$ew -fanalyzer -Wno-analyzer-malloc-leak"])
# This, $nw, is the list of warnings we disable.
nw=$ew
nw="$nw -Winline" # It's OK for a compiler to not inline.
# Using -Wstrict-overflow is a pain, but the alternative is worse.
# For an example, see the code that provoked this report:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498
# Code like that still infloops with gcc-4.6.0 and -O2. Scary indeed.
gl_MANYWARN_ALL_GCC([ws])
gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
for w in $ws; do
gl_WARN_ADD([$w])
done
gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now
gl_WARN_ADD([-fdiagnostics-show-option])
AC_SUBST([WARN_CFLAGS])
AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
AH_VERBATIM([FORTIFY_SOURCE],
[/* Enable compile-time and run-time bounds-checking, and some warnings,
without upsetting glibc 2.15+. */
#if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
# define _FORTIFY_SOURCE 2
#endif
])
AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
# We also use a smaller set of warning options for lib/.
# Remove the following and save the result in GNULIB_WARN_CFLAGS.
nw=$ew
gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
AC_SUBST([GNULIB_WARN_CFLAGS])
fi
AC_CONFIG_FILES([Makefile])
# Ensure VLAs are not used.
# Note -Wvla is implicitly added by gl_MANYWARN_ALL_GCC
AC_DEFINE([GNULIB_NO_VLA], [1], [Define to 1 to disable use of VLAs])
AC_TYPE_MODE_T
AC_TYPE_OFF_T
gl_FUNC_XATTR
AC_CHECK_FUNCS_ONCE([geteuid getuid sigaction sigfillset])
AC_FUNC_SETMODE_DOS
AC_PATH_PROG([ED], [ed], [ed])
AC_DEFINE_UNQUOTED([EDITOR_PROGRAM], ["$ED"], [Name of editor program.])
AC_CONFIG_FILES([
Makefile
lib/Makefile
src/Makefile
tests/Makefile
])
AC_OUTPUT

View File

@ -1,277 +0,0 @@
/* argmatch.c -- find a match for a string in an array
Copyright (C) 1990, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by David MacKenzie <djm@ai.mit.edu>
Modified by Akim Demaille <demaille@inf.enst.fr> */
#include <config.h>
/* Specification. */
#include "argmatch.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "error.h"
#include "quotearg.h"
#include "quote.h"
#if USE_UNLOCKED_IO
# include "unlocked-io.h"
#endif
/* When reporting an invalid argument, show nonprinting characters
by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
literal_quoting_style. */
#ifndef ARGMATCH_QUOTING_STYLE
# define ARGMATCH_QUOTING_STYLE locale_quoting_style
#endif
/* Non failing version of argmatch call this function after failing. */
#ifndef ARGMATCH_DIE
# include "exitfail.h"
# define ARGMATCH_DIE exit (exit_failure)
#endif
#ifdef ARGMATCH_DIE_DECL
ARGMATCH_DIE_DECL;
#endif
static void
__argmatch_die (void)
{
ARGMATCH_DIE;
}
/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
Default to __argmatch_die, but allow caller to change this at run-time. */
argmatch_exit_fn argmatch_die = __argmatch_die;
/* If ARG is an unambiguous match for an element of the
NULL-terminated array ARGLIST, return the index in ARGLIST
of the matched element, else -1 if it does not match any element
or -2 if it is ambiguous (is a prefix of more than one element).
If VALLIST is none null, use it to resolve ambiguities limited to
synonyms, i.e., for
"yes", "yop" -> 0
"no", "nope" -> 1
"y" is a valid argument, for `0', and "n" for `1'. */
ptrdiff_t
argmatch (const char *arg, const char *const *arglist,
const char *vallist, size_t valsize)
{
size_t i; /* Temporary index in ARGLIST. */
size_t arglen; /* Length of ARG. */
ptrdiff_t matchind = -1; /* Index of first nonexact match. */
bool ambiguous = false; /* If true, multiple nonexact match(es). */
arglen = strlen (arg);
/* Test all elements for either exact match or abbreviated matches. */
for (i = 0; arglist[i]; i++)
{
if (!strncmp (arglist[i], arg, arglen))
{
if (strlen (arglist[i]) == arglen)
/* Exact match found. */
return i;
else if (matchind == -1)
/* First nonexact match found. */
matchind = i;
else
{
/* Second nonexact match found. */
if (vallist == NULL
|| memcmp (vallist + valsize * matchind,
vallist + valsize * i, valsize))
{
/* There is a real ambiguity, or we could not
disambiguate. */
ambiguous = true;
}
}
}
}
if (ambiguous)
return -2;
else
return matchind;
}
/* Error reporting for argmatch.
CONTEXT is a description of the type of entity that was being matched.
VALUE is the invalid value that was given.
PROBLEM is the return value from argmatch. */
void
argmatch_invalid (const char *context, const char *value, ptrdiff_t problem)
{
char const *format = (problem == -1
? _("invalid argument %s for %s")
: _("ambiguous argument %s for %s"));
error (0, 0, format, quotearg_n_style (0, ARGMATCH_QUOTING_STYLE, value),
quote_n (1, context));
}
/* List the valid arguments for argmatch.
ARGLIST is the same as in argmatch.
VALLIST is a pointer to an array of values.
VALSIZE is the size of the elements of VALLIST */
void
argmatch_valid (const char *const *arglist,
const char *vallist, size_t valsize)
{
size_t i;
const char *last_val = NULL;
/* We try to put synonyms on the same line. The assumption is that
synonyms follow each other */
fprintf (stderr, _("Valid arguments are:"));
for (i = 0; arglist[i]; i++)
if ((i == 0)
|| memcmp (last_val, vallist + valsize * i, valsize))
{
fprintf (stderr, "\n - `%s'", arglist[i]);
last_val = vallist + valsize * i;
}
else
{
fprintf (stderr, ", `%s'", arglist[i]);
}
putc ('\n', stderr);
}
/* Never failing versions of the previous functions.
CONTEXT is the context for which argmatch is called (e.g.,
"--version-control", or "$VERSION_CONTROL" etc.). Upon failure,
calls the (supposed never to return) function EXIT_FN. */
ptrdiff_t
__xargmatch_internal (const char *context,
const char *arg, const char *const *arglist,
const char *vallist, size_t valsize,
argmatch_exit_fn exit_fn)
{
ptrdiff_t res = argmatch (arg, arglist, vallist, valsize);
if (res >= 0)
/* Success. */
return res;
/* We failed. Explain why. */
argmatch_invalid (context, arg, res);
argmatch_valid (arglist, vallist, valsize);
(*exit_fn) ();
return -1; /* To please the compilers. */
}
/* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
return the first corresponding argument in ARGLIST */
const char *
argmatch_to_argument (const char *value,
const char *const *arglist,
const char *vallist, size_t valsize)
{
size_t i;
for (i = 0; arglist[i]; i++)
if (!memcmp (value, vallist + valsize * i, valsize))
return arglist[i];
return NULL;
}
#ifdef TEST
/*
* Based on "getversion.c" by David MacKenzie <djm@gnu.ai.mit.edu>
*/
char *program_name;
/* When to make backup files. */
enum backup_type
{
/* Never make backups. */
no_backups,
/* Make simple backups of every file. */
simple_backups,
/* Make numbered backups of files that already have numbered backups,
and simple backups of the others. */
numbered_existing_backups,
/* Make numbered backups of every file. */
numbered_backups
};
/* Two tables describing arguments (keys) and their corresponding
values */
static const char *const backup_args[] =
{
"no", "none", "off",
"simple", "never",
"existing", "nil",
"numbered", "t",
0
};
static const enum backup_type backup_vals[] =
{
no_backups, no_backups, no_backups,
simple_backups, simple_backups,
numbered_existing_backups, numbered_existing_backups,
numbered_backups, numbered_backups
};
int
main (int argc, const char *const *argv)
{
const char *cp;
enum backup_type backup_type = no_backups;
program_name = (char *) argv[0];
if (argc > 2)
{
fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name);
exit (1);
}
if ((cp = getenv ("VERSION_CONTROL")))
backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
backup_args, backup_vals);
if (argc == 2)
backup_type = XARGMATCH (program_name, argv[1],
backup_args, backup_vals);
printf ("The version control is `%s'\n",
ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
return 0;
}
#endif

View File

@ -1,102 +0,0 @@
/* argmatch.h -- definitions and prototypes for argmatch.c
Copyright (C) 1990, 1998, 1999, 2001, 2002, 2004, 2005 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by David MacKenzie <djm@ai.mit.edu>
Modified by Akim Demaille <demaille@inf.enst.fr> */
#ifndef ARGMATCH_H_
# define ARGMATCH_H_ 1
# include <stddef.h>
# include "verify.h"
# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
/* Assert there are as many real arguments as there are values
(argument list ends with a NULL guard). */
# define ARGMATCH_VERIFY(Arglist, Vallist) \
verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
/* Return the index of the element of ARGLIST (NULL terminated) that
matches with ARG. If VALLIST is not NULL, then use it to resolve
false ambiguities (i.e., different matches of ARG but corresponding
to the same values in VALLIST). */
ptrdiff_t argmatch (char const *arg, char const *const *arglist,
char const *vallist, size_t valsize);
# define ARGMATCH(Arg, Arglist, Vallist) \
argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
/* xargmatch calls this function when it fails. This function should not
return. By default, this is a function that calls ARGMATCH_DIE which
in turn defaults to `exit (exit_failure)'. */
typedef void (*argmatch_exit_fn) (void);
extern argmatch_exit_fn argmatch_die;
/* Report on stderr why argmatch failed. Report correct values. */
void argmatch_invalid (char const *context, char const *value,
ptrdiff_t problem);
/* Left for compatibility with the old name invalid_arg */
# define invalid_arg(Context, Value, Problem) \
argmatch_invalid (Context, Value, Problem)
/* Report on stderr the list of possible arguments. */
void argmatch_valid (char const *const *arglist,
char const *vallist, size_t valsize);
# define ARGMATCH_VALID(Arglist, Vallist) \
argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
/* Same as argmatch, but upon failure, reports a explanation on the
failure, and exits using the function EXIT_FN. */
ptrdiff_t __xargmatch_internal (char const *context,
char const *arg, char const *const *arglist,
char const *vallist, size_t valsize,
argmatch_exit_fn exit_fn);
/* Programmer friendly interface to __xargmatch_internal. */
# define XARGMATCH(Context, Arg, Arglist, Vallist) \
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
(char const *) (Vallist), \
sizeof *(Vallist), \
argmatch_die)])
/* Convert a value into a corresponding argument. */
char const *argmatch_to_argument (char const *value,
char const *const *arglist,
char const *vallist, size_t valsize);
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
argmatch_to_argument (Value, Arglist, \
(char const *) (Vallist), sizeof *(Vallist))
#endif /* ARGMATCH_H_ */

View File

@ -1,362 +0,0 @@
/* backupfile.c -- make Emacs style backup file names
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert and David MacKenzie.
Some algorithms adapted from GNU Emacs. */
#include <config.h>
#include "backupfile.h"
#include "argmatch.h"
#include "dirname.h"
#include "xalloc.h"
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <dirent.h>
#ifndef _D_EXACT_NAMLEN
# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
#endif
#if D_INO_IN_DIRENT
# define REAL_DIR_ENTRY(dp) ((dp)->d_ino != 0)
#else
# define REAL_DIR_ENTRY(dp) 1
#endif
#if ! (HAVE_PATHCONF && defined _PC_NAME_MAX)
# define pathconf(file, option) (errno = -1)
#endif
#ifndef _POSIX_NAME_MAX
# define _POSIX_NAME_MAX 14
#endif
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#if defined _XOPEN_NAME_MAX
# define NAME_MAX_MINIMUM _XOPEN_NAME_MAX
#else
# define NAME_MAX_MINIMUM _POSIX_NAME_MAX
#endif
#ifndef HAVE_DOS_FILE_NAMES
# define HAVE_DOS_FILE_NAMES 0
#endif
#ifndef HAVE_LONG_FILE_NAMES
# define HAVE_LONG_FILE_NAMES 0
#endif
/* ISDIGIT differs from isdigit, as follows:
- Its arg may be any int or unsigned int; it need not be an unsigned char
or EOF.
- It's typically faster.
POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
ISDIGIT unless it's important to use the locale's definition
of `digit' even when the host does not conform to POSIX. */
#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
/* The results of opendir() in this file are not used with dirfd and fchdir,
therefore save some unnecessary work in fchdir.c. */
#undef opendir
#undef closedir
/* The extension added to file names to produce a simple (as opposed
to numbered) backup file name. */
char const *simple_backup_suffix = "~";
/* If FILE (which was of length FILELEN before an extension was
appended to it) is too long, replace the extension with the single
char E. If the result is still too long, remove the char just
before E. */
static void
check_extension (char *file, size_t filelen, char e)
{
char *base = last_component (file);
size_t baselen = base_len (base);
size_t baselen_max = HAVE_LONG_FILE_NAMES ? 255 : NAME_MAX_MINIMUM;
if (HAVE_DOS_FILE_NAMES || NAME_MAX_MINIMUM < baselen)
{
/* The new base name is long enough to require a pathconf check. */
long name_max;
/* Temporarily modify the buffer into its parent directory name,
invoke pathconf on the directory, and then restore the buffer. */
char tmp[sizeof "."];
memcpy (tmp, base, sizeof ".");
strcpy (base, ".");
errno = 0;
name_max = pathconf (file, _PC_NAME_MAX);
if (0 <= name_max || errno == 0)
{
long size = baselen_max = name_max;
if (name_max != size)
baselen_max = SIZE_MAX;
}
memcpy (base, tmp, sizeof ".");
}
if (HAVE_DOS_FILE_NAMES && baselen_max <= 12)
{
/* Live within DOS's 8.3 limit. */
char *dot = strchr (base, '.');
if (!dot)
baselen_max = 8;
else
{
char const *second_dot = strchr (dot + 1, '.');
baselen_max = (second_dot
? second_dot - base
: dot + 1 - base + 3);
}
}
if (baselen_max < baselen)
{
baselen = file + filelen - base;
if (baselen_max <= baselen)
baselen = baselen_max - 1;
base[baselen] = e;
base[baselen + 1] = '\0';
}
}
/* Returned values for NUMBERED_BACKUP. */
enum numbered_backup_result
{
/* The new backup name is the same length as an existing backup
name, so it's valid for that directory. */
BACKUP_IS_SAME_LENGTH,
/* Some backup names already exist, but the returned name is longer
than any of them, and its length should be checked. */
BACKUP_IS_LONGER,
/* There are no existing backup names. The new name's length
should be checked. */
BACKUP_IS_NEW
};
/* *BUFFER contains a file name. Store into *BUFFER the next backup
name for the named file, with a version number greater than all the
existing numbered backups. Reallocate *BUFFER as necessary; its
initial allocated size is BUFFER_SIZE, which must be at least 4
bytes longer than the file name to make room for the initially
appended ".~1". FILELEN is the length of the original file name.
The returned value indicates what kind of backup was found. If an
I/O or other read error occurs, use the highest backup number that
was found. */
static enum numbered_backup_result
numbered_backup (char **buffer, size_t buffer_size, size_t filelen)
{
enum numbered_backup_result result = BACKUP_IS_NEW;
DIR *dirp;
struct dirent *dp;
char *buf = *buffer;
size_t versionlenmax = 1;
char *base = last_component (buf);
size_t base_offset = base - buf;
size_t baselen = base_len (base);
/* Temporarily modify the buffer into its parent directory name,
open the directory, and then restore the buffer. */
char tmp[sizeof "."];
memcpy (tmp, base, sizeof ".");
strcpy (base, ".");
dirp = opendir (buf);
memcpy (base, tmp, sizeof ".");
strcpy (base + baselen, ".~1~");
if (!dirp)
return result;
while ((dp = readdir (dirp)) != NULL)
{
char const *p;
char *q;
bool all_9s;
size_t versionlen;
size_t new_buflen;
if (! REAL_DIR_ENTRY (dp) || _D_EXACT_NAMLEN (dp) < baselen + 4)
continue;
if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0)
continue;
p = dp->d_name + baselen + 2;
/* Check whether this file has a version number and if so,
whether it is larger. Use string operations rather than
integer arithmetic, to avoid problems with integer overflow. */
if (! ('1' <= *p && *p <= '9'))
continue;
all_9s = (*p == '9');
for (versionlen = 1; ISDIGIT (p[versionlen]); versionlen++)
all_9s &= (p[versionlen] == '9');
if (! (p[versionlen] == '~' && !p[versionlen + 1]
&& (versionlenmax < versionlen
|| (versionlenmax == versionlen
&& memcmp (buf + filelen + 2, p, versionlen) <= 0))))
continue;
/* This directory has the largest version number seen so far.
Append this highest numbered extension to the file name,
prepending '0' to the number if it is all 9s. */
versionlenmax = all_9s + versionlen;
result = (all_9s ? BACKUP_IS_LONGER : BACKUP_IS_SAME_LENGTH);
new_buflen = filelen + 2 + versionlenmax + 1;
if (buffer_size <= new_buflen)
{
buf = xnrealloc (buf, 2, new_buflen);
buffer_size = new_buflen * 2;
}
q = buf + filelen;
*q++ = '.';
*q++ = '~';
*q = '0';
q += all_9s;
memcpy (q, p, versionlen + 2);
/* Add 1 to the version number. */
q += versionlen;
while (*--q == '9')
*q = '0';
++*q;
}
closedir (dirp);
*buffer = buf;
return result;
}
/* Return the name of the new backup file for the existing file FILE,
allocated with malloc. Report an error and fail if out of memory.
Do not call this function if backup_type == no_backups. */
char *
find_backup_file_name (char const *file, enum backup_type backup_type)
{
size_t filelen = strlen (file);
char *s;
size_t ssize;
bool simple = true;
/* Allow room for simple or ".~N~" backups. The guess must be at
least sizeof ".~1~", but otherwise will be adjusted as needed. */
size_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
size_t backup_suffix_size_guess = simple_backup_suffix_size;
enum { GUESS = sizeof ".~12345~" };
if (backup_suffix_size_guess < GUESS)
backup_suffix_size_guess = GUESS;
ssize = filelen + backup_suffix_size_guess + 1;
s = xmalloc (ssize);
memcpy (s, file, filelen + 1);
if (backup_type != simple_backups)
switch (numbered_backup (&s, ssize, filelen))
{
case BACKUP_IS_SAME_LENGTH:
return s;
case BACKUP_IS_LONGER:
simple = false;
break;
case BACKUP_IS_NEW:
simple = (backup_type == numbered_existing_backups);
break;
}
if (simple)
memcpy (s + filelen, simple_backup_suffix, simple_backup_suffix_size);
check_extension (s, filelen, '~');
return s;
}
static char const * const backup_args[] =
{
/* In a series of synonyms, present the most meaningful first, so
that argmatch_valid be more readable. */
"none", "off",
"simple", "never",
"existing", "nil",
"numbered", "t",
NULL
};
static const enum backup_type backup_types[] =
{
no_backups, no_backups,
simple_backups, simple_backups,
numbered_existing_backups, numbered_existing_backups,
numbered_backups, numbered_backups
};
/* Ensure that these two vectors have the same number of elements,
not counting the final NULL in the first one. */
ARGMATCH_VERIFY (backup_args, backup_types);
/* Return the type of backup specified by VERSION.
If VERSION is NULL or the empty string, return numbered_existing_backups.
If VERSION is invalid or ambiguous, fail with a diagnostic appropriate
for the specified CONTEXT. Unambiguous abbreviations are accepted. */
enum backup_type
get_version (char const *context, char const *version)
{
if (version == 0 || *version == 0)
return numbered_existing_backups;
else
return XARGMATCH (context, version, backup_args, backup_types);
}
/* Return the type of backup specified by VERSION.
If VERSION is NULL, use the value of the envvar VERSION_CONTROL.
If the specified string is invalid or ambiguous, fail with a diagnostic
appropriate for the specified CONTEXT.
Unambiguous abbreviations are accepted. */
enum backup_type
xget_version (char const *context, char const *version)
{
if (version && *version)
return get_version (context, version);
else
return get_version ("$VERSION_CONTROL", getenv ("VERSION_CONTROL"));
}

View File

@ -1,59 +0,0 @@
/* backupfile.h -- declarations for making Emacs style backup file names
Copyright (C) 1990, 1991, 1992, 1997, 1998, 1999, 2003, 2004 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef BACKUPFILE_H_
# define BACKUPFILE_H_
# ifdef __cplusplus
extern "C" {
# endif
/* When to make backup files. */
enum backup_type
{
/* Never make backups. */
no_backups,
/* Make simple backups of every file. */
simple_backups,
/* Make numbered backups of files that already have numbered backups,
and simple backups of the others. */
numbered_existing_backups,
/* Make numbered backups of every file. */
numbered_backups
};
# define VALID_BACKUP_TYPE(Type) \
((unsigned int) (Type) <= numbered_backups)
extern char const *simple_backup_suffix;
char *find_backup_file_name (char const *, enum backup_type);
enum backup_type get_version (char const *context, char const *arg);
enum backup_type xget_version (char const *context, char const *arg);
void addext (char *, char const *, int);
# ifdef __cplusplus
}
# endif
#endif /* ! BACKUPFILE_H_ */

View File

@ -1,128 +0,0 @@
/* basename.c -- return the last element in a file name
Copyright (C) 1990, 1998, 1999, 2000, 2001, 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
#include <string.h>
#include "xalloc.h"
#include "xstrndup.h"
/* Return the address of the last file name component of NAME. If
NAME has no relative file name components because it is a file
system root, return the empty string. */
char *
last_component (char const *name)
{
char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
char const *p;
bool saw_slash = false;
while (ISSLASH (*base))
base++;
for (p = base; *p; p++)
{
if (ISSLASH (*p))
saw_slash = true;
else if (saw_slash)
{
base = p;
saw_slash = false;
}
}
return (char *) base;
}
/* In general, we can't use the builtin `basename' function if available,
since it has different meanings in different environments.
In some environments the builtin `basename' modifies its argument.
Return the last file name component of NAME, allocated with
xmalloc. On systems with drive letters, a leading "./"
distinguishes relative names that would otherwise look like a drive
letter. Unlike POSIX basename(), NAME cannot be NULL,
base_name("") returns "", and the first trailing slash is not
stripped.
If lstat (NAME) would succeed, then { chdir (dir_name (NAME));
lstat (base_name (NAME)); } will access the same file. Likewise,
if the sequence { chdir (dir_name (NAME));
rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME
to "foo" in the same directory NAME was in. */
char *
base_name (char const *name)
{
char const *base = last_component (name);
size_t length;
/* If there is no last component, then name is a file system root or the
empty string. */
if (! *base)
return xstrndup (name, base_len (name));
/* Collapse a sequence of trailing slashes into one. */
length = base_len (base);
if (ISSLASH (base[length]))
length++;
/* On systems with drive letters, `a/b:c' must return `./b:c' rather
than `b:c' to avoid confusion with a drive letter. On systems
with pure POSIX semantics, this is not an issue. */
if (FILE_SYSTEM_PREFIX_LEN (base))
{
char *p = xmalloc (length + 3);
p[0] = '.';
p[1] = '/';
memcpy (p + 2, base, length);
p[length + 2] = '\0';
return p;
}
/* Finally, copy the basename. */
return xstrndup (base, length);
}
/* Return the length of the basename NAME. Typically NAME is the
value returned by base_name or last_component. Act like strlen
(NAME), except omit all trailing slashes. */
size_t
base_len (char const *name)
{
size_t len;
size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
continue;
if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
&& ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
return 2;
if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
&& len == prefix_len && ISSLASH (name[prefix_len]))
return prefix_len + 1;
return len;
}

View File

@ -1,84 +0,0 @@
/* dirname.c -- return all but the last element in a file name
Copyright (C) 1990, 1998, 2000, 2001, 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
#include <string.h>
#include "xalloc.h"
/* Return the length of the prefix of FILE that will be used by
dir_name. If FILE is in the working directory, this returns zero
even though `dir_name (FILE)' will return ".". Works properly even
if there are trailing slashes (by effectively ignoring them). */
size_t
dir_len (char const *file)
{
size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
size_t length;
/* Advance prefix_length beyond important leading slashes. */
prefix_length += (prefix_length != 0
? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
&& ISSLASH (file[prefix_length]))
: (ISSLASH (file[0])
? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
&& ISSLASH (file[1]) && ! ISSLASH (file[2])
? 2 : 1))
: 0));
/* Strip the basename and any redundant slashes before it. */
for (length = last_component (file) - file;
prefix_length < length; length--)
if (! ISSLASH (file[length - 1]))
break;
return length;
}
/* In general, we can't use the builtin `dirname' function if available,
since it has different meanings in different environments.
In some environments the builtin `dirname' modifies its argument.
Return the leading directories part of FILE, allocated with xmalloc.
Works properly even if there are trailing slashes (by effectively
ignoring them). Unlike POSIX dirname(), FILE cannot be NULL.
If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
lstat (base_name (FILE)); } will access the same file. Likewise,
if the sequence { chdir (dir_name (FILE));
rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
to "foo" in the same directory FILE was in. */
char *
dir_name (char const *file)
{
size_t length = dir_len (file);
bool append_dot = (length == 0
|| (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
&& length == FILE_SYSTEM_PREFIX_LEN (file)
&& file[2] != '\0' && ! ISSLASH (file[2])));
char *dir = xmalloc (length + append_dot + 1);
memcpy (dir, file, length);
if (append_dot)
dir[length++] = '.';
dir[length] = '\0';
return dir;
}

View File

@ -1,69 +0,0 @@
/* Take file names apart into directory and base names.
Copyright (C) 1998, 2001, 2003-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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef DIRNAME_H_
# define DIRNAME_H_ 1
# include <stdbool.h>
# include <stddef.h>
# ifndef DIRECTORY_SEPARATOR
# define DIRECTORY_SEPARATOR '/'
# endif
# ifndef ISSLASH
# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
# endif
# ifndef FILE_SYSTEM_PREFIX_LEN
# if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
/* This internal macro assumes ASCII, but all hosts that support drive
letters use ASCII. */
# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
<= 'z' - 'a')
# define FILE_SYSTEM_PREFIX_LEN(Filename) \
(_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
# else
# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
# endif
# endif
# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
# endif
# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
# endif
# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
# else
# define IS_ABSOLUTE_FILE_NAME(F) \
(ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
# endif
# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
char *base_name (char const *file);
char *dir_name (char const *file);
size_t base_len (char const *file);
size_t dir_len (char const *file);
char *last_component (char const *file);
bool strip_trailing_slashes (char *file);
#endif /* not DIRNAME_H_ */

View File

@ -1,57 +0,0 @@
/* Duplicate an open file descriptor to a specified file descriptor.
Copyright (C) 1999, 2004, 2005, 2006, 2007 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* written by Paul Eggert */
#include <config.h>
/* Specification. */
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#ifndef F_DUPFD
static int
dupfd (int fd, int desired_fd)
{
int duplicated_fd = dup (fd);
if (duplicated_fd < 0 || duplicated_fd == desired_fd)
return duplicated_fd;
else
{
int r = dupfd (fd, desired_fd);
int e = errno;
close (duplicated_fd);
errno = e;
return r;
}
}
#endif
int
dup2 (int fd, int desired_fd)
{
if (fd == desired_fd)
return fd;
close (desired_fd);
#ifdef F_DUPFD
return fcntl (fd, F_DUPFD, desired_fd);
#else
return dupfd (fd, desired_fd);
#endif
}

View File

@ -1,338 +0,0 @@
/* Error handler for noninteractive utilities
Copyright (C) 1990-1998, 2000-2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#if !_LIBC
# include <config.h>
#endif
#include "error.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !_LIBC && ENABLE_NLS
# include "gettext.h"
# define _(msgid) gettext (msgid)
#endif
#ifdef _LIBC
# include <libintl.h>
# include <stdbool.h>
# include <stdint.h>
# include <wchar.h>
# define mbsrtowcs __mbsrtowcs
#endif
#if USE_UNLOCKED_IO
# include "unlocked-io.h"
#endif
#ifndef _
# define _(String) String
#endif
/* If NULL, error will flush stdout, then print on stderr the program
name, a colon and a space. Otherwise, error will call this
function without parameters instead. */
void (*error_print_progname) (void);
/* This variable is incremented each time `error' is called. */
unsigned int error_message_count;
#ifdef _LIBC
/* In the GNU C library, there is a predefined variable for this. */
# define program_name program_invocation_name
# include <errno.h>
# include <limits.h>
# include <libio/libioP.h>
/* In GNU libc we want do not want to use the common name `error' directly.
Instead make it a weak alias. */
extern void __error (int status, int errnum, const char *message, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern void __error_at_line (int status, int errnum, const char *file_name,
unsigned int line_number, const char *message,
...)
__attribute__ ((__format__ (__printf__, 5, 6)));;
# define error __error
# define error_at_line __error_at_line
# include <libio/iolibio.h>
# define fflush(s) INTUSE(_IO_fflush) (s)
# undef putc
# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
# include <bits/libc-lock.h>
#else /* not _LIBC */
# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
# ifndef HAVE_DECL_STRERROR_R
"this configure-time declaration test was not run"
# endif
char *strerror_r ();
# endif
/* The calling program should define program_name and set it to the
name of the executing program. */
extern char *program_name;
# if HAVE_STRERROR_R || defined strerror_r
# define __strerror_r strerror_r
# endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */
static void
print_errno_message (int errnum)
{
char const *s;
#if defined HAVE_STRERROR_R || _LIBC
char errbuf[1024];
# if STRERROR_R_CHAR_P || _LIBC
s = __strerror_r (errnum, errbuf, sizeof errbuf);
# else
if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
s = errbuf;
else
s = 0;
# endif
#else
s = strerror (errnum);
#endif
#if !_LIBC
if (! s)
s = _("Unknown system error");
#endif
#if _LIBC
__fxprintf (NULL, ": %s", s);
#else
fprintf (stderr, ": %s", s);
#endif
}
static void
error_tail (int status, int errnum, const char *message, va_list args)
{
#if _LIBC
if (_IO_fwide (stderr, 0) > 0)
{
# define ALLOCA_LIMIT 2000
size_t len = strlen (message) + 1;
wchar_t *wmessage = NULL;
mbstate_t st;
size_t res;
const char *tmp;
bool use_malloc = false;
while (1)
{
if (__libc_use_alloca (len * sizeof (wchar_t)))
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
else
{
if (!use_malloc)
wmessage = NULL;
wchar_t *p = (wchar_t *) realloc (wmessage,
len * sizeof (wchar_t));
if (p == NULL)
{
free (wmessage);
fputws_unlocked (L"out of memory\n", stderr);
return;
}
wmessage = p;
use_malloc = true;
}
memset (&st, '\0', sizeof (st));
tmp = message;
res = mbsrtowcs (wmessage, &tmp, len, &st);
if (res != len)
break;
if (__builtin_expect (len >= SIZE_MAX / 2, 0))
{
/* This really should not happen if everything is fine. */
res = (size_t) -1;
break;
}
len *= 2;
}
if (res == (size_t) -1)
{
/* The string cannot be converted. */
if (use_malloc)
{
free (wmessage);
use_malloc = false;
}
wmessage = (wchar_t *) L"???";
}
__vfwprintf (stderr, wmessage, args);
if (use_malloc)
free (wmessage);
}
else
#endif
vfprintf (stderr, message, args);
va_end (args);
++error_message_count;
if (errnum)
print_errno_message (errnum);
#if _LIBC
__fxprintf (NULL, "\n");
#else
putc ('\n', stderr);
#endif
fflush (stderr);
if (status)
exit (status);
}
/* Print the program name and error message MESSAGE, which is a printf-style
format string with optional args.
If ERRNUM is nonzero, print its corresponding system error message.
Exit with status STATUS if it is nonzero. */
void
error (int status, int errnum, const char *message, ...)
{
va_list args;
#if defined _LIBC && defined __libc_ptf_call
/* We do not want this call to be cut short by a thread
cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0);
#endif
fflush (stdout);
#ifdef _LIBC
_IO_flockfile (stderr);
#endif
if (error_print_progname)
(*error_print_progname) ();
else
{
#if _LIBC
__fxprintf (NULL, "%s: ", program_name);
#else
fprintf (stderr, "%s: ", program_name);
#endif
}
va_start (args, message);
error_tail (status, errnum, message, args);
#ifdef _LIBC
_IO_funlockfile (stderr);
# ifdef __libc_ptf_call
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
# endif
#endif
}
/* Sometimes we want to have at most one error per line. This
variable controls whether this mode is selected or not. */
int error_one_per_line;
void
error_at_line (int status, int errnum, const char *file_name,
unsigned int line_number, const char *message, ...)
{
va_list args;
if (error_one_per_line)
{
static const char *old_file_name;
static unsigned int old_line_number;
if (old_line_number == line_number
&& (file_name == old_file_name
|| strcmp (old_file_name, file_name) == 0))
/* Simply return and print nothing. */
return;
old_file_name = file_name;
old_line_number = line_number;
}
#if defined _LIBC && defined __libc_ptf_call
/* We do not want this call to be cut short by a thread
cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0);
#endif
fflush (stdout);
#ifdef _LIBC
_IO_flockfile (stderr);
#endif
if (error_print_progname)
(*error_print_progname) ();
else
{
#if _LIBC
__fxprintf (NULL, "%s:", program_name);
#else
fprintf (stderr, "%s:", program_name);
#endif
}
#if _LIBC
__fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
#else
fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
#endif
va_start (args, message);
error_tail (status, errnum, message, args);
#ifdef _LIBC
_IO_funlockfile (stderr);
# ifdef __libc_ptf_call
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
# endif
#endif
}
#ifdef _LIBC
/* Make the weak alias. */
# undef error
# undef error_at_line
weak_alias (__error, error)
weak_alias (__error_at_line, error_at_line)
#endif

View File

@ -1,65 +0,0 @@
/* Declaration for error-reporting function
Copyright (C) 1995, 1996, 1997, 2003, 2006, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _ERROR_H
#define _ERROR_H 1
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
# define __format__ format
# define __printf__ printf
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Print a message with `fprintf (stderr, FORMAT, ...)';
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
extern void error (int __status, int __errnum, const char *__format, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern void error_at_line (int __status, int __errnum, const char *__fname,
unsigned int __lineno, const char *__format, ...)
__attribute__ ((__format__ (__printf__, 5, 6)));
/* If NULL, error will flush stdout, then print on stderr the program
name, a colon and a space. Otherwise, error will call this
function without parameters instead. */
extern void (*error_print_progname) (void);
/* This variable is incremented each time `error' is called. */
extern unsigned int error_message_count;
/* Sometimes we want to have at most one error per line. This
variable controls whether this mode is selected or not. */
extern int error_one_per_line;
#ifdef __cplusplus
}
#endif
#endif /* error.h */

View File

@ -1,24 +0,0 @@
/* Failure exit status
Copyright (C) 2002, 2003, 2005, 2006, 2007 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "exitfail.h"
#include <stdlib.h>
int volatile exit_failure = EXIT_FAILURE;

View File

@ -1,18 +0,0 @@
/* Failure exit status
Copyright (C) 2002 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
extern int volatile exit_failure;

View File

@ -1,80 +0,0 @@
/* An interface to read and write that retries (if necessary) until complete.
Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#ifdef FULL_READ
# include "full-read.h"
#else
# include "full-write.h"
#endif
#include <errno.h>
#ifdef FULL_READ
# include "safe-read.h"
# define safe_rw safe_read
# define full_rw full_read
# undef const
# define const /* empty */
#else
# include "safe-write.h"
# define safe_rw safe_write
# define full_rw full_write
#endif
#ifdef FULL_READ
/* Set errno to zero upon EOF. */
# define ZERO_BYTE_TRANSFER_ERRNO 0
#else
/* Some buggy drivers return 0 when one tries to write beyond
a device's end. (Example: Linux 1.2.13 on /dev/fd0.)
Set errno to ENOSPC so they get a sensible diagnostic. */
# define ZERO_BYTE_TRANSFER_ERRNO ENOSPC
#endif
/* Write(read) COUNT bytes at BUF to(from) descriptor FD, retrying if
interrupted or if a partial write(read) occurs. Return the number
of bytes transferred.
When writing, set errno if fewer than COUNT bytes are written.
When reading, if fewer than COUNT bytes are read, you must examine
errno to distinguish failure from EOF (errno == 0). */
size_t
full_rw (int fd, const void *buf, size_t count)
{
size_t total = 0;
const char *ptr = (const char *) buf;
while (count > 0)
{
size_t n_rw = safe_rw (fd, ptr, count);
if (n_rw == (size_t) -1)
break;
if (n_rw == 0)
{
errno = ZERO_BYTE_TRANSFER_ERRNO;
break;
}
total += n_rw;
ptr += n_rw;
count -= n_rw;
}
return total;
}

View File

@ -1,34 +0,0 @@
/* An interface to write() that writes all it is asked to write.
Copyright (C) 2002-2003 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Write COUNT bytes at BUF to descriptor FD, retrying if interrupted
or if partial writes occur. Return the number of bytes successfully
written, setting errno if that is less than COUNT. */
extern size_t full_write (int fd, const void *buf, size_t count);
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,225 +0,0 @@
/* Declarations for getopt.
Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007
Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _GETOPT_H
#ifndef __need_getopt
# define _GETOPT_H 1
#endif
/* Standalone applications should #define __GETOPT_PREFIX to an
identifier that prefixes the external functions and variables
defined in this header. When this happens, include the
headers that might declare getopt so that they will not cause
confusion if included after this file. Then systematically rename
identifiers so that they do not collide with the system functions
and variables. Renaming avoids problems with some compilers and
linkers. */
#if defined __GETOPT_PREFIX && !defined __need_getopt
# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# undef __need_getopt
# undef getopt
# undef getopt_long
# undef getopt_long_only
# undef optarg
# undef opterr
# undef optind
# undef optopt
# define __GETOPT_CONCAT(x, y) x ## y
# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
# define getopt __GETOPT_ID (getopt)
# define getopt_long __GETOPT_ID (getopt_long)
# define getopt_long_only __GETOPT_ID (getopt_long_only)
# define optarg __GETOPT_ID (optarg)
# define opterr __GETOPT_ID (opterr)
# define optind __GETOPT_ID (optind)
# define optopt __GETOPT_ID (optopt)
#endif
/* Standalone applications get correct prototypes for getopt_long and
getopt_long_only; they declare "char **argv". libc uses prototypes
with "char *const *argv" that are incorrect because getopt_long and
getopt_long_only can permute argv; this is required for backward
compatibility (e.g., for LSB 2.0.1).
This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
but it caused redefinition warnings if both unistd.h and getopt.h were
included, since unistd.h includes getopt.h having previously defined
__need_getopt.
The only place where __getopt_argv_const is used is in definitions
of getopt_long and getopt_long_only below, but these are visible
only if __need_getopt is not defined, so it is quite safe to rewrite
the conditional as follows:
*/
#if !defined __need_getopt
# if defined __GETOPT_PREFIX
# define __getopt_argv_const /* empty */
# else
# define __getopt_argv_const const
# endif
#endif
/* If __GNU_LIBRARY__ is not already defined, either we are being used
standalone, or this is the first header included in the source file.
If we are being used with glibc, we need to include <features.h>, but
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
not defined, include <ctype.h>, which will pull in <features.h> for us
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
doesn't flood the namespace with stuff the way some other headers do.) */
#if !defined __GNU_LIBRARY__
# include <ctype.h>
#endif
#ifndef __THROW
# ifndef __GNUC_PREREQ
# define __GNUC_PREREQ(maj, min) (0)
# endif
# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW throw ()
# else
# define __THROW
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
#ifndef __need_getopt
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
const char *name;
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
# define no_argument 0
# define required_argument 1
# define optional_argument 2
#endif /* need getopt */
/* Get definitions and prototypes for functions to process the
arguments in ARGV (ARGC of them, minus the program name) for
options given in OPTS.
Return the option character from OPTS just read. Return -1 when
there are no more options. For unrecognized options, or options
missing arguments, `optopt' is set to the option letter, and '?' is
returned.
The OPTS string is a list of characters which are recognized option
letters, optionally followed by colons, specifying that that letter
takes an argument, to be placed in `optarg'.
If a letter in OPTS is followed by two colons, its argument is
optional. This behavior is specific to the GNU `getopt'.
The argument `--' causes premature termination of argument
scanning, explicitly telling `getopt' that there are no more
options.
If OPTS begins with `-', then non-option arguments are treated as
arguments to the option '\1'. This behavior is specific to the GNU
`getopt'. If OPTS begins with `+', or POSIXLY_CORRECT is set in
the environment, then do not permute arguments. */
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
__THROW;
#ifndef __need_getopt
extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
#endif
#ifdef __cplusplus
}
#endif
/* Make sure we later can get all the definitions and declarations. */
#undef __need_getopt
#endif /* getopt.h */

View File

@ -1,170 +0,0 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006
Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifdef _LIBC
# include <getopt.h>
#else
# include <config.h>
# include "getopt.h"
#endif
#include "getopt_int.h"
#include <stdio.h>
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
#endif
#ifndef NULL
#define NULL 0
#endif
int
getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal (argc, (char **) argv, options, long_options,
opt_index, 0, 0);
}
int
_getopt_long_r (int argc, char **argv, const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
0, 0, d);
}
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
If an option that starts with '-' (not '--') doesn't match a long option,
but does match a short option, it is parsed as a short option
instead. */
int
getopt_long_only (int argc, char *__getopt_argv_const *argv,
const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal (argc, (char **) argv, options, long_options,
opt_index, 1, 0);
}
int
_getopt_long_only_r (int argc, char **argv, const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
1, 0, d);
}
#ifdef TEST
#include <stdio.h>
int
main (int argc, char **argv)
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
{
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'd':
printf ("option d with value `%s'\n", optarg);
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
#endif /* TEST */

View File

@ -1,130 +0,0 @@
/* Internal declarations for getopt.
Copyright (C) 1989-1994,1996-1999,2001,2003,2004
Free Software Foundation, Inc.
This file is part of the GNU C Library.
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _GETOPT_INT_H
#define _GETOPT_INT_H 1
extern int _getopt_internal (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, int __posixly_correct);
/* Reentrant versions which can handle parsing multiple argument
vectors at the same time. */
/* Data type for reentrant functions. */
struct _getopt_data
{
/* These have exactly the same meaning as the corresponding global
variables, except that they are used for the reentrant
versions of getopt. */
int optind;
int opterr;
int optopt;
char *optarg;
/* Internal members. */
/* True if the internal members have been initialized. */
int __initialized;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
This allows us to pick up the scan where we left off.
If this is zero, or a null string, it means resume the scan
by advancing to the next ARGV-element. */
char *__nextchar;
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters, or by calling getopt.
PERMUTE is the default. We permute the contents of ARGV as we
scan, so that eventually all the non-options are at the end.
This allows options to be given in any order, even with programs
that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were
written to expect options and other ARGV-elements in any order
and that care about the ordering of the two. We describe each
non-option ARGV-element as if it were the argument of an option
with character code 1. Using `-' as the first character of the
list of option characters selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} __ordering;
/* If the POSIXLY_CORRECT environment variable is set
or getopt was called. */
int __posixly_correct;
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
been skipped. `first_nonopt' is the index in ARGV of the first
of them; `last_nonopt' is the index after the last of them. */
int __first_nonopt;
int __last_nonopt;
#if defined _LIBC && defined USE_NONOPTION_FLAGS
int __nonoption_flags_max_len;
int __nonoption_flags_len;
# endif
};
/* The initializer is necessary to set OPTIND and OPTERR to their
default values and to clear the initialization flag. */
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
extern int _getopt_internal_r (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, int __posixly_correct,
struct _getopt_data *__data);
extern int _getopt_long_r (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
struct _getopt_data *__data);
extern int _getopt_long_only_r (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts,
int *__longind,
struct _getopt_data *__data);
#endif /* getopt_int.h */

View File

@ -1,270 +0,0 @@
/* Convenience header for conditional use of GNU <libintl.h>.
Copyright (C) 1995-1998, 2000-2002, 2004-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 Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _LIBGETTEXT_H
#define _LIBGETTEXT_H 1
/* NLS can be disabled through the configure --disable-nls option. */
#if ENABLE_NLS
/* Get declarations of GNU message catalog functions. */
# include <libintl.h>
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
the gettext() and ngettext() macros. This is an alternative to calling
textdomain(), and is useful for libraries. */
# ifdef DEFAULT_TEXT_DOMAIN
# undef gettext
# define gettext(Msgid) \
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
# undef ngettext
# define ngettext(Msgid1, Msgid2, N) \
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
# endif
#else
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
chokes if dcgettext is defined as a macro. So include it now, to make
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
as well because people using "gettext.h" will not include <libintl.h>,
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
is OK. */
#if defined(__sun)
# include <locale.h>
#endif
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
it now, to make later inclusions of <libintl.h> a NOP. */
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
# include <cstdlib>
# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
# include <libintl.h>
# endif
#endif
/* Disabled NLS.
The casts to 'const char *' serve the purpose of producing warnings
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# define gettext(Msgid) ((const char *) (Msgid))
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
# define dcgettext(Domainname, Msgid, Category) \
((void) (Category), dgettext (Domainname, Msgid))
# define ngettext(Msgid1, Msgid2, N) \
((N) == 1 \
? ((void) (Msgid2), (const char *) (Msgid1)) \
: ((void) (Msgid1), (const char *) (Msgid2)))
# define dngettext(Domainname, Msgid1, Msgid2, N) \
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
# define textdomain(Domainname) ((const char *) (Domainname))
# define bindtextdomain(Domainname, Dirname) \
((void) (Domainname), (const char *) (Dirname))
# define bind_textdomain_codeset(Domainname, Codeset) \
((void) (Domainname), (const char *) (Codeset))
#endif
/* A pseudo function call that serves as a marker for the automated
extraction of messages, but does not call gettext(). The run-time
translation is done at a different place in the code.
The argument, String, should be a literal string. Concatenated strings
and other string expressions won't work.
The macro's expansion is not parenthesized, so that it is suitable as
initializer for static 'char[]' or 'const char[]' variables. */
#define gettext_noop(String) String
/* The separator between msgctxt and msgid in a .mo file. */
#define GETTEXT_CONTEXT_GLUE "\004"
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
short and rarely need to change.
The letter 'p' stands for 'particular' or 'special'. */
#ifdef DEFAULT_TEXT_DOMAIN
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#else
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#endif
#define dpgettext(Domainname, Msgctxt, Msgid) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
#ifdef DEFAULT_TEXT_DOMAIN
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#else
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#endif
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
pgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
int category)
{
const char *translation = dcgettext (domain, msg_ctxt_id, category);
if (translation == msg_ctxt_id)
return msgid;
else
return translation;
}
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
npgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
const char *translation =
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
if (translation == msg_ctxt_id || translation == msgid_plural)
return (n == 1 ? msgid : msgid_plural);
else
return translation;
}
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
can be arbitrary expressions. But for string literals these macros are
less efficient than those above. */
#include <string.h>
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
(((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
/* || __STDC_VERSION__ >= 199901L */ )
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
#include <stdlib.h>
#endif
#define pgettext_expr(Msgctxt, Msgid) \
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
dcpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcgettext (domain, msg_ctxt_id, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (translation != msg_ctxt_id)
return translation;
}
return msgid;
}
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
dcnpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (!(translation == msg_ctxt_id || translation == msgid_plural))
return translation;
}
return (n == 1 ? msgid : msgid_plural);
}
#endif /* _LIBGETTEXT_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,87 +0,0 @@
/* hash - hashing table processing.
Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
Written by Jim Meyering <meyering@ascend.com>, 1998.
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* A generic hash table package. */
/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
obstacks instead of malloc, and recompile `hash.c' with same setting. */
#ifndef HASH_H_
# define HASH_H_
# include <stdio.h>
# include <stdbool.h>
typedef size_t (*Hash_hasher) (const void *, size_t);
typedef bool (*Hash_comparator) (const void *, const void *);
typedef void (*Hash_data_freer) (void *);
typedef bool (*Hash_processor) (void *, void *);
struct hash_entry
{
void *data;
struct hash_entry *next;
};
struct hash_tuning
{
/* This structure is mainly used for `hash_initialize', see the block
documentation of `hash_reset_tuning' for more complete comments. */
float shrink_threshold; /* ratio of used buckets to trigger a shrink */
float shrink_factor; /* ratio of new smaller size to original size */
float growth_threshold; /* ratio of used buckets to trigger a growth */
float growth_factor; /* ratio of new bigger size to original size */
bool is_n_buckets; /* if CANDIDATE really means table size */
};
typedef struct hash_tuning Hash_tuning;
struct hash_table;
typedef struct hash_table Hash_table;
/* Information and lookup. */
size_t hash_get_n_buckets (const Hash_table *);
size_t hash_get_n_buckets_used (const Hash_table *);
size_t hash_get_n_entries (const Hash_table *);
size_t hash_get_max_bucket_length (const Hash_table *);
bool hash_table_ok (const Hash_table *);
void hash_print_statistics (const Hash_table *, FILE *);
void *hash_lookup (const Hash_table *, const void *);
/* Walking. */
void *hash_get_first (const Hash_table *);
void *hash_get_next (const Hash_table *, const void *);
size_t hash_get_entries (const Hash_table *, void **, size_t);
size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
/* Allocation and clean-up. */
size_t hash_string (const char *, size_t);
void hash_reset_tuning (Hash_tuning *);
Hash_table *hash_initialize (size_t, const Hash_tuning *,
Hash_hasher, Hash_comparator,
Hash_data_freer);
void hash_clear (Hash_table *);
void hash_free (Hash_table *);
/* Insertion and deletion. */
bool hash_rehash (Hash_table *, size_t);
void *hash_insert (Hash_table *, const void *);
void *hash_delete (Hash_table *, const void *);
#endif

View File

@ -1,57 +0,0 @@
/* malloc() function that is glibc compatible.
Copyright (C) 1997, 1998, 2006, 2007 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 Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* written by Jim Meyering and Bruno Haible */
#include <config.h>
/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
#ifdef malloc
# define NEED_MALLOC_GNU
# undef malloc
#endif
/* Specification. */
#include <stdlib.h>
#include <errno.h>
/* Call the system's malloc below. */
#undef malloc
/* Allocate an N-byte block of memory from the heap.
If N is zero, allocate a 1-byte block. */
void *
rpl_malloc (size_t n)
{
void *result;
#ifdef NEED_MALLOC_GNU
if (n == 0)
n = 1;
#endif
result = malloc (n);
#if !HAVE_MALLOC_POSIX
if (result == NULL)
errno = ENOMEM;
#endif
return result;
}

View File

@ -1,386 +0,0 @@
/* Convert multibyte character to wide character.
Copyright (C) 1999-2002, 2005-2009 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2008.
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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <wchar.h>
#if GNULIB_defined_mbstate_t
/* Implement mbrtowc() on top of mbtowc(). */
# include <errno.h>
# include <stdlib.h>
# include "localcharset.h"
# include "streq.h"
# include "verify.h"
verify (sizeof (mbstate_t) >= 4);
static char internal_state[4];
size_t
mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
{
char *pstate = (char *)ps;
if (pstate == NULL)
pstate = internal_state;
if (s == NULL)
{
pwc = NULL;
s = "";
n = 1;
}
if (n == 0)
return (size_t)(-2);
/* Here n > 0. */
{
size_t nstate = pstate[0];
char buf[4];
const char *p;
size_t m;
switch (nstate)
{
case 0:
p = s;
m = n;
break;
case 3:
buf[2] = pstate[3];
/*FALLTHROUGH*/
case 2:
buf[1] = pstate[2];
/*FALLTHROUGH*/
case 1:
buf[0] = pstate[1];
p = buf;
m = nstate;
buf[m++] = s[0];
if (n >= 2 && m < 4)
{
buf[m++] = s[1];
if (n >= 3 && m < 4)
buf[m++] = s[2];
}
break;
default:
errno = EINVAL;
return (size_t)(-1);
}
/* Here m > 0. */
# if __GLIBC__
/* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
mbtowc (NULL, NULL, 0);
# endif
{
int res = mbtowc (pwc, p, m);
if (res >= 0)
{
if (pwc != NULL && ((*pwc == 0) != (res == 0)))
abort ();
if (nstate >= (res > 0 ? res : 1))
abort ();
res -= nstate;
pstate[0] = 0;
return res;
}
/* mbtowc does not distinguish between invalid and incomplete multibyte
sequences. But mbrtowc needs to make this distinction.
There are two possible approaches:
- Use iconv() and its return value.
- Use built-in knowledge about the possible encodings.
Given the low quality of implementation of iconv() on the systems that
lack mbrtowc(), we use the second approach.
The possible encodings are:
- 8-bit encodings,
- EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
- UTF-8.
Use specialized code for each. */
if (m >= 4 || m >= MB_CUR_MAX)
goto invalid;
/* Here MB_CUR_MAX > 1 and 0 < m < 4. */
{
const char *encoding = locale_charset ();
if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
{
/* Cf. unistr/u8-mblen.c. */
unsigned char c = (unsigned char) p[0];
if (c >= 0xc2)
{
if (c < 0xe0)
{
if (m == 1)
goto incomplete;
}
else if (c < 0xf0)
{
if (m == 1)
goto incomplete;
if (m == 2)
{
unsigned char c2 = (unsigned char) p[1];
if ((c2 ^ 0x80) < 0x40
&& (c >= 0xe1 || c2 >= 0xa0)
&& (c != 0xed || c2 < 0xa0))
goto incomplete;
}
}
else if (c <= 0xf4)
{
if (m == 1)
goto incomplete;
else /* m == 2 || m == 3 */
{
unsigned char c2 = (unsigned char) p[1];
if ((c2 ^ 0x80) < 0x40
&& (c >= 0xf1 || c2 >= 0x90)
&& (c < 0xf4 || (c == 0xf4 && c2 < 0x90)))
{
if (m == 2)
goto incomplete;
else /* m == 3 */
{
unsigned char c3 = (unsigned char) p[2];
if ((c3 ^ 0x80) < 0x40)
goto incomplete;
}
}
}
}
}
goto invalid;
}
/* As a reference for this code, you can use the GNU libiconv
implementation. Look for uses of the RET_TOOFEW macro. */
if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
{
if (m == 1)
{
unsigned char c = (unsigned char) p[0];
if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
goto incomplete;
}
if (m == 2)
{
unsigned char c = (unsigned char) p[0];
if (c == 0x8f)
{
unsigned char c2 = (unsigned char) p[1];
if (c2 >= 0xa1 && c2 < 0xff)
goto incomplete;
}
}
goto invalid;
}
if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
|| STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
|| STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
{
if (m == 1)
{
unsigned char c = (unsigned char) p[0];
if (c >= 0xa1 && c < 0xff)
goto incomplete;
}
goto invalid;
}
if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
{
if (m == 1)
{
unsigned char c = (unsigned char) p[0];
if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
goto incomplete;
}
else /* m == 2 || m == 3 */
{
unsigned char c = (unsigned char) p[0];
if (c == 0x8e)
goto incomplete;
}
goto invalid;
}
if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
{
if (m == 1)
{
unsigned char c = (unsigned char) p[0];
if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
goto incomplete;
}
else /* m == 2 || m == 3 */
{
unsigned char c = (unsigned char) p[0];
if (c >= 0x90 && c <= 0xe3)
{
unsigned char c2 = (unsigned char) p[1];
if (c2 >= 0x30 && c2 <= 0x39)
{
if (m == 2)
goto incomplete;
else /* m == 3 */
{
unsigned char c3 = (unsigned char) p[2];
if (c3 >= 0x81 && c3 <= 0xfe)
goto incomplete;
}
}
}
}
goto invalid;
}
if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
{
if (m == 1)
{
unsigned char c = (unsigned char) p[0];
if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
|| (c >= 0xf0 && c <= 0xf9))
goto incomplete;
}
goto invalid;
}
/* An unknown multibyte encoding. */
goto incomplete;
}
incomplete:
{
size_t k = nstate;
/* Here 0 <= k < m < 4. */
pstate[++k] = s[0];
if (k < m)
{
pstate[++k] = s[1];
if (k < m)
pstate[++k] = s[2];
}
if (k != m)
abort ();
}
pstate[0] = m;
return (size_t)(-2);
invalid:
errno = EILSEQ;
/* The conversion state is undefined, says POSIX. */
return (size_t)(-1);
}
}
}
#else
/* Override the system's mbrtowc() function. */
# undef mbrtowc
size_t
rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
{
# if MBRTOWC_NULL_ARG_BUG || MBRTOWC_RETVAL_BUG
if (s == NULL)
{
pwc = NULL;
s = "";
n = 1;
}
# endif
# if MBRTOWC_RETVAL_BUG
{
static mbstate_t internal_state;
/* Override mbrtowc's internal state. We can not call mbsinit() on the
hidden internal state, but we can call it on our variable. */
if (ps == NULL)
ps = &internal_state;
if (!mbsinit (ps))
{
/* Parse the rest of the multibyte character byte for byte. */
size_t count = 0;
for (; n > 0; s++, n--)
{
wchar_t wc;
size_t ret = mbrtowc (&wc, s, 1, ps);
if (ret == (size_t)(-1))
return (size_t)(-1);
count++;
if (ret != (size_t)(-2))
{
/* The multibyte character has been completed. */
if (pwc != NULL)
*pwc = wc;
return (wc == 0 ? 0 : count);
}
}
return (size_t)(-2);
}
}
# endif
# if MBRTOWC_NUL_RETVAL_BUG
{
wchar_t wc;
size_t ret = mbrtowc (&wc, s, n, ps);
if (ret != (size_t)(-1) && ret != (size_t)(-2))
{
if (pwc != NULL)
*pwc = wc;
if (wc == 0)
ret = 0;
}
return ret;
}
# else
return mbrtowc (pwc, s, n, ps);
# endif
}
#endif

View File

@ -1,172 +0,0 @@
/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006, 2008
Free Software Foundation, Inc.
Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
with help from Dan Sahlin (dan@sics.se) and
commentary by Jim Blandy (jimb@ai.mit.edu);
adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
and implemented by Roland McGrath (roland@ai.mit.edu).
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
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
Free Software Foundation; either version 3 of the License, or any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _LIBC
# include <config.h>
#endif
#include <string.h>
#include <stddef.h>
#if defined _LIBC
# include <memcopy.h>
#else
# define reg_char char
#endif
#include <limits.h>
#if HAVE_BP_SYM_H || defined _LIBC
# include <bp-sym.h>
#else
# define BP_SYM(sym) sym
#endif
#undef __memchr
#ifdef _LIBC
# undef memchr
#endif
#ifndef weak_alias
# define __memchr memchr
#endif
/* Search no more than N bytes of S for C. */
void *
__memchr (void const *s, int c_in, size_t n)
{
/* On 32-bit hardware, choosing longword to be a 32-bit unsigned
long instead of a 64-bit uintmax_t tends to give better
performance. On 64-bit hardware, unsigned long is generally 64
bits already. Change this typedef to experiment with
performance. */
typedef unsigned long int longword;
const unsigned char *char_ptr;
const longword *longword_ptr;
longword repeated_one;
longword repeated_c;
unsigned reg_char c;
c = (unsigned char) c_in;
/* Handle the first few bytes by reading one byte at a time.
Do this until CHAR_PTR is aligned on a longword boundary. */
for (char_ptr = (const unsigned char *) s;
n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
--n, ++char_ptr)
if (*char_ptr == c)
return (void *) char_ptr;
longword_ptr = (const longword *) char_ptr;
/* All these elucidatory comments refer to 4-byte longwords,
but the theory applies equally well to any size longwords. */
/* Compute auxiliary longword values:
repeated_one is a value which has a 1 in every byte.
repeated_c has c in every byte. */
repeated_one = 0x01010101;
repeated_c = c | (c << 8);
repeated_c |= repeated_c << 16;
if (0xffffffffU < (longword) -1)
{
repeated_one |= repeated_one << 31 << 1;
repeated_c |= repeated_c << 31 << 1;
if (8 < sizeof (longword))
{
size_t i;
for (i = 64; i < sizeof (longword) * 8; i *= 2)
{
repeated_one |= repeated_one << i;
repeated_c |= repeated_c << i;
}
}
}
/* Instead of the traditional loop which tests each byte, we will test a
longword at a time. The tricky part is testing if *any of the four*
bytes in the longword in question are equal to c. We first use an xor
with repeated_c. This reduces the task to testing whether *any of the
four* bytes in longword1 is zero.
We compute tmp =
((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
That is, we perform the following operations:
1. Subtract repeated_one.
2. & ~longword1.
3. & a mask consisting of 0x80 in every byte.
Consider what happens in each byte:
- If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
and step 3 transforms it into 0x80. A carry can also be propagated
to more significant bytes.
- If a byte of longword1 is nonzero, let its lowest 1 bit be at
position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
the byte ends in a single bit of value 0 and k bits of value 1.
After step 2, the result is just k bits of value 1: 2^k - 1. After
step 3, the result is 0. And no carry is produced.
So, if longword1 has only non-zero bytes, tmp is zero.
Whereas if longword1 has a zero byte, call j the position of the least
significant zero byte. Then the result has a zero at positions 0, ...,
j-1 and a 0x80 at position j. We cannot predict the result at the more
significant bytes (positions j+1..3), but it does not matter since we
already have a non-zero bit at position 8*j+7.
So, the test whether any byte in longword1 is zero is equivalent to
testing whether tmp is nonzero. */
while (n >= sizeof (longword))
{
longword longword1 = *longword_ptr ^ repeated_c;
if ((((longword1 - repeated_one) & ~longword1)
& (repeated_one << 7)) != 0)
break;
longword_ptr++;
n -= sizeof (longword);
}
char_ptr = (const unsigned char *) longword_ptr;
/* At this point, we know that either n < sizeof (longword), or one of the
sizeof (longword) bytes starting at char_ptr is == c. On little-endian
machines, we could determine the first such byte without any further
memory accesses, just by looking at the tmp result from the last loop
iteration. But this does not work on big-endian machines. Choose code
that works in both cases. */
for (; n > 0; --n, ++char_ptr)
{
if (*char_ptr == c)
return (void *) char_ptr;
}
return NULL;
}
#ifdef weak_alias
weak_alias (__memchr, BP_SYM (memchr))
#endif

View File

@ -1,60 +0,0 @@
/* MIN, MAX macros.
Copyright (C) 1995, 1998, 2001, 2003, 2005 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 Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _MINMAX_H
#define _MINMAX_H
/* Note: MIN, MAX are also defined in <sys/param.h> on some systems
(glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about
MIN, MAX macro redefinitions on some systems; the workaround is to
#include this file as the last one among the #include list. */
/* Before we define the following symbols we get the <limits.h> file
since otherwise we get redefinitions on some systems if <limits.h> is
included after this file. Likewise for <sys/param.h>.
If more than one of these system headers define MIN and MAX, pick just
one of the headers (because the definitions most likely are the same). */
#if HAVE_MINMAX_IN_LIMITS_H
# include <limits.h>
#elif HAVE_MINMAX_IN_SYS_PARAM_H
# include <sys/param.h>
#endif
/* Note: MIN and MAX should be used with two arguments of the
same type. They might not return the minimum and maximum of their two
arguments, if the arguments have different types or have unusual
floating-point values. For example, on a typical host with 32-bit 'int',
64-bit 'long long', and 64-bit IEEE 754 'double' types:
MAX (-1, 2147483648) returns 4294967295.
MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0.
MAX (NaN, 0.0) returns 0.0.
MAX (+0.0, -0.0) returns -0.0.
and in each case the answer is in some sense bogus. */
/* MAX(a,b) returns the maximum of A and B. */
#ifndef MAX
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
/* MIN(a,b) returns the minimum of A and B. */
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#endif /* _MINMAX_H */

View File

@ -1,40 +0,0 @@
/* quote.c - quote arguments for output
Copyright (C) 1998, 1999, 2000, 2001, 2003, 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert <eggert@twinsun.com> */
#include <config.h>
#include "quotearg.h"
#include "quote.h"
/* Return an unambiguous printable representation of NAME,
allocated in slot N, suitable for diagnostics. */
char const *
quote_n (int n, char const *name)
{
return quotearg_n_style (n, locale_quoting_style, name);
}
/* Return an unambiguous printable representation of NAME,
suitable for diagnostics. */
char const *
quote (char const *name)
{
return quote_n (0, name);
}

View File

@ -1,21 +0,0 @@
/* quote.h - prototypes for quote.c
Copyright (C) 1998, 1999, 2000, 2001, 2003 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
char const *quote_n (int n, char const *name);
char const *quote (char const *name);

View File

@ -1,799 +0,0 @@
/* quotearg.c - quote arguments for output
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007,
2008 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert <eggert@twinsun.com> */
#include <config.h>
#include "quotearg.h"
#include "xalloc.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#define INT_BITS (sizeof (int) * CHAR_BIT)
struct quoting_options
{
/* Basic quoting style. */
enum quoting_style style;
/* Additional flags. Bitwise combination of enum quoting_flags. */
int flags;
/* Quote the characters indicated by this bit vector even if the
quoting style would not normally require them to be quoted. */
unsigned int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
};
/* Names of quoting styles. */
char const *const quoting_style_args[] =
{
"literal",
"shell",
"shell-always",
"c",
"c-maybe",
"escape",
"locale",
"clocale",
0
};
/* Correspondences to quoting style names. */
enum quoting_style const quoting_style_vals[] =
{
literal_quoting_style,
shell_quoting_style,
shell_always_quoting_style,
c_quoting_style,
c_maybe_quoting_style,
escape_quoting_style,
locale_quoting_style,
clocale_quoting_style
};
/* The default quoting options. */
static struct quoting_options default_quoting_options;
/* Allocate a new set of quoting options, with contents initially identical
to O if O is not null, or to the default if O is null.
It is the caller's responsibility to free the result. */
struct quoting_options *
clone_quoting_options (struct quoting_options *o)
{
int e = errno;
struct quoting_options *p = xmemdup (o ? o : &default_quoting_options,
sizeof *o);
errno = e;
return p;
}
/* Get the value of O's quoting style. If O is null, use the default. */
enum quoting_style
get_quoting_style (struct quoting_options *o)
{
return (o ? o : &default_quoting_options)->style;
}
/* In O (or in the default if O is null),
set the value of the quoting style to S. */
void
set_quoting_style (struct quoting_options *o, enum quoting_style s)
{
(o ? o : &default_quoting_options)->style = s;
}
/* In O (or in the default if O is null),
set the value of the quoting options for character C to I.
Return the old value. Currently, the only values defined for I are
0 (the default) and 1 (which means to quote the character even if
it would not otherwise be quoted). */
int
set_char_quoting (struct quoting_options *o, char c, int i)
{
unsigned char uc = c;
unsigned int *p =
(o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
int shift = uc % INT_BITS;
int r = (*p >> shift) & 1;
*p ^= ((i & 1) ^ r) << shift;
return r;
}
/* In O (or in the default if O is null),
set the value of the quoting options flag to I, which can be a
bitwise combination of enum quoting_flags, or 0 for default
behavior. Return the old value. */
int
set_quoting_flags (struct quoting_options *o, int i)
{
int r;
if (!o)
o = &default_quoting_options;
r = o->flags;
o->flags = i;
return r;
}
/* Return quoting options for STYLE, with no extra quoting. */
static struct quoting_options
quoting_options_from_style (enum quoting_style style)
{
struct quoting_options o;
o.style = style;
o.flags = 0;
memset (o.quote_these_too, 0, sizeof o.quote_these_too);
return o;
}
/* MSGID approximates a quotation mark. Return its translation if it
has one; otherwise, return either it or "\"", depending on S. */
static char const *
gettext_quote (char const *msgid, enum quoting_style s)
{
char const *translation = _(msgid);
if (translation == msgid && s == clocale_quoting_style)
translation = "\"";
return translation;
}
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
argument ARG (of size ARGSIZE), using QUOTING_STYLE, FLAGS, and
QUOTE_THESE_TOO to control quoting.
Terminate the output with a null character, and return the written
size of the output, not counting the terminating null.
If BUFFERSIZE is too small to store the output string, return the
value that would have been returned had BUFFERSIZE been large enough.
If ARGSIZE is SIZE_MAX, use the string length of the argument for ARGSIZE.
This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
ARGSIZE, O), except it breaks O into its component pieces and is
not careful about errno. */
static size_t
quotearg_buffer_restyled (char *buffer, size_t buffersize,
char const *arg, size_t argsize,
enum quoting_style quoting_style, int flags,
unsigned int const *quote_these_too)
{
size_t i;
size_t len = 0;
char const *quote_string = 0;
size_t quote_string_len = 0;
bool backslash_escapes = false;
bool unibyte_locale = MB_CUR_MAX == 1;
bool elide_outer_quotes = (flags & QA_ELIDE_OUTER_QUOTES) != 0;
#define STORE(c) \
do \
{ \
if (len < buffersize) \
buffer[len] = (c); \
len++; \
} \
while (0)
switch (quoting_style)
{
case c_maybe_quoting_style:
quoting_style = c_quoting_style;
elide_outer_quotes = true;
/* Fall through. */
case c_quoting_style:
if (!elide_outer_quotes)
STORE ('"');
backslash_escapes = true;
quote_string = "\"";
quote_string_len = 1;
break;
case escape_quoting_style:
backslash_escapes = true;
elide_outer_quotes = false;
break;
case locale_quoting_style:
case clocale_quoting_style:
{
/* TRANSLATORS:
Get translations for open and closing quotation marks.
The message catalog should translate "`" to a left
quotation mark suitable for the locale, and similarly for
"'". If the catalog has no translation,
locale_quoting_style quotes `like this', and
clocale_quoting_style quotes "like this".
For example, an American English Unicode locale should
translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and
should translate "'" to U+201D (RIGHT DOUBLE QUOTATION
MARK). A British English Unicode locale should instead
translate these to U+2018 (LEFT SINGLE QUOTATION MARK) and
U+2019 (RIGHT SINGLE QUOTATION MARK), respectively.
If you don't know what to put here, please see
<http://en.wikipedia.org/wiki/Quotation_mark#Glyphs>
and use glyphs suitable for your language. */
char const *left = gettext_quote (N_("`"), quoting_style);
char const *right = gettext_quote (N_("'"), quoting_style);
if (!elide_outer_quotes)
for (quote_string = left; *quote_string; quote_string++)
STORE (*quote_string);
backslash_escapes = true;
quote_string = right;
quote_string_len = strlen (quote_string);
}
break;
case shell_quoting_style:
quoting_style = shell_always_quoting_style;
elide_outer_quotes = true;
/* Fall through. */
case shell_always_quoting_style:
if (!elide_outer_quotes)
STORE ('\'');
quote_string = "'";
quote_string_len = 1;
break;
case literal_quoting_style:
elide_outer_quotes = false;
break;
default:
abort ();
}
for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++)
{
unsigned char c;
unsigned char esc;
if (backslash_escapes
&& quote_string_len
&& i + quote_string_len <= argsize
&& memcmp (arg + i, quote_string, quote_string_len) == 0)
{
if (elide_outer_quotes)
goto force_outer_quoting_style;
STORE ('\\');
}
c = arg[i];
switch (c)
{
case '\0':
if (backslash_escapes)
{
if (elide_outer_quotes)
goto force_outer_quoting_style;
STORE ('\\');
if (i + 1 < argsize && '0' <= arg[i + 1] && arg[i + 1] <= '9')
{
STORE ('0');
STORE ('0');
}
c = '0';
}
else if (flags & QA_ELIDE_NULL_BYTES)
continue;
break;
case '?':
switch (quoting_style)
{
case shell_always_quoting_style:
if (elide_outer_quotes)
goto force_outer_quoting_style;
break;
case c_quoting_style:
if ((flags & QA_SPLIT_TRIGRAPHS)
&& i + 2 < argsize && arg[i + 1] == '?')
switch (arg[i + 2])
{
case '!': case '\'':
case '(': case ')': case '-': case '/':
case '<': case '=': case '>':
/* Escape the second '?' in what would otherwise be
a trigraph. */
if (elide_outer_quotes)
goto force_outer_quoting_style;
c = arg[i + 2];
i += 2;
STORE ('?');
STORE ('"');
STORE ('"');
STORE ('?');
break;
default:
break;
}
break;
default:
break;
}
break;
case '\a': esc = 'a'; goto c_escape;
case '\b': esc = 'b'; goto c_escape;
case '\f': esc = 'f'; goto c_escape;
case '\n': esc = 'n'; goto c_and_shell_escape;
case '\r': esc = 'r'; goto c_and_shell_escape;
case '\t': esc = 't'; goto c_and_shell_escape;
case '\v': esc = 'v'; goto c_escape;
case '\\': esc = c;
/* No need to escape the escape if we are trying to elide
outer quotes and nothing else is problematic. */
if (backslash_escapes && elide_outer_quotes && quote_string_len)
goto store_c;
c_and_shell_escape:
if (quoting_style == shell_always_quoting_style
&& elide_outer_quotes)
goto force_outer_quoting_style;
/* Fall through. */
c_escape:
if (backslash_escapes)
{
c = esc;
goto store_escape;
}
break;
case '{': case '}': /* sometimes special if isolated */
if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
break;
/* Fall through. */
case '#': case '~':
if (i != 0)
break;
/* Fall through. */
case ' ':
case '!': /* special in bash */
case '"': case '$': case '&':
case '(': case ')': case '*': case ';':
case '<':
case '=': /* sometimes special in 0th or (with "set -k") later args */
case '>': case '[':
case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
case '`': case '|':
/* A shell special character. In theory, '$' and '`' could
be the first bytes of multibyte characters, which means
we should check them with mbrtowc, but in practice this
doesn't happen so it's not worth worrying about. */
if (quoting_style == shell_always_quoting_style
&& elide_outer_quotes)
goto force_outer_quoting_style;
break;
case '\'':
if (quoting_style == shell_always_quoting_style)
{
if (elide_outer_quotes)
goto force_outer_quoting_style;
STORE ('\'');
STORE ('\\');
STORE ('\'');
}
break;
case '%': case '+': case ',': case '-': case '.': case '/':
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9': case ':':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
case 'o': case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
/* These characters don't cause problems, no matter what the
quoting style is. They cannot start multibyte sequences. */
break;
default:
/* If we have a multibyte sequence, copy it until we reach
its end, find an error, or come back to the initial shift
state. For C-like styles, if the sequence has
unprintable characters, escape the whole sequence, since
we can't easily escape single characters within it. */
{
/* Length of multibyte sequence found so far. */
size_t m;
bool printable;
if (unibyte_locale)
{
m = 1;
printable = isprint (c) != 0;
}
else
{
mbstate_t mbstate;
memset (&mbstate, 0, sizeof mbstate);
m = 0;
printable = true;
if (argsize == SIZE_MAX)
argsize = strlen (arg);
do
{
wchar_t w;
size_t bytes = mbrtowc (&w, &arg[i + m],
argsize - (i + m), &mbstate);
if (bytes == 0)
break;
else if (bytes == (size_t) -1)
{
printable = false;
break;
}
else if (bytes == (size_t) -2)
{
printable = false;
while (i + m < argsize && arg[i + m])
m++;
break;
}
else
{
/* Work around a bug with older shells that "see" a '\'
that is really the 2nd byte of a multibyte character.
In practice the problem is limited to ASCII
chars >= '@' that are shell special chars. */
if ('[' == 0x5b && elide_outer_quotes
&& quoting_style == shell_always_quoting_style)
{
size_t j;
for (j = 1; j < bytes; j++)
switch (arg[i + m + j])
{
case '[': case '\\': case '^':
case '`': case '|':
goto force_outer_quoting_style;
default:
break;
}
}
if (! iswprint (w))
printable = false;
m += bytes;
}
}
while (! mbsinit (&mbstate));
}
if (1 < m || (backslash_escapes && ! printable))
{
/* Output a multibyte sequence, or an escaped
unprintable unibyte character. */
size_t ilim = i + m;
for (;;)
{
if (backslash_escapes && ! printable)
{
if (elide_outer_quotes)
goto force_outer_quoting_style;
STORE ('\\');
STORE ('0' + (c >> 6));
STORE ('0' + ((c >> 3) & 7));
c = '0' + (c & 7);
}
if (ilim <= i + 1)
break;
STORE (c);
c = arg[++i];
}
goto store_c;
}
}
}
if (! ((backslash_escapes || elide_outer_quotes)
&& quote_these_too
&& quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))
goto store_c;
store_escape:
if (elide_outer_quotes)
goto force_outer_quoting_style;
STORE ('\\');
store_c:
STORE (c);
}
if (len == 0 && quoting_style == shell_always_quoting_style
&& elide_outer_quotes)
goto force_outer_quoting_style;
if (quote_string && !elide_outer_quotes)
for (; *quote_string; quote_string++)
STORE (*quote_string);
if (len < buffersize)
buffer[len] = '\0';
return len;
force_outer_quoting_style:
/* Don't reuse quote_these_too, since the addition of outer quotes
sufficiently quotes the specified characters. */
return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
quoting_style,
flags & ~QA_ELIDE_OUTER_QUOTES, NULL);
}
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
argument ARG (of size ARGSIZE), using O to control quoting.
If O is null, use the default.
Terminate the output with a null character, and return the written
size of the output, not counting the terminating null.
If BUFFERSIZE is too small to store the output string, return the
value that would have been returned had BUFFERSIZE been large enough.
If ARGSIZE is SIZE_MAX, use the string length of the argument for
ARGSIZE. */
size_t
quotearg_buffer (char *buffer, size_t buffersize,
char const *arg, size_t argsize,
struct quoting_options const *o)
{
struct quoting_options const *p = o ? o : &default_quoting_options;
int e = errno;
size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
p->style, p->flags, p->quote_these_too);
errno = e;
return r;
}
/* Equivalent to quotearg_alloc (ARG, ARGSIZE, NULL, O). */
char *
quotearg_alloc (char const *arg, size_t argsize,
struct quoting_options const *o)
{
return quotearg_alloc_mem (arg, argsize, NULL, o);
}
/* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly
allocated storage containing the quoted string, and store the
resulting size into *SIZE, if non-NULL. The result can contain
embedded null bytes only if ARGSIZE is not SIZE_MAX, SIZE is not
NULL, and set_quoting_flags has not set the null byte elision
flag. */
char *
quotearg_alloc_mem (char const *arg, size_t argsize, size_t *size,
struct quoting_options const *o)
{
struct quoting_options const *p = o ? o : &default_quoting_options;
int e = errno;
/* Elide embedded null bytes if we can't return a size. */
int flags = p->flags | (size ? 0 : QA_ELIDE_NULL_BYTES);
size_t bufsize = quotearg_buffer_restyled (0, 0, arg, argsize, p->style,
flags, p->quote_these_too) + 1;
char *buf = xcharalloc (bufsize);
quotearg_buffer_restyled (buf, bufsize, arg, argsize, p->style, flags,
p->quote_these_too);
errno = e;
if (size)
*size = bufsize - 1;
return buf;
}
/* A storage slot with size and pointer to a value. */
struct slotvec
{
size_t size;
char *val;
};
/* Preallocate a slot 0 buffer, so that the caller can always quote
one small component of a "memory exhausted" message in slot 0. */
static char slot0[256];
static unsigned int nslots = 1;
static struct slotvec slotvec0 = {sizeof slot0, slot0};
static struct slotvec *slotvec = &slotvec0;
void
quotearg_free (void)
{
struct slotvec *sv = slotvec;
unsigned int i;
for (i = 1; i < nslots; i++)
free (sv[i].val);
if (sv[0].val != slot0)
{
free (sv[0].val);
slotvec0.size = sizeof slot0;
slotvec0.val = slot0;
}
if (sv != &slotvec0)
{
free (sv);
slotvec = &slotvec0;
}
nslots = 1;
}
/* Use storage slot N to return a quoted version of argument ARG.
ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a
null-terminated string.
OPTIONS specifies the quoting options.
The returned value points to static storage that can be
reused by the next call to this function with the same value of N.
N must be nonnegative. N is deliberately declared with type "int"
to allow for future extensions (using negative values). */
static char *
quotearg_n_options (int n, char const *arg, size_t argsize,
struct quoting_options const *options)
{
int e = errno;
unsigned int n0 = n;
struct slotvec *sv = slotvec;
if (n < 0)
abort ();
if (nslots <= n0)
{
/* FIXME: technically, the type of n1 should be `unsigned int',
but that evokes an unsuppressible warning from gcc-4.0.1 and
older. If gcc ever provides an option to suppress that warning,
revert to the original type, so that the test in xalloc_oversized
is once again performed only at compile time. */
size_t n1 = n0 + 1;
bool preallocated = (sv == &slotvec0);
if (xalloc_oversized (n1, sizeof *sv))
xalloc_die ();
slotvec = sv = xrealloc (preallocated ? NULL : sv, n1 * sizeof *sv);
if (preallocated)
*sv = slotvec0;
memset (sv + nslots, 0, (n1 - nslots) * sizeof *sv);
nslots = n1;
}
{
size_t size = sv[n].size;
char *val = sv[n].val;
/* Elide embedded null bytes since we don't return a size. */
int flags = options->flags | QA_ELIDE_NULL_BYTES;
size_t qsize = quotearg_buffer_restyled (val, size, arg, argsize,
options->style, flags,
options->quote_these_too);
if (size <= qsize)
{
sv[n].size = size = qsize + 1;
if (val != slot0)
free (val);
sv[n].val = val = xcharalloc (size);
quotearg_buffer_restyled (val, size, arg, argsize, options->style,
flags, options->quote_these_too);
}
errno = e;
return val;
}
}
char *
quotearg_n (int n, char const *arg)
{
return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);
}
char *
quotearg_n_mem (int n, char const *arg, size_t argsize)
{
return quotearg_n_options (n, arg, argsize, &default_quoting_options);
}
char *
quotearg (char const *arg)
{
return quotearg_n (0, arg);
}
char *
quotearg_mem (char const *arg, size_t argsize)
{
return quotearg_n_mem (0, arg, argsize);
}
char *
quotearg_n_style (int n, enum quoting_style s, char const *arg)
{
struct quoting_options const o = quoting_options_from_style (s);
return quotearg_n_options (n, arg, SIZE_MAX, &o);
}
char *
quotearg_n_style_mem (int n, enum quoting_style s,
char const *arg, size_t argsize)
{
struct quoting_options const o = quoting_options_from_style (s);
return quotearg_n_options (n, arg, argsize, &o);
}
char *
quotearg_style (enum quoting_style s, char const *arg)
{
return quotearg_n_style (0, s, arg);
}
char *
quotearg_style_mem (enum quoting_style s, char const *arg, size_t argsize)
{
return quotearg_n_style_mem (0, s, arg, argsize);
}
char *
quotearg_char_mem (char const *arg, size_t argsize, char ch)
{
struct quoting_options options;
options = default_quoting_options;
set_char_quoting (&options, ch, 1);
return quotearg_n_options (0, arg, argsize, &options);
}
char *
quotearg_char (char const *arg, char ch)
{
return quotearg_char_mem (arg, SIZE_MAX, ch);
}
char *
quotearg_colon (char const *arg)
{
return quotearg_char (arg, ':');
}
char *
quotearg_colon_mem (char const *arg, size_t argsize)
{
return quotearg_char_mem (arg, argsize, ':');
}

View File

@ -1,305 +0,0 @@
/* quotearg.h - quote arguments for output
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006, 2008 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert <eggert@twinsun.com> */
#ifndef QUOTEARG_H_
# define QUOTEARG_H_ 1
# include <stddef.h>
/* Basic quoting styles. For each style, an example is given on the
input strings "simple", "\0 \t\n'\"\033?""?/\\", and "a:b", using
quotearg_buffer, quotearg_mem, and quotearg_colon_mem with that
style and the default flags and quoted characters. Note that the
examples are shown here as valid C strings rather than what
displays on a terminal (with "??/" as a trigraph for "\\"). */
enum quoting_style
{
/* Output names as-is (ls --quoting-style=literal). Can result in
embedded null bytes if QA_ELIDE_NULL_BYTES is not in
effect.
quotearg_buffer:
"simple", "\0 \t\n'\"\033??/\\", "a:b"
quotearg:
"simple", " \t\n'\"\033??/\\", "a:b"
quotearg_colon:
"simple", " \t\n'\"\033??/\\", "a:b"
*/
literal_quoting_style,
/* Quote names for the shell if they contain shell metacharacters
or would cause ambiguous output (ls --quoting-style=shell).
Can result in embedded null bytes if QA_ELIDE_NULL_BYTES is not
in effect.
quotearg_buffer:
"simple", "'\0 \t\n'\\''\"\033??/\\'", "a:b"
quotearg:
"simple", "' \t\n'\\''\"\033??/\\'", "a:b"
quotearg_colon:
"simple", "' \t\n'\\''\"\033??/\\'", "'a:b'"
*/
shell_quoting_style,
/* Quote names for the shell, even if they would normally not
require quoting (ls --quoting-style=shell-always). Can result
in embedded null bytes if QA_ELIDE_NULL_BYTES is not in effect.
Behaves like shell_quoting_style if QA_ELIDE_OUTER_QUOTES is in
effect.
quotearg_buffer:
"'simple'", "'\0 \t\n'\\''\"\033??/\\'", "'a:b'"
quotearg:
"'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
quotearg_colon:
"'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
*/
shell_always_quoting_style,
/* Quote names as for a C language string (ls --quoting-style=c).
Behaves like c_maybe_quoting_style if QA_ELIDE_OUTER_QUOTES is
in effect. Split into consecutive strings if
QA_SPLIT_TRIGRAPHS.
quotearg_buffer:
"\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
quotearg:
"\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
quotearg_colon:
"\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
*/
c_quoting_style,
/* Like c_quoting_style except omit the surrounding double-quote
characters if no quoted characters are encountered.
quotearg_buffer:
"simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
quotearg:
"simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
quotearg_colon:
"simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
*/
c_maybe_quoting_style,
/* Like c_quoting_style except always omit the surrounding
double-quote characters (ls --quoting-style=escape).
quotearg_buffer:
"simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
quotearg:
"simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
quotearg_colon:
"simple", "\\0 \\t\\n'\"\\033??/\\\\", "a\\:b"
*/
escape_quoting_style,
/* Like clocale_quoting_style, but quote `like this' instead of
"like this" in the default C locale (ls --quoting-style=locale).
LC_MESSAGES=C
quotearg_buffer:
"`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
quotearg:
"`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
quotearg_colon:
"`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a\\:b'"
LC_MESSAGES=pt_PT.utf8
quotearg_buffer:
"\302\253simple\302\273",
"\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
quotearg:
"\302\253simple\302\273",
"\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
quotearg_colon:
"\302\253simple\302\273",
"\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
*/
locale_quoting_style,
/* Like c_quoting_style except use quotation marks appropriate for
the locale (ls --quoting-style=clocale).
LC_MESSAGES=C
quotearg_buffer:
"\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
quotearg:
"\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
quotearg_colon:
"\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
LC_MESSAGES=pt_PT.utf8
quotearg_buffer:
"\302\253simple\302\273",
"\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
quotearg:
"\302\253simple\302\273",
"\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
quotearg_colon:
"\302\253simple\302\273",
"\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
*/
clocale_quoting_style
};
/* Flags for use in set_quoting_flags. */
enum quoting_flags
{
/* Always elide null bytes from styles that do not quote them,
even when the length of the result is available to the
caller. */
QA_ELIDE_NULL_BYTES = 0x01,
/* Omit the surrounding quote characters if no escaped characters
are encountered. Note that if no other character needs
escaping, then neither does the escape character. */
QA_ELIDE_OUTER_QUOTES = 0x02,
/* In the c_quoting_style and c_maybe_quoting_style, split ANSI
trigraph sequences into concatenated strings (for example,
"?""?/" rather than "??/", which could be confused with
"\\"). */
QA_SPLIT_TRIGRAPHS = 0x04
};
/* For now, --quoting-style=literal is the default, but this may change. */
# ifndef DEFAULT_QUOTING_STYLE
# define DEFAULT_QUOTING_STYLE literal_quoting_style
# endif
/* Names of quoting styles and their corresponding values. */
extern char const *const quoting_style_args[];
extern enum quoting_style const quoting_style_vals[];
struct quoting_options;
/* The functions listed below set and use a hidden variable
that contains the default quoting style options. */
/* Allocate a new set of quoting options, with contents initially identical
to O if O is not null, or to the default if O is null.
It is the caller's responsibility to free the result. */
struct quoting_options *clone_quoting_options (struct quoting_options *o);
/* Get the value of O's quoting style. If O is null, use the default. */
enum quoting_style get_quoting_style (struct quoting_options *o);
/* In O (or in the default if O is null),
set the value of the quoting style to S. */
void set_quoting_style (struct quoting_options *o, enum quoting_style s);
/* In O (or in the default if O is null),
set the value of the quoting options for character C to I.
Return the old value. Currently, the only values defined for I are
0 (the default) and 1 (which means to quote the character even if
it would not otherwise be quoted). */
int set_char_quoting (struct quoting_options *o, char c, int i);
/* In O (or in the default if O is null),
set the value of the quoting options flag to I, which can be a
bitwise combination of enum quoting_flags, or 0 for default
behavior. Return the old value. */
int set_quoting_flags (struct quoting_options *o, int i);
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
argument ARG (of size ARGSIZE), using O to control quoting.
If O is null, use the default.
Terminate the output with a null character, and return the written
size of the output, not counting the terminating null.
If BUFFERSIZE is too small to store the output string, return the
value that would have been returned had BUFFERSIZE been large enough.
If ARGSIZE is -1, use the string length of the argument for ARGSIZE.
On output, BUFFER might contain embedded null bytes if ARGSIZE was
not -1, the style of O does not use backslash escapes, and the
flags of O do not request elision of null bytes.*/
size_t quotearg_buffer (char *buffer, size_t buffersize,
char const *arg, size_t argsize,
struct quoting_options const *o);
/* Like quotearg_buffer, except return the result in a newly allocated
buffer. It is the caller's responsibility to free the result. The
result will not contain embedded null bytes. */
char *quotearg_alloc (char const *arg, size_t argsize,
struct quoting_options const *o);
/* Like quotearg_alloc, except that the length of the result,
excluding the terminating null byte, is stored into SIZE if it is
non-NULL. The result might contain embedded null bytes if ARGSIZE
was not -1, SIZE was not NULL, the style of O does not use
backslash escapes, and the flags of O do not request elision of
null bytes.*/
char *quotearg_alloc_mem (char const *arg, size_t argsize,
size_t *size, struct quoting_options const *o);
/* Use storage slot N to return a quoted version of the string ARG.
Use the default quoting options.
The returned value points to static storage that can be
reused by the next call to this function with the same value of N.
N must be nonnegative. The output of all functions in the
quotearg_n family are guaranteed to not contain embedded null
bytes.*/
char *quotearg_n (int n, char const *arg);
/* Equivalent to quotearg_n (0, ARG). */
char *quotearg (char const *arg);
/* Use storage slot N to return a quoted version of the argument ARG
of size ARGSIZE. This is like quotearg_n (N, ARG), except it can
quote null bytes. */
char *quotearg_n_mem (int n, char const *arg, size_t argsize);
/* Equivalent to quotearg_n_mem (0, ARG, ARGSIZE). */
char *quotearg_mem (char const *arg, size_t argsize);
/* Use style S and storage slot N to return a quoted version of the string ARG.
This is like quotearg_n (N, ARG), except that it uses S with no other
options to specify the quoting method. */
char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
/* Use style S and storage slot N to return a quoted version of the
argument ARG of size ARGSIZE. This is like quotearg_n_style
(N, S, ARG), except it can quote null bytes. */
char *quotearg_n_style_mem (int n, enum quoting_style s,
char const *arg, size_t argsize);
/* Equivalent to quotearg_n_style (0, S, ARG). */
char *quotearg_style (enum quoting_style s, char const *arg);
/* Equivalent to quotearg_n_style_mem (0, S, ARG, ARGSIZE). */
char *quotearg_style_mem (enum quoting_style s,
char const *arg, size_t argsize);
/* Like quotearg (ARG), except also quote any instances of CH. */
char *quotearg_char (char const *arg, char ch);
/* Like quotearg_char (ARG, CH), except it can quote null bytes. */
char *quotearg_char_mem (char const *arg, size_t argsize, char ch);
/* Equivalent to quotearg_char (ARG, ':'). */
char *quotearg_colon (char const *arg);
/* Like quotearg_colon (ARG), except it can quote null bytes. */
char *quotearg_colon_mem (char const *arg, size_t argsize);
/* Free any dynamically allocated memory. */
void quotearg_free (void);
#endif /* !QUOTEARG_H_ */

View File

@ -1,87 +0,0 @@
/* realloc() function that is glibc compatible.
Copyright (C) 1997, 2003, 2004, 2006, 2007 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* written by Jim Meyering and Bruno Haible */
#include <config.h>
/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h. */
#ifdef realloc
# define NEED_REALLOC_GNU 1
#endif
/* Infer the properties of the system's malloc function.
Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
#if GNULIB_MALLOC_GNU && !defined malloc
# define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
#endif
/* Below we want to call the system's malloc and realloc.
Undefine the symbols here so that including <stdlib.h> provides a
declaration of malloc(), not of rpl_malloc(), and likewise for realloc. */
#undef malloc
#undef realloc
/* Specification. */
#include <stdlib.h>
#include <errno.h>
/* Below we want to call the system's malloc and realloc.
Undefine the symbols, if they were defined by gnulib's <stdlib.h>
replacement. */
#undef malloc
#undef realloc
/* Change the size of an allocated block of memory P to N bytes,
with error checking. If N is zero, change it to 1. If P is NULL,
use malloc. */
void *
rpl_realloc (void *p, size_t n)
{
void *result;
#if NEED_REALLOC_GNU
if (n == 0)
{
n = 1;
/* In theory realloc might fail, so don't rely on it to free. */
free (p);
p = NULL;
}
#endif
if (p == NULL)
{
#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE
if (n == 0)
n = 1;
#endif
result = malloc (n);
}
else
result = realloc (p, n);
#if !HAVE_REALLOC_POSIX
if (result == NULL)
errno = ENOMEM;
#endif
return result;
}

View File

@ -1,165 +0,0 @@
/* Work around rename bugs in some systems. On SunOS 4.1.1_U1
and mips-dec-ultrix4.4, rename fails when the source file has
a trailing slash. On mingw, rename fails when the destination
exists.
Copyright (C) 2001, 2002, 2003, 2005, 2006, 2009 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* written by Volker Borchert */
#include <config.h>
#undef rename
#if RENAME_DEST_EXISTS_BUG
/* This replacement must come first, otherwise when cross
* compiling to Windows we will guess that it has the trailing
* slash bug and entirely miss this one. */
#include <errno.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* Rename the file SRC to DST. This replacement is necessary on
Windows, on which the system rename function will not replace
an existing DST. */
int
rpl_rename (char const *src, char const *dst)
{
int error;
/* MoveFileEx works if SRC is a directory without any flags,
but fails with MOVEFILE_REPLACE_EXISTING, so try without
flags first. */
if (MoveFileEx (src, dst, 0))
return 0;
/* Retry with MOVEFILE_REPLACE_EXISTING if the move failed
* due to the destination already existing. */
error = GetLastError ();
if (error == ERROR_FILE_EXISTS || error == ERROR_ALREADY_EXISTS)
{
if (MoveFileEx (src, dst, MOVEFILE_REPLACE_EXISTING))
return 0;
error = GetLastError ();
}
switch (error)
{
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
case ERROR_BAD_PATHNAME:
case ERROR_DIRECTORY:
errno = ENOENT;
break;
case ERROR_ACCESS_DENIED:
case ERROR_SHARING_VIOLATION:
errno = EACCES;
break;
case ERROR_OUTOFMEMORY:
errno = ENOMEM;
break;
case ERROR_CURRENT_DIRECTORY:
errno = EBUSY;
break;
case ERROR_NOT_SAME_DEVICE:
errno = EXDEV;
break;
case ERROR_WRITE_PROTECT:
errno = EROFS;
break;
case ERROR_WRITE_FAULT:
case ERROR_READ_FAULT:
case ERROR_GEN_FAILURE:
errno = EIO;
break;
case ERROR_HANDLE_DISK_FULL:
case ERROR_DISK_FULL:
case ERROR_DISK_TOO_FRAGMENTED:
errno = ENOSPC;
break;
case ERROR_FILE_EXISTS:
case ERROR_ALREADY_EXISTS:
errno = EEXIST;
break;
case ERROR_BUFFER_OVERFLOW:
case ERROR_FILENAME_EXCED_RANGE:
errno = ENAMETOOLONG;
break;
case ERROR_INVALID_NAME:
case ERROR_DELETE_PENDING:
errno = EPERM; /* ? */
break;
#ifndef ERROR_FILE_TOO_LARGE
/* This value is documented but not defined in all versions of windows.h. */
#define ERROR_FILE_TOO_LARGE 223
#endif
case ERROR_FILE_TOO_LARGE:
errno = EFBIG;
break;
default:
errno = EINVAL;
break;
}
return -1;
}
#elif RENAME_TRAILING_SLASH_BUG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dirname.h"
#include "xalloc.h"
/* Rename the file SRC to DST, removing any trailing
slashes from SRC. Needed for SunOS 4.1.1_U1. */
int
rpl_rename (char const *src, char const *dst)
{
char *src_temp;
int ret_val;
size_t s_len = strlen (src);
if (s_len && src[s_len - 1] == '/')
{
src_temp = xstrdup (src);
strip_trailing_slashes (src_temp);
}
else
src_temp = (char *) src;
ret_val = rename (src_temp, dst);
if (src_temp != src)
free (src_temp);
return ret_val;
}
#endif /* RENAME_TRAILING_SLASH_BUG */

View File

@ -1,77 +0,0 @@
/* An interface to read and write that retries after interrupts.
Copyright (C) 1993, 1994, 1998, 2002, 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#ifdef SAFE_WRITE
# include "safe-write.h"
#else
# include "safe-read.h"
#endif
/* Get ssize_t. */
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#ifdef EINTR
# define IS_EINTR(x) ((x) == EINTR)
#else
# define IS_EINTR(x) 0
#endif
#include <limits.h>
#ifdef SAFE_WRITE
# define safe_rw safe_write
# define rw write
#else
# define safe_rw safe_read
# define rw read
# undef const
# define const /* empty */
#endif
/* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if
interrupted. Return the actual number of bytes read(written), zero for EOF,
or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */
size_t
safe_rw (int fd, void const *buf, size_t count)
{
/* Work around a bug in Tru64 5.1. Attempting to read more than
INT_MAX bytes fails with errno == EINVAL. See
<http://lists.gnu.org/archive/html/bug-gnu-utils/2002-04/msg00010.html>.
When decreasing COUNT, keep it block-aligned. */
enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };
for (;;)
{
ssize_t result = rw (fd, buf, count);
if (0 <= result)
return result;
else if (IS_EINTR (errno))
continue;
else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
count = BUGGY_READ_MAXIMUM;
else
return result;
}
}

View File

@ -1,18 +0,0 @@
/* An interface to write that retries after interrupts.
Copyright (C) 2002 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#define SAFE_WRITE
#include "safe-read.c"

View File

@ -1,24 +0,0 @@
/* An interface to write() that retries after interrupts.
Copyright (C) 2002 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stddef.h>
#define SAFE_WRITE_ERROR ((size_t) -1)
/* Write up to COUNT bytes at BUF to descriptor FD, retrying if interrupted.
Return the actual number of bytes written, zero for EOF, or SAFE_WRITE_ERROR
upon error. */
extern size_t safe_write (int fd, const void *buf, size_t count);

View File

@ -1,119 +0,0 @@
/* Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
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 Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_STDBOOL_H
#define _GL_STDBOOL_H
/* ISO C 99 <stdbool.h> for platforms that lack it. */
/* Usage suggestions:
Programs that use <stdbool.h> should be aware of some limitations
and standards compliance issues.
Standards compliance:
- <stdbool.h> must be #included before 'bool', 'false', 'true'
can be used.
- You cannot assume that sizeof (bool) == 1.
- Programs should not undefine the macros bool, true, and false,
as C99 lists that as an "obsolescent feature".
Limitations of this substitute, when used in a C89 environment:
- <stdbool.h> must be #included before the '_Bool' type can be used.
- You cannot assume that _Bool is a typedef; it might be a macro.
- Bit-fields of type 'bool' are not supported. Portable code
should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
- In C99, casts and automatic conversions to '_Bool' or 'bool' are
performed in such a way that every nonzero value gets converted
to 'true', and zero gets converted to 'false'. This doesn't work
with this substitute. With this substitute, only the values 0 and 1
give the expected result when converted to _Bool' or 'bool'.
Also, it is suggested that programs use 'bool' rather than '_Bool';
this isn't required, but 'bool' is more common. */
/* 7.16. Boolean type and values */
/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
definitions below, but temporarily we have to #undef them. */
#if defined __BEOS__ && !defined __HAIKU__
# include <OS.h> /* defines bool but not _Bool */
# undef false
# undef true
#endif
/* For the sake of symbolic names in gdb, we define true and false as
enum constants, not only as macros.
It is tempting to write
typedef enum { false = 0, true = 1 } _Bool;
so that gdb prints values of type 'bool' symbolically. But if we do
this, values of type '_Bool' may promote to 'int' or 'unsigned int'
(see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
(see ISO C 99 6.3.1.1.(2)). So we add a negative value to the
enum; this ensures that '_Bool' promotes to 'int'. */
#if defined __cplusplus || (defined __BEOS__ && !defined __HAIKU__)
/* A compiler known to have 'bool'. */
/* If the compiler already has both 'bool' and '_Bool', we can assume they
are the same types. */
# if !@HAVE__BOOL@
typedef bool _Bool;
# endif
#else
# if !defined __GNUC__
/* If @HAVE__BOOL@:
Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
the built-in _Bool type is used. See
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
Similar bugs are likely with other compilers as well; this file
wouldn't be used if <stdbool.h> was working.
So we override the _Bool type.
If !@HAVE__BOOL@:
Need to define _Bool ourselves. As 'signed char' or as an enum type?
Use of a typedef, with SunPRO C, leads to a stupid
"warning: _Bool is a keyword in ISO C99".
Use of an enum type, with IRIX cc, leads to a stupid
"warning(1185): enumerated type mixed with another type".
Even the existence of an enum type, without a typedef,
"Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
The only benefit of the enum, debuggability, is not important
with these compilers. So use 'signed char' and no enum. */
# define _Bool signed char
# else
/* With this compiler, trust the _Bool type if the compiler has it. */
# if !@HAVE__BOOL@
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
# endif
# endif
#endif
#define bool _Bool
/* The other macros must be usable in preprocessor directives. */
#define false 0
#define true 1
#define __bool_true_false_are_defined 1
#endif /* _GL_STDBOOL_H */

View File

@ -1,63 +0,0 @@
/* Case-insensitive string comparison function.
Copyright (C) 1998-1999, 2005-2007 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 Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#include <string.h>
#include <ctype.h>
#include <limits.h>
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
greater than zero if S1 is lexicographically less than, equal to or greater
than S2.
Note: This function does not work with multibyte strings! */
int
strcasecmp (const char *s1, const char *s2)
{
const unsigned char *p1 = (const unsigned char *) s1;
const unsigned char *p2 = (const unsigned char *) s2;
unsigned char c1, c2;
if (p1 == p2)
return 0;
do
{
c1 = TOLOWER (*p1);
c2 = TOLOWER (*p2);
if (c1 == '\0')
break;
++p1;
++p2;
}
while (c1 == c2);
if (UCHAR_MAX <= INT_MAX)
return c1 - c2;
else
/* On machines where 'char' and 'int' are types of the same size, the
difference of two 'unsigned char' values - including the sign bit -
doesn't fit in an 'int'. */
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
}

View File

@ -1,44 +0,0 @@
/* stripslash.c -- remove redundant trailing slashes from a file name
Copyright (C) 1990, 2001, 2003-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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
/* Remove trailing slashes from FILE. Return true if a trailing slash
was removed. This is useful when using file name completion from a
shell that adds a "/" after directory names (such as tcsh and
bash), because on symlinks to directories, several system calls
have different semantics according to whether a trailing slash is
present. */
bool
strip_trailing_slashes (char *file)
{
char *base = last_component (file);
char *base_lim;
bool had_slash;
/* last_component returns "" for file system roots, but we need to turn
`///' into `/'. */
if (! *base)
base = file;
base_lim = base + base_len (base);
had_slash = (*base_lim != '\0');
*base_lim = '\0';
return had_slash;
}

View File

@ -1,63 +0,0 @@
/* strncasecmp.c -- case insensitive string comparator
Copyright (C) 1998-1999, 2005-2007 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 Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#include <string.h>
#include <ctype.h>
#include <limits.h>
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
/* Compare no more than N bytes of strings S1 and S2, ignoring case,
returning less than, equal to or greater than zero if S1 is
lexicographically less than, equal to or greater than S2.
Note: This function cannot work correctly in multibyte locales. */
int
strncasecmp (const char *s1, const char *s2, size_t n)
{
register const unsigned char *p1 = (const unsigned char *) s1;
register const unsigned char *p2 = (const unsigned char *) s2;
unsigned char c1, c2;
if (p1 == p2 || n == 0)
return 0;
do
{
c1 = TOLOWER (*p1);
c2 = TOLOWER (*p2);
if (--n == 0 || c1 == '\0')
break;
++p1;
++p2;
}
while (c1 == c2);
if (UCHAR_MAX <= INT_MAX)
return c1 - c2;
else
/* On machines where 'char' and 'int' are types of the same size, the
difference of two 'unsigned char' values - including the sign bit -
doesn't fit in an 'int'. */
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
}

View File

@ -1,41 +0,0 @@
/* A replacement function, for systems that lack strndup.
Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007
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
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include <string.h>
#include <stdlib.h>
#ifndef HAVE_DECL_STRNLEN
extern size_t strnlen (const char *, size_t);
#endif
char *
strndup (char const *s, size_t n)
{
size_t len = strnlen (s, n);
char *new = malloc (len + 1);
if (new == NULL)
return NULL;
new[len] = '\0';
return memcpy (new, s, len);
}

View File

@ -1,31 +0,0 @@
/* Find the length of STRING, but scan at most MAXLEN characters.
Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
Written by Simon Josefsson.
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 Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include <string.h>
/* Find the length of STRING, but scan at most MAXLEN characters.
If no '\0' terminator is found in that many characters, return MAXLEN. */
size_t
strnlen (const char *string, size_t maxlen)
{
const char *end = memchr (string, '\0', maxlen);
return end ? (size_t) (end - string) : maxlen;
}

View File

@ -1,136 +0,0 @@
/* Prefer faster, non-thread-safe stdio functions if available.
Copyright (C) 2001, 2002, 2003, 2004 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Jim Meyering. */
#ifndef UNLOCKED_IO_H
# define UNLOCKED_IO_H 1
/* These are wrappers for functions/macros from the GNU C library, and
from other C libraries supporting POSIX's optional thread-safe functions.
The standard I/O functions are thread-safe. These *_unlocked ones are
more efficient but not thread-safe. That they're not thread-safe is
fine since all of the applications in this package are single threaded.
Also, some code that is shared with the GNU C library may invoke
the *_unlocked functions directly. On hosts that lack those
functions, invoke the non-thread-safe versions instead. */
# include <stdio.h>
# if HAVE_DECL_CLEARERR_UNLOCKED
# undef clearerr
# define clearerr(x) clearerr_unlocked (x)
# else
# define clearerr_unlocked(x) clearerr (x)
# endif
# if HAVE_DECL_FEOF_UNLOCKED
# undef feof
# define feof(x) feof_unlocked (x)
# else
# define feof_unlocked(x) feof (x)
# endif
# if HAVE_DECL_FERROR_UNLOCKED
# undef ferror
# define ferror(x) ferror_unlocked (x)
# else
# define ferror_unlocked(x) ferror (x)
# endif
# if HAVE_DECL_FFLUSH_UNLOCKED
# undef fflush
# define fflush(x) fflush_unlocked (x)
# else
# define fflush_unlocked(x) fflush (x)
# endif
# if HAVE_DECL_FGETS_UNLOCKED
# undef fgets
# define fgets(x,y,z) fgets_unlocked (x,y,z)
# else
# define fgets_unlocked(x,y,z) fgets (x,y,z)
# endif
# if HAVE_DECL_FPUTC_UNLOCKED
# undef fputc
# define fputc(x,y) fputc_unlocked (x,y)
# else
# define fputc_unlocked(x,y) fputc (x,y)
# endif
# if HAVE_DECL_FPUTS_UNLOCKED
# undef fputs
# define fputs(x,y) fputs_unlocked (x,y)
# else
# define fputs_unlocked(x,y) fputs (x,y)
# endif
# if HAVE_DECL_FREAD_UNLOCKED
# undef fread
# define fread(w,x,y,z) fread_unlocked (w,x,y,z)
# else
# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
# endif
# if HAVE_DECL_FWRITE_UNLOCKED
# undef fwrite
# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
# else
# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
# endif
# if HAVE_DECL_GETC_UNLOCKED
# undef getc
# define getc(x) getc_unlocked (x)
# else
# define getc_unlocked(x) getc (x)
# endif
# if HAVE_DECL_GETCHAR_UNLOCKED
# undef getchar
# define getchar() getchar_unlocked ()
# else
# define getchar_unlocked() getchar ()
# endif
# if HAVE_DECL_PUTC_UNLOCKED
# undef putc
# define putc(x,y) putc_unlocked (x,y)
# else
# define putc_unlocked(x,y) putc (x,y)
# endif
# if HAVE_DECL_PUTCHAR_UNLOCKED
# undef putchar
# define putchar(x) putchar_unlocked (x)
# else
# define putchar_unlocked(x) putchar (x)
# endif
# undef flockfile
# define flockfile(x) ((void) 0)
# undef ftrylockfile
# define ftrylockfile(x) 0
# undef funlockfile
# define funlockfile(x) ((void) 0)
#endif /* UNLOCKED_IO_H */

View File

@ -1,140 +0,0 @@
/* Compile-time assert-like macros.
Copyright (C) 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
#ifndef VERIFY_H
# define VERIFY_H 1
/* Each of these macros verifies that its argument R is nonzero. To
be portable, R should be an integer constant expression. Unlike
assert (R), there is no run-time overhead.
There are two macros, since no single macro can be used in all
contexts in C. verify_true (R) is for scalar contexts, including
integer constant expression contexts. verify (R) is for declaration
contexts, e.g., the top level.
Symbols ending in "__" are private to this header.
The code below uses several ideas.
* The first step is ((R) ? 1 : -1). Given an expression R, of
integral or boolean or floating-point type, this yields an
expression of integral type, whose value is later verified to be
constant and nonnegative.
* Next this expression W is wrapped in a type
struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
If W is negative, this yields a compile-time error. No compiler can
deal with a bit-field of negative size.
One might think that an array size check would have the same
effect, that is, that the type struct { unsigned int dummy[W]; }
would work as well. However, inside a function, some compilers
(such as C++ compilers and GNU C) allow local parameters and
variables inside array size expressions. With these compilers,
an array size check would not properly diagnose this misuse of
the verify macro:
void function (int n) { verify (n < 0); }
* For the verify macro, the struct verify_type__ will need to
somehow be embedded into a declaration. To be portable, this
declaration must declare an object, a constant, a function, or a
typedef name. If the declared entity uses the type directly,
such as in
struct dummy {...};
typedef struct {...} dummy;
extern struct {...} *dummy;
extern void dummy (struct {...} *);
extern struct {...} *dummy (void);
two uses of the verify macro would yield colliding declarations
if the entity names are not disambiguated. A workaround is to
attach the current line number to the entity name:
#define GL_CONCAT0(x, y) x##y
#define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
extern struct {...} * GL_CONCAT(dummy,__LINE__);
But this has the problem that two invocations of verify from
within the same macro would collide, since the __LINE__ value
would be the same for both invocations.
A solution is to use the sizeof operator. It yields a number,
getting rid of the identity of the type. Declarations like
extern int dummy [sizeof (struct {...})];
extern void dummy (int [sizeof (struct {...})]);
extern int (*dummy (void)) [sizeof (struct {...})];
can be repeated.
* Should the implementation use a named struct or an unnamed struct?
Which of the following alternatives can be used?
extern int dummy [sizeof (struct {...})];
extern int dummy [sizeof (struct verify_type__ {...})];
extern void dummy (int [sizeof (struct {...})]);
extern void dummy (int [sizeof (struct verify_type__ {...})]);
extern int (*dummy (void)) [sizeof (struct {...})];
extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
In the second and sixth case, the struct type is exported to the
outer scope; two such declarations therefore collide. GCC warns
about the first, third, and fourth cases. So the only remaining
possibility is the fifth case:
extern int (*dummy (void)) [sizeof (struct {...})];
* This implementation exploits the fact that GCC does not warn about
the last declaration mentioned above. If a future version of GCC
introduces a warning for this, the problem could be worked around
by using code specialized to GCC, e.g.,:
#if 4 <= __GNUC__
# define verify(R) \
extern int (* verify_function__ (void)) \
[__builtin_constant_p (R) && (R) ? 1 : -1]
#endif
* In C++, any struct definition inside sizeof is invalid.
Use a template type to work around the problem. */
/* Verify requirement R at compile-time, as an integer constant expression.
Return 1. */
# ifdef __cplusplus
template <int w>
struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
# define verify_true(R) \
(!!sizeof (verify_type__<(R) ? 1 : -1>))
# else
# define verify_true(R) \
(!!sizeof \
(struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
# endif
/* Verify requirement R at compile-time, as a declaration without a
trailing ';'. */
# define verify(R) extern int (* verify_function__ (void)) [verify_true (R)]
#endif

View File

@ -1,280 +0,0 @@
/* xalloc.h -- malloc with out-of-memory checking
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2003, 2004, 2006, 2007, 2008 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef XALLOC_H_
# define XALLOC_H_
# include <stddef.h>
# ifdef __cplusplus
extern "C" {
# endif
# ifndef __attribute__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
# define __attribute__(x)
# endif
# endif
# ifndef ATTRIBUTE_NORETURN
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
# endif
# ifndef ATTRIBUTE_MALLOC
# if __GNUC__ >= 3
# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
# else
# define ATTRIBUTE_MALLOC
# endif
# endif
/* This function is always triggered when memory is exhausted.
It must be defined by the application, either explicitly
or by using gnulib's xalloc-die module. This is the
function to call when one wants the program to die because of a
memory allocation failure. */
extern void xalloc_die (void) ATTRIBUTE_NORETURN;
void *xmalloc (size_t s) ATTRIBUTE_MALLOC;
void *xzalloc (size_t s) ATTRIBUTE_MALLOC;
void *xcalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
void *xrealloc (void *p, size_t s);
void *x2realloc (void *p, size_t *pn);
void *xmemdup (void const *p, size_t s) ATTRIBUTE_MALLOC;
char *xstrdup (char const *str) ATTRIBUTE_MALLOC;
/* Return 1 if an array of N objects, each of size S, cannot exist due
to size arithmetic overflow. S must be positive and N must be
nonnegative. This is a macro, not an inline function, so that it
works correctly even when SIZE_MAX < N.
By gnulib convention, SIZE_MAX represents overflow in size
calculations, so the conservative dividend to use here is
SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
However, malloc (SIZE_MAX) fails on all known hosts where
sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
branch when S is known to be 1. */
# define xalloc_oversized(n, s) \
((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
/* In the following macros, T must be an elementary or structure/union or
typedef'ed type, or a pointer to such a type. To apply one of the
following macros to a function pointer or array type, you need to typedef
it first and use the typedef name. */
/* Allocate an object of type T dynamically, with error checking. */
/* extern t *XMALLOC (typename t); */
# define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
/* Allocate memory for N elements of type T, with error checking. */
/* extern t *XNMALLOC (size_t n, typename t); */
# define XNMALLOC(n, t) \
((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
/* Allocate an object of type T dynamically, with error checking,
and zero it. */
/* extern t *XZALLOC (typename t); */
# define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
/* Allocate memory for N elements of type T, with error checking,
and zero it. */
/* extern t *XCALLOC (size_t n, typename t); */
# define XCALLOC(n, t) \
((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
# if HAVE_INLINE
# define static_inline static inline
# else
void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
void *xnrealloc (void *p, size_t n, size_t s);
void *x2nrealloc (void *p, size_t *pn, size_t s);
char *xcharalloc (size_t n) ATTRIBUTE_MALLOC;
# endif
# ifdef static_inline
/* Allocate an array of N objects, each with S bytes of memory,
dynamically, with error checking. S must be nonzero. */
static_inline void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
static_inline void *
xnmalloc (size_t n, size_t s)
{
if (xalloc_oversized (n, s))
xalloc_die ();
return xmalloc (n * s);
}
/* Change the size of an allocated block of memory P to an array of N
objects each of S bytes, with error checking. S must be nonzero. */
static_inline void *
xnrealloc (void *p, size_t n, size_t s)
{
if (xalloc_oversized (n, s))
xalloc_die ();
return xrealloc (p, n * s);
}
/* If P is null, allocate a block of at least *PN such objects;
otherwise, reallocate P so that it contains more than *PN objects
each of S bytes. *PN must be nonzero unless P is null, and S must
be nonzero. Set *PN to the new number of objects, and return the
pointer to the new block. *PN is never set to zero, and the
returned pointer is never null.
Repeated reallocations are guaranteed to make progress, either by
allocating an initial block with a nonzero size, or by allocating a
larger block.
In the following implementation, nonzero sizes are increased by a
factor of approximately 1.5 so that repeated reallocations have
O(N) overall cost rather than O(N**2) cost, but the
specification for this function does not guarantee that rate.
Here is an example of use:
int *p = NULL;
size_t used = 0;
size_t allocated = 0;
void
append_int (int value)
{
if (used == allocated)
p = x2nrealloc (p, &allocated, sizeof *p);
p[used++] = value;
}
This causes x2nrealloc to allocate a block of some nonzero size the
first time it is called.
To have finer-grained control over the initial size, set *PN to a
nonzero value before calling this function with P == NULL. For
example:
int *p = NULL;
size_t used = 0;
size_t allocated = 0;
size_t allocated1 = 1000;
void
append_int (int value)
{
if (used == allocated)
{
p = x2nrealloc (p, &allocated1, sizeof *p);
allocated = allocated1;
}
p[used++] = value;
}
*/
static_inline void *
x2nrealloc (void *p, size_t *pn, size_t s)
{
size_t n = *pn;
if (! p)
{
if (! n)
{
/* The approximate size to use for initial small allocation
requests, when the invoking code specifies an old size of
zero. 64 bytes is the largest "small" request for the
GNU C library malloc. */
enum { DEFAULT_MXFAST = 64 };
n = DEFAULT_MXFAST / s;
n += !n;
}
}
else
{
/* Set N = ceil (1.5 * N) so that progress is made if N == 1.
Check for overflow, so that N * S stays in size_t range.
The check is slightly conservative, but an exact check isn't
worth the trouble. */
if ((size_t) -1 / 3 * 2 / s <= n)
xalloc_die ();
n += (n + 1) / 2;
}
*pn = n;
return xrealloc (p, n * s);
}
/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
except it returns char *. */
static_inline char *xcharalloc (size_t n) ATTRIBUTE_MALLOC;
static_inline char *
xcharalloc (size_t n)
{
return XNMALLOC (n, char);
}
# endif
# ifdef __cplusplus
}
/* C++ does not allow conversions from void * to other pointer types
without a cast. Use templates to work around the problem when
possible. */
template <typename T> inline T *
xrealloc (T *p, size_t s)
{
return (T *) xrealloc ((void *) p, s);
}
template <typename T> inline T *
xnrealloc (T *p, size_t n, size_t s)
{
return (T *) xnrealloc ((void *) p, n, s);
}
template <typename T> inline T *
x2realloc (T *p, size_t *pn)
{
return (T *) x2realloc ((void *) p, pn);
}
template <typename T> inline T *
x2nrealloc (T *p, size_t *pn, size_t s)
{
return (T *) x2nrealloc ((void *) p, pn, s);
}
template <typename T> inline T *
xmemdup (T const *p, size_t s)
{
return (T *) xmemdup ((void const *) p, s);
}
# endif
#endif /* !XALLOC_H_ */

View File

@ -1,118 +0,0 @@
/* xmalloc.c -- malloc with out of memory checking
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2002, 2003, 2004, 2005, 2006, 2008-2009 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#if ! HAVE_INLINE
# define static_inline
#endif
#include "xalloc.h"
#undef static_inline
#include <stdlib.h>
#include <string.h>
/* 1 if calloc is known to be compatible with GNU calloc. This
matters if we are not also using the calloc module, which defines
HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */
#if defined HAVE_CALLOC || defined __GLIBC__
enum { HAVE_GNU_CALLOC = 1 };
#else
enum { HAVE_GNU_CALLOC = 0 };
#endif
/* Allocate N bytes of memory dynamically, with error checking. */
void *
xmalloc (size_t n)
{
void *p = malloc (n);
if (!p && n != 0)
xalloc_die ();
return p;
}
/* Change the size of an allocated block of memory P to N bytes,
with error checking. */
void *
xrealloc (void *p, size_t n)
{
p = realloc (p, n);
if (!p && n != 0)
xalloc_die ();
return p;
}
/* If P is null, allocate a block of at least *PN bytes; otherwise,
reallocate P so that it contains more than *PN bytes. *PN must be
nonzero unless P is null. Set *PN to the new block's size, and
return the pointer to the new block. *PN is never set to zero, and
the returned pointer is never null. */
void *
x2realloc (void *p, size_t *pn)
{
return x2nrealloc (p, pn, 1);
}
/* Allocate S bytes of zeroed memory dynamically, with error checking.
There's no need for xnzalloc (N, S), since it would be equivalent
to xcalloc (N, S). */
void *
xzalloc (size_t s)
{
return memset (xmalloc (s), 0, s);
}
/* Allocate zeroed memory for N elements of S bytes, with error
checking. S must be nonzero. */
void *
xcalloc (size_t n, size_t s)
{
void *p;
/* Test for overflow, since some calloc implementations don't have
proper overflow checks. But omit overflow and size-zero tests if
HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
returns NULL if successful. */
if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s))
|| (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
xalloc_die ();
return p;
}
/* Clone an object P of size S, with error checking. There's no need
for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
need for an arithmetic overflow check. */
void *
xmemdup (void const *p, size_t s)
{
return memcpy (xmalloc (s), p, s);
}
/* Clone STRING. */
char *
xstrdup (char const *string)
{
return xmemdup (string, strlen (string) + 1);
}

View File

@ -1,40 +0,0 @@
/* Duplicate a bounded initial segment of a string, with out-of-memory
checking.
Copyright (C) 2003, 2006, 2007 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include "xstrndup.h"
#include <string.h>
#include "xalloc.h"
#ifndef HAVE_DECL_STRNDUP
extern char *strndup (const char *, size_t);
#endif
/* Return a newly allocated copy of at most N bytes of STRING.
In other words, return a copy of the initial segment of length N of
STRING. */
char *
xstrndup (const char *string, size_t n)
{
char *s = strndup (string, n);
if (! s)
xalloc_die ();
return s;
}

View File

@ -1,23 +0,0 @@
/* Duplicate a bounded initial segment of a string, with out-of-memory
checking.
Copyright (C) 2003 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 Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stddef.h>
/* Return a newly allocated copy of at most N bytes of STRING.
In other words, return a copy of the initial segment of length N of
STRING. */
extern char *xstrndup (const char *string, size_t n);

View File

@ -1,10 +0,0 @@
#serial 3
dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_ARGMATCH],
[
AC_LIBOBJ([argmatch])
])

View File

@ -1,16 +0,0 @@
# backupfile.m4 serial 12
dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_BACKUPFILE],
[
AC_LIBOBJ([backupfile])
dnl Prerequisites of lib/backupfile.c.
AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
AC_REQUIRE([gl_AC_DOS])
AC_REQUIRE([AC_SYS_LONG_FILE_NAMES])
AC_CHECK_FUNCS_ONCE([pathconf])
])

View File

@ -1,41 +0,0 @@
# serial 11
dnl From Jim Meyering.
dnl
dnl Check whether struct dirent has a member named d_ino.
dnl
# Copyright (C) 1997, 1999-2001, 2003-2004, 2006-2007, 2009 Free Software
# Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO],
[AC_CACHE_CHECK([for d_ino member in directory struct],
gl_cv_struct_dirent_d_ino,
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
]],
[[DIR *dp = opendir (".");
struct dirent *e;
struct stat st;
if (! dp)
return 1;
e = readdir (dp);
return ! (e
&& stat (e->d_name, &st) == 0
&& e->d_ino == st.st_ino);]])],
[gl_cv_struct_dirent_d_ino=yes],
[gl_cv_struct_dirent_d_ino=no],
[gl_cv_struct_dirent_d_ino=no])])
if test $gl_cv_struct_dirent_d_ino = yes; then
AC_DEFINE([D_INO_IN_DIRENT], [1],
[Define if struct dirent has a member d_ino that actually works.])
fi
]
)

View File

@ -1,18 +0,0 @@
#serial 7 -*- autoconf -*-
dnl Copyright (C) 2002-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_DIRNAME],
[
AC_LIBOBJ([basename])
AC_LIBOBJ([dirname])
AC_LIBOBJ([stripslash])
dnl Prerequisites of lib/dirname.h.
AC_REQUIRE([gl_AC_DOS])
AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])
dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c.
])

View File

@ -1,71 +0,0 @@
#serial 10 -*- autoconf -*-
# Define some macros required for proper operation of code in lib/*.c
# on MSDOS/Windows systems.
# Copyright (C) 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# From Jim Meyering.
AC_DEFUN([gl_AC_DOS],
[
AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos],
[
AC_TRY_COMPILE([],
[#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__
neither MSDOS nor Windows
#endif],
[ac_cv_win_or_dos=yes],
[ac_cv_win_or_dos=no])
])
if test x"$ac_cv_win_or_dos" = xyes; then
ac_fs_accepts_drive_letter_prefix=1
ac_fs_backslash_is_file_name_separator=1
AC_CACHE_CHECK([whether drive letter can start relative path],
[ac_cv_drive_letter_can_be_relative],
[
AC_TRY_COMPILE([],
[#if defined __CYGWIN__
drive letters are always absolute
#endif],
[ac_cv_drive_letter_can_be_relative=yes],
[ac_cv_drive_letter_can_be_relative=no])
])
if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then
ac_fs_drive_letter_can_be_relative=1
else
ac_fs_drive_letter_can_be_relative=0
fi
else
ac_fs_accepts_drive_letter_prefix=0
ac_fs_backslash_is_file_name_separator=0
ac_fs_drive_letter_can_be_relative=0
fi
AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX],
$ac_fs_accepts_drive_letter_prefix,
[Define on systems for which file names may have a so-called
`drive letter' prefix, define this to compute the length of that
prefix, including the colon.])
AH_VERBATIM(ISSLASH,
[#if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
#else
# define ISSLASH(C) ((C) == '/')
#endif])
AC_DEFINE_UNQUOTED([FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR],
$ac_fs_backslash_is_file_name_separator,
[Define if the backslash character may also serve as a file name
component separator.])
AC_DEFINE_UNQUOTED([FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE],
$ac_fs_drive_letter_can_be_relative,
[Define if a drive letter prefix denotes a relative path if it is
not followed by a file name component separator.])
])

View File

@ -1,38 +0,0 @@
# double-slash-root.m4 serial 4 -*- Autoconf -*-
dnl Copyright (C) 2006, 2008, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_DOUBLE_SLASH_ROOT],
[
AC_REQUIRE([AC_CANONICAL_HOST])
AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root],
[ if test x"$cross_compiling" = xyes ; then
# When cross-compiling, there is no way to tell whether // is special
# short of a list of hosts. However, the only known hosts to date
# that have a distinct // are Apollo DomainOS (too old to port to),
# Cygwin, and z/OS. If anyone knows of another system for which // has
# special semantics and is distinct from /, please report it to
# <bug-gnulib@gnu.org>.
case $host in
*-cygwin | i370-ibm-openedition)
gl_cv_double_slash_root=yes ;;
*)
# Be optimistic and assume that / and // are the same when we
# don't know.
gl_cv_double_slash_root='unknown, assuming no' ;;
esac
else
set x `ls -di / // 2>/dev/null`
if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then
gl_cv_double_slash_root=no
else
gl_cv_double_slash_root=yes
fi
fi])
if test "$gl_cv_double_slash_root" = yes; then
AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], [1],
[Define to 1 if // is a file system root distinct from /.])
fi
])

View File

@ -1,15 +0,0 @@
#serial 5
dnl Copyright (C) 2002, 2005, 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_DUP2],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
AC_CHECK_FUNCS_ONCE([dup2])
if test $ac_cv_func_dup2 = no; then
HAVE_DUP2=0
AC_LIBOBJ([dup2])
fi
])

View File

@ -1,22 +0,0 @@
#serial 11
# Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004 Free Software
# Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_ERROR],
[
AC_FUNC_ERROR_AT_LINE
dnl Note: AC_FUNC_ERROR_AT_LINE does AC_LIBSOURCES([error.h, error.c]).
gl_PREREQ_ERROR
])
# Prerequisites of lib/error.c.
AC_DEFUN([gl_PREREQ_ERROR],
[
AC_REQUIRE([AC_FUNC_STRERROR_R])
:
])

View File

@ -1,13 +0,0 @@
# exitfail.m4 serial 6
dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_EXITFAIL],
[
AC_LIBOBJ([exitfail])
dnl No prerequisites of lib/exitfail.c.
:
])

View File

@ -1,104 +0,0 @@
# serial 8 -*- Autoconf -*-
# Enable extensions on systems that normally disable them.
# Copyright (C) 2003, 2006-2009 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS
# Autoconf. Perhaps we can remove this once we can assume Autoconf
# 2.62 or later everywhere, but since CVS Autoconf mutates rapidly
# enough in this area it's likely we'll need to redefine
# AC_USE_SYSTEM_EXTENSIONS for quite some time.
# AC_USE_SYSTEM_EXTENSIONS
# ------------------------
# Enable extensions on systems that normally disable them,
# typically due to standards-conformance issues.
# Remember that #undef in AH_VERBATIM gets replaced with #define by
# AC_DEFINE. The goal here is to define all known feature-enabling
# macros, then, if reports of conflicts are made, disable macros that
# cause problems on some platforms (such as __EXTENSIONS__).
AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS],
[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
AC_REQUIRE([AC_CANONICAL_HOST])
AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
if test "$MINIX" = yes; then
AC_DEFINE([_POSIX_SOURCE], [1],
[Define to 1 if you need to in order for `stat' and other
things to work.])
AC_DEFINE([_POSIX_1_SOURCE], [2],
[Define to 2 if the system does not provide POSIX.1 features
except with this defined.])
AC_DEFINE([_MINIX], [1],
[Define to 1 if on MINIX.])
fi
dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to 500,
dnl regardless of whether the flags -Ae or _D_HPUX_SOURCE=1 are already
dnl provided.
case "$host_os" in
hpux*)
AC_DEFINE([_XOPEN_SOURCE], [500],
[Define to 500 only on HP-UX.])
;;
esac
AH_VERBATIM([__EXTENSIONS__],
[/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
])
AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
[ac_cv_safe_to_define___extensions__],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
# define __EXTENSIONS__ 1
]AC_INCLUDES_DEFAULT])],
[ac_cv_safe_to_define___extensions__=yes],
[ac_cv_safe_to_define___extensions__=no])])
test $ac_cv_safe_to_define___extensions__ = yes &&
AC_DEFINE([__EXTENSIONS__])
AC_DEFINE([_ALL_SOURCE])
AC_DEFINE([_GNU_SOURCE])
AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
AC_DEFINE([_TANDEM_SOURCE])
])# AC_USE_SYSTEM_EXTENSIONS
# gl_USE_SYSTEM_EXTENSIONS
# ------------------------
# Enable extensions on systems that normally disable them,
# typically due to standards-conformance issues.
AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS],
[
dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS.
dnl gnulib does not need it. But if it gets required by third-party macros
dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a
dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE,
dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck.
AC_REQUIRE([AC_GNU_SOURCE])
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
])

View File

@ -1,83 +0,0 @@
# getopt.m4 serial 14
dnl Copyright (C) 2002-2006, 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
# The getopt module assume you want GNU getopt, with getopt_long etc,
# rather than vanilla POSIX getopt. This means your code should
# always include <getopt.h> for the getopt prototypes.
AC_DEFUN([gl_GETOPT_SUBSTITUTE],
[
AC_LIBOBJ([getopt])
AC_LIBOBJ([getopt1])
gl_GETOPT_SUBSTITUTE_HEADER
gl_PREREQ_GETOPT
])
AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
[
GETOPT_H=getopt.h
AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
[Define to rpl_ if the getopt replacement functions and variables
should be used.])
AC_SUBST([GETOPT_H])
])
AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
[
if test -z "$GETOPT_H"; then
AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h])
fi
if test -z "$GETOPT_H"; then
AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h])
fi
dnl BSD getopt_long uses an incompatible method to reset option processing,
dnl and (as of 2004-10-15) mishandles optional option-arguments.
if test -z "$GETOPT_H"; then
AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include <getopt.h>])
fi
dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
dnl option string (as of 2005-05-05).
if test -z "$GETOPT_H"; then
AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM([[#include <getopt.h>]],
[[
char *myargv[3];
myargv[0] = "conftest";
myargv[1] = "-+";
myargv[2] = 0;
return getopt (2, myargv, "+a") != '?';
]])],
[gl_cv_func_gnu_getopt=yes],
[gl_cv_func_gnu_getopt=no],
[dnl cross compiling - pessimistically guess based on decls
dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
dnl option string (as of 2005-05-05).
AC_CHECK_DECL([getopt_clip],
[gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
[#include <getopt.h>])])])
if test "$gl_cv_func_gnu_getopt" = "no"; then
GETOPT_H=getopt.h
fi
fi
])
AC_DEFUN([gl_GETOPT_IFELSE],
[
AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
AS_IF([test -n "$GETOPT_H"], [$1], [$2])
])
AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
# Prerequisites of lib/getopt*.
AC_DEFUN([gl_PREREQ_GETOPT],
[
AC_CHECK_DECLS_ONCE([getenv])
])

View File

@ -1,381 +0,0 @@
# gettext.m4 serial 62 (gettext-0.18)
dnl Copyright (C) 1995-2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl
dnl This file can can be used in projects which are not available under
dnl the GNU General Public License or the GNU Library General Public
dnl License but which still want to provide support for the GNU gettext
dnl functionality.
dnl Please note that the actual code of the GNU gettext library is covered
dnl by the GNU Library General Public License, and the rest of the GNU
dnl gettext package package is covered by the GNU General Public License.
dnl They are *not* in the public domain.
dnl Authors:
dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006.
dnl Macro to add for using GNU gettext.
dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The
dnl default (if it is not specified or empty) is 'no-libtool'.
dnl INTLSYMBOL should be 'external' for packages with no intl directory,
dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory.
dnl If INTLSYMBOL is 'use-libtool', then a libtool library
dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
dnl depending on --{enable,disable}-{shared,static} and on the presence of
dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library
dnl $(top_builddir)/intl/libintl.a will be created.
dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
dnl implementations (in libc or libintl) without the ngettext() function
dnl will be ignored. If NEEDSYMBOL is specified and is
dnl 'need-formatstring-macros', then GNU gettext implementations that don't
dnl support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
dnl INTLDIR is used to find the intl libraries. If empty,
dnl the value `$(top_builddir)/intl/' is used.
dnl
dnl The result of the configuration is one of three cases:
dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
dnl and used.
dnl Catalog format: GNU --> install in $(datadir)
dnl Catalog extension: .mo after installation, .gmo in source tree
dnl 2) GNU gettext has been found in the system's C library.
dnl Catalog format: GNU --> install in $(datadir)
dnl Catalog extension: .mo after installation, .gmo in source tree
dnl 3) No internationalization, always use English msgid.
dnl Catalog format: none
dnl Catalog extension: none
dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
dnl The use of .gmo is historical (it was needed to avoid overwriting the
dnl GNU format catalogs when building on a platform with an X/Open gettext),
dnl but we keep it in order not to force irrelevant filename changes on the
dnl maintainers.
dnl
AC_DEFUN([AM_GNU_GETTEXT],
[
dnl Argument checking.
ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], ,
[errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
])])])])])
ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
[errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
])])])])
define([gt_included_intl],
ifelse([$1], [external],
ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]),
[yes]))
define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], []))
gt_NEEDS_INIT
AM_GNU_GETTEXT_NEED([$2])
AC_REQUIRE([AM_PO_SUBDIRS])dnl
ifelse(gt_included_intl, yes, [
AC_REQUIRE([AM_INTL_SUBDIR])dnl
])
dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
AC_REQUIRE([AC_LIB_RPATH])
dnl Sometimes libintl requires libiconv, so first search for libiconv.
dnl Ideally we would do this search only after the
dnl if test "$USE_NLS" = "yes"; then
dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
dnl the configure script would need to contain the same shell code
dnl again, outside any 'if'. There are two solutions:
dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not
dnl documented, we avoid it.
ifelse(gt_included_intl, yes, , [
AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
])
dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation.
gt_INTL_MACOSX
dnl Set USE_NLS.
AC_REQUIRE([AM_NLS])
ifelse(gt_included_intl, yes, [
BUILD_INCLUDED_LIBINTL=no
USE_INCLUDED_LIBINTL=no
])
LIBINTL=
LTLIBINTL=
POSUB=
dnl Add a version number to the cache macros.
case " $gt_needs " in
*" need-formatstring-macros "*) gt_api_version=3 ;;
*" need-ngettext "*) gt_api_version=2 ;;
*) gt_api_version=1 ;;
esac
gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc"
gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl"
dnl If we use NLS figure out what method
if test "$USE_NLS" = "yes"; then
gt_use_preinstalled_gnugettext=no
ifelse(gt_included_intl, yes, [
AC_MSG_CHECKING([whether included gettext is requested])
AC_ARG_WITH([included-gettext],
[ --with-included-gettext use the GNU gettext library included here],
nls_cv_force_use_gnu_gettext=$withval,
nls_cv_force_use_gnu_gettext=no)
AC_MSG_RESULT([$nls_cv_force_use_gnu_gettext])
nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
])
dnl User does not insist on using GNU NLS library. Figure out what
dnl to use. If GNU gettext is available we use this. Else we have
dnl to fall back to GNU NLS library.
if test $gt_api_version -ge 3; then
gt_revision_test_code='
#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
#endif
changequote(,)dnl
typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
changequote([,])dnl
'
else
gt_revision_test_code=
fi
if test $gt_api_version -ge 2; then
gt_expression_test_code=' + * ngettext ("", "", 0)'
else
gt_expression_test_code=
fi
AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc],
[AC_TRY_LINK([#include <libintl.h>
$gt_revision_test_code
extern int _nl_msg_cat_cntr;
extern int *_nl_domain_bindings;],
[bindtextdomain ("", "");
return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings],
[eval "$gt_func_gnugettext_libc=yes"],
[eval "$gt_func_gnugettext_libc=no"])])
if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
dnl Sometimes libintl requires libiconv, so first search for libiconv.
ifelse(gt_included_intl, yes, , [
AM_ICONV_LINK
])
dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
dnl even if libiconv doesn't exist.
AC_LIB_LINKFLAGS_BODY([intl])
AC_CACHE_CHECK([for GNU gettext in libintl],
[$gt_func_gnugettext_libintl],
[gt_save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $INCINTL"
gt_save_LIBS="$LIBS"
LIBS="$LIBS $LIBINTL"
dnl Now see whether libintl exists and does not depend on libiconv.
AC_TRY_LINK([#include <libintl.h>
$gt_revision_test_code
extern int _nl_msg_cat_cntr;
extern
#ifdef __cplusplus
"C"
#endif
const char *_nl_expand_alias (const char *);],
[bindtextdomain ("", "");
return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
[eval "$gt_func_gnugettext_libintl=yes"],
[eval "$gt_func_gnugettext_libintl=no"])
dnl Now see whether libintl exists and depends on libiconv.
if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then
LIBS="$LIBS $LIBICONV"
AC_TRY_LINK([#include <libintl.h>
$gt_revision_test_code
extern int _nl_msg_cat_cntr;
extern
#ifdef __cplusplus
"C"
#endif
const char *_nl_expand_alias (const char *);],
[bindtextdomain ("", "");
return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")],
[LIBINTL="$LIBINTL $LIBICONV"
LTLIBINTL="$LTLIBINTL $LTLIBICONV"
eval "$gt_func_gnugettext_libintl=yes"
])
fi
CPPFLAGS="$gt_save_CPPFLAGS"
LIBS="$gt_save_LIBS"])
fi
dnl If an already present or preinstalled GNU gettext() is found,
dnl use it. But if this macro is used in GNU gettext, and GNU
dnl gettext is already preinstalled in libintl, we update this
dnl libintl. (Cf. the install rule in intl/Makefile.in.)
if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
|| { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
&& test "$PACKAGE" != gettext-runtime \
&& test "$PACKAGE" != gettext-tools; }; then
gt_use_preinstalled_gnugettext=yes
else
dnl Reset the values set by searching for libintl.
LIBINTL=
LTLIBINTL=
INCINTL=
fi
ifelse(gt_included_intl, yes, [
if test "$gt_use_preinstalled_gnugettext" != "yes"; then
dnl GNU gettext is not found in the C library.
dnl Fall back on included GNU gettext library.
nls_cv_use_gnu_gettext=yes
fi
fi
if test "$nls_cv_use_gnu_gettext" = "yes"; then
dnl Mark actions used to generate GNU NLS library.
BUILD_INCLUDED_LIBINTL=yes
USE_INCLUDED_LIBINTL=yes
LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD"
LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD"
LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
fi
CATOBJEXT=
if test "$gt_use_preinstalled_gnugettext" = "yes" \
|| test "$nls_cv_use_gnu_gettext" = "yes"; then
dnl Mark actions to use GNU gettext tools.
CATOBJEXT=.gmo
fi
])
if test -n "$INTL_MACOSX_LIBS"; then
if test "$gt_use_preinstalled_gnugettext" = "yes" \
|| test "$nls_cv_use_gnu_gettext" = "yes"; then
dnl Some extra flags are needed during linking.
LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
fi
fi
if test "$gt_use_preinstalled_gnugettext" = "yes" \
|| test "$nls_cv_use_gnu_gettext" = "yes"; then
AC_DEFINE([ENABLE_NLS], [1],
[Define to 1 if translation of program messages to the user's native language
is requested.])
else
USE_NLS=no
fi
fi
AC_MSG_CHECKING([whether to use NLS])
AC_MSG_RESULT([$USE_NLS])
if test "$USE_NLS" = "yes"; then
AC_MSG_CHECKING([where the gettext function comes from])
if test "$gt_use_preinstalled_gnugettext" = "yes"; then
if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
gt_source="external libintl"
else
gt_source="libc"
fi
else
gt_source="included intl directory"
fi
AC_MSG_RESULT([$gt_source])
fi
if test "$USE_NLS" = "yes"; then
if test "$gt_use_preinstalled_gnugettext" = "yes"; then
if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
AC_MSG_CHECKING([how to link with libintl])
AC_MSG_RESULT([$LIBINTL])
AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
fi
dnl For backward compatibility. Some packages may be using this.
AC_DEFINE([HAVE_GETTEXT], [1],
[Define if the GNU gettext() function is already present or preinstalled.])
AC_DEFINE([HAVE_DCGETTEXT], [1],
[Define if the GNU dcgettext() function is already present or preinstalled.])
fi
dnl We need to process the po/ directory.
POSUB=po
fi
ifelse(gt_included_intl, yes, [
dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL
dnl to 'yes' because some of the testsuite requires it.
if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then
BUILD_INCLUDED_LIBINTL=yes
fi
dnl Make all variables we use known to autoconf.
AC_SUBST([BUILD_INCLUDED_LIBINTL])
AC_SUBST([USE_INCLUDED_LIBINTL])
AC_SUBST([CATOBJEXT])
dnl For backward compatibility. Some configure.ins may be using this.
nls_cv_header_intl=
nls_cv_header_libgt=
dnl For backward compatibility. Some Makefiles may be using this.
DATADIRNAME=share
AC_SUBST([DATADIRNAME])
dnl For backward compatibility. Some Makefiles may be using this.
INSTOBJEXT=.mo
AC_SUBST([INSTOBJEXT])
dnl For backward compatibility. Some Makefiles may be using this.
GENCAT=gencat
AC_SUBST([GENCAT])
dnl For backward compatibility. Some Makefiles may be using this.
INTLOBJS=
if test "$USE_INCLUDED_LIBINTL" = yes; then
INTLOBJS="\$(GETTOBJS)"
fi
AC_SUBST([INTLOBJS])
dnl Enable libtool support if the surrounding package wishes it.
INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix
AC_SUBST([INTL_LIBTOOL_SUFFIX_PREFIX])
])
dnl For backward compatibility. Some Makefiles may be using this.
INTLLIBS="$LIBINTL"
AC_SUBST([INTLLIBS])
dnl Make all documented variables known to autoconf.
AC_SUBST([LIBINTL])
AC_SUBST([LTLIBINTL])
AC_SUBST([POSUB])
])
dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
m4_define([gt_NEEDS_INIT],
[
m4_divert_text([DEFAULTS], [gt_needs=])
m4_define([gt_NEEDS_INIT], [])
])
dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
AC_DEFUN([AM_GNU_GETTEXT_NEED],
[
m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
])
dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])

View File

@ -1,13 +0,0 @@
# hash.m4 serial 6
dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_HASH],
[
AC_LIBOBJ([hash])
dnl Prerequisites of lib/hash.c.
AC_REQUIRE([AM_STDBOOL_H])
])

View File

@ -1,40 +0,0 @@
# inline.m4 serial 4
dnl Copyright (C) 2006, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl Test for the 'inline' keyword or equivalent.
dnl Define 'inline' to a supported equivalent, or to nothing if not supported,
dnl like AC_C_INLINE does. Also, define HAVE_INLINE if 'inline' or an
dnl equivalent is effectively supported, i.e. if the compiler is likely to
dnl drop unused 'static inline' functions.
AC_DEFUN([gl_INLINE],
[
AC_REQUIRE([AC_C_INLINE])
AC_CACHE_CHECK([whether the compiler generally respects inline],
[gl_cv_c_inline_effective],
[if test $ac_cv_c_inline = no; then
gl_cv_c_inline_effective=no
else
dnl GCC defines __NO_INLINE__ if not optimizing or if -fno-inline is
dnl specified.
dnl Use AC_COMPILE_IFELSE here, not AC_EGREP_CPP, because the result
dnl depends on optimization flags, which can be in CFLAGS.
dnl (AC_EGREP_CPP looks only at the CPPFLAGS.)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[]],
[[#ifdef __NO_INLINE__
#error "inline is not effective"
#endif]])],
[gl_cv_c_inline_effective=yes],
[gl_cv_c_inline_effective=no])
fi
])
if test $gl_cv_c_inline_effective = yes; then
AC_DEFINE([HAVE_INLINE], [1],
[Define to 1 if the compiler supports one of the keywords
'inline', '__inline__', '__inline' and effectively inlines
functions marked as such.])
fi
])

View File

@ -1,41 +0,0 @@
# malloc.m4 serial 9
dnl Copyright (C) 2007, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
# gl_FUNC_MALLOC_POSIX
# --------------------
# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
# fails), and replace malloc if it is not.
AC_DEFUN([gl_FUNC_MALLOC_POSIX],
[
AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
if test $gl_cv_func_malloc_posix = yes; then
HAVE_MALLOC_POSIX=1
AC_DEFINE([HAVE_MALLOC_POSIX], [1],
[Define if the 'malloc' function is POSIX compliant.])
else
AC_LIBOBJ([malloc])
HAVE_MALLOC_POSIX=0
fi
AC_SUBST([HAVE_MALLOC_POSIX])
])
# Test whether malloc, realloc, calloc are POSIX compliant,
# Set gl_cv_func_malloc_posix to yes or no accordingly.
AC_DEFUN([gl_CHECK_MALLOC_POSIX],
[
AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant],
[gl_cv_func_malloc_posix],
[
dnl It is too dangerous to try to allocate a large amount of memory:
dnl some systems go to their knees when you do that. So assume that
dnl all Unix implementations of the function are POSIX compliant.
AC_TRY_COMPILE([],
[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
choke me
#endif
], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no])
])
])

View File

@ -1,382 +0,0 @@
# mbrtowc.m4 serial 14
dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_MBRTOWC],
[
AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
AC_REQUIRE([AC_TYPE_MBSTATE_T])
gl_MBSTATE_T_BROKEN
if test $REPLACE_MBSTATE_T = 1; then
REPLACE_MBRTOWC=1
fi
AC_CHECK_FUNCS_ONCE([mbrtowc])
if test $ac_cv_func_mbrtowc = no; then
HAVE_MBRTOWC=0
fi
if test $HAVE_MBRTOWC != 0 && test $REPLACE_MBRTOWC != 1; then
gl_MBRTOWC_NULL_ARG
gl_MBRTOWC_RETVAL
gl_MBRTOWC_NUL_RETVAL
case "$gl_cv_func_mbrtowc_null_arg" in
*yes) ;;
*) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1],
[Define if the mbrtowc function has the NULL string argument bug.])
REPLACE_MBRTOWC=1
;;
esac
case "$gl_cv_func_mbrtowc_retval" in
*yes) ;;
*) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
[Define if the mbrtowc function returns a wrong return value.])
REPLACE_MBRTOWC=1
;;
esac
case "$gl_cv_func_mbrtowc_nul_retval" in
*yes) ;;
*) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
[Define if the mbrtowc function does not return 0 for a NUL character.])
REPLACE_MBRTOWC=1
;;
esac
fi
if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
gl_REPLACE_WCHAR_H
AC_LIBOBJ([mbrtowc])
gl_PREREQ_MBRTOWC
fi
])
dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
dnl redefines the semantics of the given mbstate_t type.
dnl Result is REPLACE_MBSTATE_T.
dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
dnl avoid inconsistencies.
AC_DEFUN([gl_MBSTATE_T_BROKEN],
[
AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
AC_REQUIRE([AC_TYPE_MBSTATE_T])
AC_CHECK_FUNCS_ONCE([mbsinit])
AC_CHECK_FUNCS_ONCE([mbrtowc])
if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
gl_MBRTOWC_INCOMPLETE_STATE
gl_MBRTOWC_SANITYCHECK
REPLACE_MBSTATE_T=0
case "$gl_cv_func_mbrtowc_incomplete_state" in
*yes) ;;
*) REPLACE_MBSTATE_T=1 ;;
esac
case "$gl_cv_func_mbrtowc_sanitycheck" in
*yes) ;;
*) REPLACE_MBSTATE_T=1 ;;
esac
else
REPLACE_MBSTATE_T=1
fi
if test $REPLACE_MBSTATE_T = 1; then
gl_REPLACE_WCHAR_H
fi
])
dnl Test whether mbrtowc puts the state into non-initial state when parsing an
dnl incomplete multibyte character.
dnl Result is gl_cv_func_mbrtowc_incomplete_state.
AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gt_LOCALE_JA])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
[gl_cv_func_mbrtowc_incomplete_state],
[
dnl Initial guess, used when cross-compiling or when no suitable locale
dnl is present.
changequote(,)dnl
case "$host_os" in
# Guess no on AIX and OSF/1.
osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
# Guess yes otherwise.
*) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
esac
changequote([,])dnl
if test $LOCALE_JA != none; then
AC_TRY_RUN([
#include <locale.h>
#include <string.h>
#include <wchar.h>
int main ()
{
if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
{
const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
mbstate_t state;
wchar_t wc;
memset (&state, '\0', sizeof (mbstate_t));
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
if (mbsinit (&state))
return 1;
}
return 0;
}],
[gl_cv_func_mbrtowc_incomplete_state=yes],
[gl_cv_func_mbrtowc_incomplete_state=no],
[])
fi
])
])
dnl Test whether mbrtowc works not worse than mbtowc.
dnl Result is gl_cv_func_mbrtowc_sanitycheck.
AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gt_LOCALE_ZH_CN])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
[gl_cv_func_mbrtowc_sanitycheck],
[
dnl Initial guess, used when cross-compiling or when no suitable locale
dnl is present.
changequote(,)dnl
case "$host_os" in
# Guess no on Solaris 8.
solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
# Guess yes otherwise.
*) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
esac
changequote([,])dnl
if test $LOCALE_ZH_CN != none; then
AC_TRY_RUN([
#include <locale.h>
#include <string.h>
#include <wchar.h>
int main ()
{
/* This fails on Solaris 8:
mbrtowc returns 2, and sets wc to 0x00F0.
mbtowc returns 4 (correct) and sets wc to 0x5EDC. */
if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
{
char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
mbstate_t state;
wchar_t wc;
memset (&state, '\0', sizeof (mbstate_t));
if (mbrtowc (&wc, input + 3, 6, &state) != 4
&& mbtowc (&wc, input + 3, 6) == 4)
return 1;
}
return 0;
}],
[gl_cv_func_mbrtowc_sanitycheck=yes],
[gl_cv_func_mbrtowc_sanitycheck=no],
[])
fi
])
])
dnl Test whether mbrtowc supports a NULL string argument correctly.
dnl Result is gl_cv_func_mbrtowc_null_arg.
AC_DEFUN([gl_MBRTOWC_NULL_ARG],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gt_LOCALE_FR_UTF8])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
[gl_cv_func_mbrtowc_null_arg],
[
dnl Initial guess, used when cross-compiling or when no suitable locale
dnl is present.
changequote(,)dnl
case "$host_os" in
# Guess no on OSF/1.
osf*) gl_cv_func_mbrtowc_null_arg="guessing no" ;;
# Guess yes otherwise.
*) gl_cv_func_mbrtowc_null_arg="guessing yes" ;;
esac
changequote([,])dnl
if test $LOCALE_FR_UTF8 != none; then
AC_TRY_RUN([
#include <locale.h>
#include <string.h>
#include <wchar.h>
int main ()
{
if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
{
mbstate_t state;
wchar_t wc;
int ret;
memset (&state, '\0', sizeof (mbstate_t));
wc = (wchar_t) 0xBADFACE;
mbrtowc (&wc, NULL, 5, &state);
/* Check that wc was not modified. */
if (wc != (wchar_t) 0xBADFACE)
return 1;
}
return 0;
}], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], [])
fi
])
])
dnl Test whether mbrtowc, when parsing the end of a multibyte character,
dnl correctly returns the number of bytes that were needed to complete the
dnl character (not the total number of bytes of the multibyte character).
dnl Result is gl_cv_func_mbrtowc_retval.
AC_DEFUN([gl_MBRTOWC_RETVAL],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gt_LOCALE_FR_UTF8])
AC_REQUIRE([gt_LOCALE_JA])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether mbrtowc has a correct return value],
[gl_cv_func_mbrtowc_retval],
[
dnl Initial guess, used when cross-compiling or when no suitable locale
dnl is present.
changequote(,)dnl
case "$host_os" in
# Guess no on HP-UX and Solaris.
hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;;
# Guess yes otherwise.
*) gl_cv_func_mbrtowc_retval="guessing yes" ;;
esac
changequote([,])dnl
if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
AC_TRY_RUN([
#include <locale.h>
#include <string.h>
#include <wchar.h>
int main ()
{
/* This fails on Solaris. */
if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
{
char input[] = "B\303\274\303\237er"; /* "Büßer" */
mbstate_t state;
wchar_t wc;
memset (&state, '\0', sizeof (mbstate_t));
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
{
input[1] = '\0';
if (mbrtowc (&wc, input + 2, 5, &state) != 1)
return 1;
}
}
/* This fails on HP-UX 11.11. */
if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
{
char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
mbstate_t state;
wchar_t wc;
memset (&state, '\0', sizeof (mbstate_t));
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
{
input[1] = '\0';
if (mbrtowc (&wc, input + 2, 5, &state) != 2)
return 1;
}
}
return 0;
}],
[gl_cv_func_mbrtowc_retval=yes],
[gl_cv_func_mbrtowc_retval=no],
[])
fi
])
])
dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
dnl Result is gl_cv_func_mbrtowc_nul_retval.
AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
[
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([gt_LOCALE_ZH_CN])
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
[gl_cv_func_mbrtowc_nul_retval],
[
dnl Initial guess, used when cross-compiling or when no suitable locale
dnl is present.
changequote(,)dnl
case "$host_os" in
# Guess no on Solaris 8 and 9.
solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
# Guess yes otherwise.
*) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
esac
changequote([,])dnl
if test $LOCALE_ZH_CN != none; then
AC_TRY_RUN([
#include <locale.h>
#include <string.h>
#include <wchar.h>
int main ()
{
/* This fails on Solaris 8 and 9. */
if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
{
mbstate_t state;
wchar_t wc;
memset (&state, '\0', sizeof (mbstate_t));
if (mbrtowc (&wc, "", 1, &state) != 0)
return 1;
}
return 0;
}],
[gl_cv_func_mbrtowc_nul_retval=yes],
[gl_cv_func_mbrtowc_nul_retval=no],
[])
fi
])
])
# Prerequisites of lib/mbrtowc.c.
AC_DEFUN([gl_PREREQ_MBRTOWC], [
:
])
dnl From Paul Eggert
dnl This override of an autoconf macro can be removed when autoconf 2.60 or
dnl newer can be assumed everywhere.
m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.60]),[-1],[
AC_DEFUN([AC_FUNC_MBRTOWC],
[
dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
gl_cv_func_mbrtowc,
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <wchar.h>]],
[[wchar_t wc;
char const s[] = "";
size_t n = 1;
mbstate_t state;
return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
gl_cv_func_mbrtowc=yes,
gl_cv_func_mbrtowc=no)])
if test $gl_cv_func_mbrtowc = yes; then
AC_DEFINE([HAVE_MBRTOWC], [1],
[Define to 1 if mbrtowc and mbstate_t are properly declared.])
fi
])
])

View File

@ -1,34 +0,0 @@
# mbstate_t.m4 serial 12
dnl Copyright (C) 2000-2002, 2008, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
# From Paul Eggert.
# BeOS 5 has <wchar.h> but does not define mbstate_t,
# so you can't declare an object of that type.
# Check for this incompatibility with Standard C.
# AC_TYPE_MBSTATE_T
# -----------------
AC_DEFUN([AC_TYPE_MBSTATE_T],
[
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) dnl for HP-UX 11.11
AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT[
# include <wchar.h>]],
[[mbstate_t x; return sizeof x;]])],
[ac_cv_type_mbstate_t=yes],
[ac_cv_type_mbstate_t=no])])
if test $ac_cv_type_mbstate_t = yes; then
AC_DEFINE([HAVE_MBSTATE_T], [1],
[Define to 1 if <wchar.h> declares mbstate_t.])
else
AC_DEFINE([mbstate_t], [int],
[Define to a type if <wchar.h> does not define.])
fi
])

View File

@ -1,18 +0,0 @@
# memchr.m4 serial 5
dnl Copyright (C) 2002, 2003, 2004, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_MEMCHR],
[
AC_REPLACE_FUNCS([memchr])
if test $ac_cv_func_memchr = no; then
gl_PREREQ_MEMCHR
fi
])
# Prerequisites of lib/memchr.c.
AC_DEFUN([gl_PREREQ_MEMCHR], [
AC_CHECK_HEADERS([bp-sym.h])
])

View File

@ -1,41 +0,0 @@
# minmax.m4 serial 3
dnl Copyright (C) 2005, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_PREREQ([2.52])
AC_DEFUN([gl_MINMAX],
[
AC_REQUIRE([gl_PREREQ_MINMAX])
])
# Prerequisites of lib/minmax.h.
AC_DEFUN([gl_PREREQ_MINMAX],
[
gl_MINMAX_IN_HEADER([limits.h])
gl_MINMAX_IN_HEADER([sys/param.h])
])
dnl gl_MINMAX_IN_HEADER(HEADER)
dnl The parameter has to be a literal header name; it cannot be macro,
dnl nor a shell variable. (Because autoheader collects only AC_DEFINE
dnl invocations with a literal macro name.)
AC_DEFUN([gl_MINMAX_IN_HEADER],
[
m4_pushdef([header], AS_TR_SH([$1]))
m4_pushdef([HEADER], AS_TR_CPP([$1]))
AC_CACHE_CHECK([whether <$1> defines MIN and MAX],
[gl_cv_minmax_in_]header,
[AC_TRY_COMPILE([#include <$1>
int x = MIN (42, 17);], [],
[gl_cv_minmax_in_]header[=yes],
[gl_cv_minmax_in_]header[=no])])
if test $gl_cv_minmax_in_[]header = yes; then
AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1,
[Define to 1 if <$1> defines the MIN and MAX macros.])
fi
m4_popdef([HEADER])
m4_popdef([header])
])

View File

@ -1,90 +0,0 @@
# onceonly.m4 serial 6
dnl Copyright (C) 2002-2003, 2005-2006, 2008 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
dnl This file defines some "once only" variants of standard autoconf macros.
dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS
dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS
dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS
dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL
dnl The advantage is that the check for each of the headers/functions/decls
dnl will be put only once into the 'configure' file. It keeps the size of
dnl the 'configure' file down, and avoids redundant output when 'configure'
dnl is run.
dnl The drawback is that the checks cannot be conditionalized. If you write
dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi
dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to
dnl empty, and the check will be inserted before the body of the AC_DEFUNed
dnl function.
dnl The original code implemented AC_CHECK_HEADERS_ONCE and AC_CHECK_FUNCS_ONCE
dnl in terms of AC_DEFUN and AC_REQUIRE. This implementation uses diversions to
dnl named sections DEFAULTS and INIT_PREPARE in order to check all requested
dnl headers at once, thus reducing the size of 'configure'. It is known to work
dnl with autoconf 2.57..2.62 at least . The size reduction is ca. 9%.
dnl Autoconf version 2.59 plus gnulib is required; this file is not needed
dnl with Autoconf 2.60 or greater. But note that autoconf's implementation of
dnl AC_CHECK_DECLS_ONCE expects a comma-separated list of symbols as first
dnl argument!
AC_PREREQ([2.59])
# AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of
# AC_CHECK_HEADERS(HEADER1 HEADER2 ...).
AC_DEFUN([AC_CHECK_HEADERS_ONCE], [
:
m4_foreach_w([gl_HEADER_NAME], [$1], [
AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME,
[./-], [___])), [
m4_divert_text([INIT_PREPARE],
[gl_header_list="$gl_header_list gl_HEADER_NAME"])
gl_HEADERS_EXPANSION
AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])),
[Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.])
])
AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME,
[./-], [___])))
])
])
m4_define([gl_HEADERS_EXPANSION], [
m4_divert_text([DEFAULTS], [gl_header_list=])
AC_CHECK_HEADERS([$gl_header_list])
m4_define([gl_HEADERS_EXPANSION], [])
])
# AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of
# AC_CHECK_FUNCS(FUNC1 FUNC2 ...).
AC_DEFUN([AC_CHECK_FUNCS_ONCE], [
:
m4_foreach_w([gl_FUNC_NAME], [$1], [
AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [
m4_divert_text([INIT_PREPARE],
[gl_func_list="$gl_func_list gl_FUNC_NAME"])
gl_FUNCS_EXPANSION
AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])),
[Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.])
])
AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]))
])
])
m4_define([gl_FUNCS_EXPANSION], [
m4_divert_text([DEFAULTS], [gl_func_list=])
AC_CHECK_FUNCS([$gl_func_list])
m4_define([gl_FUNCS_EXPANSION], [])
])
# AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of
# AC_CHECK_DECLS(DECL1, DECL2, ...).
AC_DEFUN([AC_CHECK_DECLS_ONCE], [
:
m4_foreach_w([gl_DECL_NAME], [$1], [
AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [
AC_CHECK_DECLS(m4_defn([gl_DECL_NAME]))
])
AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]))
])
])

View File

@ -1,13 +0,0 @@
# quote.m4 serial 5
dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_QUOTE],
[
AC_LIBOBJ([quote])
dnl Prerequisites of lib/quote.c.
dnl (none)
])

View File

@ -1,10 +0,0 @@
# quotearg.m4 serial 8
dnl Copyright (C) 2002, 2004-2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_QUOTEARG],
[
AC_LIBOBJ([quotearg])
])

View File

@ -1,23 +0,0 @@
# realloc.m4 serial 9
dnl Copyright (C) 2007, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
# gl_FUNC_REALLOC_POSIX
# ---------------------
# Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it
# fails), and replace realloc if it is not.
AC_DEFUN([gl_FUNC_REALLOC_POSIX],
[
AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
if test $gl_cv_func_malloc_posix = yes; then
HAVE_REALLOC_POSIX=1
AC_DEFINE([HAVE_REALLOC_POSIX], [1],
[Define if the 'realloc' function is POSIX compliant.])
else
AC_LIBOBJ([realloc])
HAVE_REALLOC_POSIX=0
fi
AC_SUBST([HAVE_REALLOC_POSIX])
])

View File

@ -1,69 +0,0 @@
# serial 13
# Copyright (C) 2001, 2003, 2005, 2006, 2009 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
dnl From Volker Borchert.
dnl Determine whether rename works for source file names with a trailing slash.
dnl The rename from SunOS 4.1.1_U1 doesn't.
dnl
dnl If it doesn't, then define RENAME_TRAILING_SLASH_BUG and arrange
dnl to compile the wrapper function.
dnl
AC_DEFUN([gl_FUNC_RENAME],
[
AC_REQUIRE([AC_CANONICAL_HOST])
AC_CACHE_CHECK([whether rename is broken with a trailing slash],
gl_cv_func_rename_trailing_slash_bug,
[
rm -rf conftest.d1 conftest.d2
mkdir conftest.d1 ||
AC_MSG_ERROR([cannot create temporary directory])
AC_TRY_RUN([
# include <stdio.h>
# include <stdlib.h>
int
main ()
{
exit (rename ("conftest.d1/", "conftest.d2") ? 1 : 0);
}
],
gl_cv_func_rename_trailing_slash_bug=no,
gl_cv_func_rename_trailing_slash_bug=yes,
dnl When crosscompiling, assume rename is broken.
gl_cv_func_rename_trailing_slash_bug=yes)
rm -rf conftest.d1 conftest.d2
])
AC_CACHE_CHECK([whether rename is broken when the destination exists],
gl_cv_func_rename_dest_exists_bug,
[
case "$host_os" in
mingw*) gl_cv_func_rename_dest_exists_bug=yes ;;
*) gl_cv_func_rename_dest_exists_bug=no ;;
esac
])
if test $gl_cv_func_rename_trailing_slash_bug = yes ||
test $gl_cv_func_rename_dest_exists_bug = yes; then
AC_LIBOBJ([rename])
AC_DEFINE([rename], [rpl_rename],
[Define to rpl_rename if the replacement function should be used.])
if test $gl_cv_func_rename_trailing_slash_bug = yes; then
AC_DEFINE([RENAME_TRAILING_SLASH_BUG], [1],
[Define if rename does not work for source file names with a trailing
slash, like the one from SunOS 4.1.1_U1.])
fi
if test $gl_cv_func_rename_dest_exists_bug = yes; then
AC_DEFINE([RENAME_DEST_EXISTS_BUG], [1],
[Define if rename does not work when the destination file exists,
as on Windows.])
fi
gl_PREREQ_RENAME
fi
])
# Prerequisites of lib/rename.c.
AC_DEFUN([gl_PREREQ_RENAME], [:])

View File

@ -1,18 +0,0 @@
# safe-read.m4 serial 5
dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_SAFE_READ],
[
AC_LIBOBJ([safe-read])
gl_PREREQ_SAFE_READ
])
# Prerequisites of lib/safe-read.c.
AC_DEFUN([gl_PREREQ_SAFE_READ],
[
AC_REQUIRE([gt_TYPE_SSIZE_T])
])

View File

@ -1,18 +0,0 @@
# safe-write.m4 serial 3
dnl Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_SAFE_WRITE],
[
AC_LIBOBJ([safe-write])
gl_PREREQ_SAFE_WRITE
])
# Prerequisites of lib/safe-write.c.
AC_DEFUN([gl_PREREQ_SAFE_WRITE],
[
gl_PREREQ_SAFE_READ
])

View File

@ -1,21 +0,0 @@
# ssize_t.m4 serial 4 (gettext-0.15)
dnl Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Bruno Haible.
dnl Test whether ssize_t is defined.
AC_DEFUN([gt_TYPE_SSIZE_T],
[
AC_CACHE_CHECK([for ssize_t], [gt_cv_ssize_t],
[AC_TRY_COMPILE([#include <sys/types.h>],
[int x = sizeof (ssize_t *) + sizeof (ssize_t);
return !x;],
[gt_cv_ssize_t=yes], [gt_cv_ssize_t=no])])
if test $gt_cv_ssize_t = no; then
AC_DEFINE([ssize_t], [int],
[Define as a signed type of the same size as size_t.])
fi
])

View File

@ -1,115 +0,0 @@
# Check for stdbool.h that conforms to C99.
dnl Copyright (C) 2002-2006, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
# Prepare for substituting <stdbool.h> if it is not supported.
AC_DEFUN([AM_STDBOOL_H],
[
AC_REQUIRE([AC_HEADER_STDBOOL])
# Define two additional variables used in the Makefile substitution.
if test "$ac_cv_header_stdbool_h" = yes; then
STDBOOL_H=''
else
STDBOOL_H='stdbool.h'
fi
AC_SUBST([STDBOOL_H])
if test "$ac_cv_type__Bool" = yes; then
HAVE__BOOL=1
else
HAVE__BOOL=0
fi
AC_SUBST([HAVE__BOOL])
])
# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
# This macro is only needed in autoconf <= 2.59. Newer versions of autoconf
# have this macro built-in.
AC_DEFUN([AC_HEADER_STDBOOL],
[AC_CACHE_CHECK([for stdbool.h that conforms to C99],
[ac_cv_header_stdbool_h],
[AC_TRY_COMPILE(
[
#include <stdbool.h>
#ifndef bool
"error: bool is not defined"
#endif
#ifndef false
"error: false is not defined"
#endif
#if false
"error: false is not 0"
#endif
#ifndef true
"error: true is not defined"
#endif
#if true != 1
"error: true is not 1"
#endif
#ifndef __bool_true_false_are_defined
"error: __bool_true_false_are_defined is not defined"
#endif
struct s { _Bool s: 1; _Bool t; } s;
char a[true == 1 ? 1 : -1];
char b[false == 0 ? 1 : -1];
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
char d[(bool) 0.5 == true ? 1 : -1];
bool e = &s;
char f[(_Bool) 0.0 == false ? 1 : -1];
char g[true];
char h[sizeof (_Bool)];
char i[sizeof s.t];
enum { j = false, k = true, l = false * true, m = true * 256 };
_Bool n[m];
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
#if defined __xlc__ || defined __GNUC__
/* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
reported by James Lemley on 2005-10-05; see
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
This test is not quite right, since xlc is allowed to
reject this program, as the initializer for xlcbug is
not one of the forms that C requires support for.
However, doing the test right would require a run-time
test, and that would make cross-compilation harder.
Let us hope that IBM fixes the xlc bug, and also adds
support for this kind of constant expression. In the
meantime, this test will reject xlc, which is OK, since
our stdbool.h substitute should suffice. We also test
this with GCC, where it should work, to detect more
quickly whether someone messes up the test in the
future. */
char digs[] = "0123456789";
int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
#endif
/* Catch a bug in an HP-UX C compiler. See
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
*/
_Bool q = true;
_Bool *pq = &q;
],
[
*pq |= q;
*pq |= ! q;
/* Refer to every declared value, to avoid compiler optimizations. */
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
+ !m + !n + !o + !p + !q + !pq);
],
[ac_cv_header_stdbool_h=yes],
[ac_cv_header_stdbool_h=no])])
AC_CHECK_TYPES([_Bool])
if test $ac_cv_header_stdbool_h = yes; then
AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.])
fi])

View File

@ -1,39 +0,0 @@
# strcase.m4 serial 1
dnl Copyright (C) 2002 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
AC_DEFUN([gl_STRCASE],
[
gl_FUNC_STRCASECMP
gl_FUNC_STRNCASECMP
])
AC_DEFUN([gl_FUNC_STRCASECMP],
[
AC_REPLACE_FUNCS(strcasecmp)
if test $ac_cv_func_strcasecmp = no; then
gl_PREREQ_STRCASECMP
fi
])
AC_DEFUN([gl_FUNC_STRNCASECMP],
[
AC_REPLACE_FUNCS(strncasecmp)
if test $ac_cv_func_strncasecmp = no; then
gl_PREREQ_STRNCASECMP
fi
])
# Prerequisites of lib/strcasecmp.c.
AC_DEFUN([gl_PREREQ_STRCASECMP], [
:
])
# Prerequisites of lib/strncasecmp.c.
AC_DEFUN([gl_PREREQ_STRNCASECMP], [
:
])

View File

@ -1,53 +0,0 @@
# strndup.m4 serial 16
dnl Copyright (C) 2002-2003, 2005-2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_STRNDUP],
[
dnl Persuade glibc <string.h> to declare strndup().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
dnl AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
AC_CHECK_DECLS_ONCE([strndup])
if test $ac_cv_have_decl_strndup = no; then
HAVE_DECL_STRNDUP=0
fi
# AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup],
[AC_RUN_IFELSE([
AC_LANG_PROGRAM([[#include <string.h>
#include <stdlib.h>]], [[
#ifndef HAVE_DECL_STRNDUP
extern char *strndup (const char *, size_t);
#endif
char *s;
s = strndup ("some longer string", 15);
free (s);
s = strndup ("shorter string", 13);
return s[13] != '\0';]])],
[gl_cv_func_strndup=yes],
[gl_cv_func_strndup=no],
[AC_CHECK_FUNC([strndup],
[AC_EGREP_CPP([too risky], [
#ifdef _AIX
too risky
#endif
],
[gl_cv_func_strndup=no],
[gl_cv_func_strndup=yes])],
[gl_cv_func_strndup=no])])])
if test $gl_cv_func_strndup = yes; then
AC_DEFINE([HAVE_STRNDUP], [1],
[Define if you have the strndup() function and it works.])
else
HAVE_STRNDUP=0
AC_LIBOBJ([strndup])
gl_PREREQ_STRNDUP
fi
])
# Prerequisites of lib/strndup.c.
AC_DEFUN([gl_PREREQ_STRNDUP], [:])

View File

@ -1,31 +0,0 @@
# strnlen.m4 serial 10
dnl Copyright (C) 2002-2003, 2005-2007, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_STRNLEN],
[
dnl Persuade glibc <string.h> to declare strnlen().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
dnl AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
AC_CHECK_DECLS_ONCE([strnlen])
if test $ac_cv_have_decl_strnlen = no; then
HAVE_DECL_STRNLEN=0
fi
AC_FUNC_STRNLEN
if test $ac_cv_func_strnlen_working = no; then
# This is necessary because automake-1.6.1 doesn't understand
# that the above use of AC_FUNC_STRNLEN means we may have to use
# lib/strnlen.c.
AC_LIBOBJ([strnlen])
AC_DEFINE([strnlen], [rpl_strnlen],
[Define to rpl_strnlen if the replacement function should be used.])
gl_PREREQ_STRNLEN
fi
])
# Prerequisites of lib/strnlen.c.
AC_DEFUN([gl_PREREQ_STRNLEN], [:])

View File

@ -1,41 +0,0 @@
# unlocked-io.m4 serial 15
# Copyright (C) 1998-2006, 2009 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
dnl From Jim Meyering.
dnl
dnl See if the glibc *_unlocked I/O macros or functions are available.
dnl Use only those *_unlocked macros or functions that are declared
dnl (because some of them were declared in Solaris 2.5.1 but were removed
dnl in Solaris 2.6, whereas we want binaries built on Solaris 2.5.1 to run
dnl on Solaris 2.6).
AC_DEFUN([gl_FUNC_GLIBC_UNLOCKED_IO],
[
AC_DEFINE([USE_UNLOCKED_IO], [1],
[Define to 1 if you want getc etc. to use unlocked I/O if available.
Unlocked I/O can improve performance in unithreaded apps,
but it is not safe for multithreaded apps.])
dnl Persuade glibc and Solaris <stdio.h> to declare
dnl fgets_unlocked(), fputs_unlocked() etc.
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AC_CHECK_DECLS_ONCE([clearerr_unlocked])
AC_CHECK_DECLS_ONCE([feof_unlocked])
AC_CHECK_DECLS_ONCE([ferror_unlocked])
AC_CHECK_DECLS_ONCE([fflush_unlocked])
AC_CHECK_DECLS_ONCE([fgets_unlocked])
AC_CHECK_DECLS_ONCE([fputc_unlocked])
AC_CHECK_DECLS_ONCE([fputs_unlocked])
AC_CHECK_DECLS_ONCE([fread_unlocked])
AC_CHECK_DECLS_ONCE([fwrite_unlocked])
AC_CHECK_DECLS_ONCE([getc_unlocked])
AC_CHECK_DECLS_ONCE([getchar_unlocked])
AC_CHECK_DECLS_ONCE([putc_unlocked])
AC_CHECK_DECLS_ONCE([putchar_unlocked])
])

View File

@ -1,39 +0,0 @@
# serial 9
# Copyright (C) 1998-2001, 2003-2004, 2007, 2009 Free Software
# Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
dnl From Jim Meyering
dnl Define HAVE_STRUCT_UTIMBUF if `struct utimbuf' is declared --
dnl usually in <utime.h>.
dnl Some systems have utime.h but don't declare the struct anywhere.
AC_DEFUN([gl_CHECK_TYPE_STRUCT_UTIMBUF],
[
AC_CHECK_HEADERS_ONCE([sys/time.h utime.h])
AC_CACHE_CHECK([for struct utimbuf], [gl_cv_sys_struct_utimbuf],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <time.h>
#ifdef HAVE_UTIME_H
#include <utime.h>
#endif
]],
[[static struct utimbuf x; x.actime = x.modtime;]])],
[gl_cv_sys_struct_utimbuf=yes],
[gl_cv_sys_struct_utimbuf=no])])
if test $gl_cv_sys_struct_utimbuf = yes; then
AC_DEFINE([HAVE_STRUCT_UTIMBUF], [1],
[Define if struct utimbuf is declared -- usually in <utime.h>.
Some systems have utime.h but don't declare the struct anywhere. ])
fi
])

View File

@ -1,24 +0,0 @@
# xalloc.m4 serial 16
dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_XALLOC],
[
AC_LIBOBJ([xmalloc])
gl_PREREQ_XALLOC
gl_PREREQ_XMALLOC
])
# Prerequisites of lib/xalloc.h.
AC_DEFUN([gl_PREREQ_XALLOC], [
AC_REQUIRE([gl_INLINE])
:
])
# Prerequisites of lib/xmalloc.c.
AC_DEFUN([gl_PREREQ_XMALLOC], [
:
])

View File

@ -1,15 +0,0 @@
# xstrndup.m4 serial 2
dnl Copyright (C) 2003 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_XSTRNDUP],
[
gl_PREREQ_XSTRNDUP
])
# Prerequisites of lib/xstrndup.c.
AC_DEFUN([gl_PREREQ_XSTRNDUP], [
:
])

1
gnulib Submodule

@ -0,0 +1 @@
Subproject commit 9829f0a93c40492875f67ee738e000611bdcf0e7

Some files were not shown because too many files have changed in this diff Show More