Merge commit 'upstream/1.4'
authorBdale Garbee <bdale@gag.com>
Tue, 20 Apr 2010 08:15:23 +0000 (02:15 -0600)
committerBdale Garbee <bdale@gag.com>
Tue, 20 Apr 2010 08:15:23 +0000 (02:15 -0600)
Conflicts:
COPYING
ChangeLog
INSTALL
Makefile.am
Makefile.in
NEWS
README
README-alpha
TODO
aclocal.m4
bits.c
build-aux/compile
build-aux/config.guess
build-aux/config.sub
build-aux/depcomp
build-aux/install-sh
build-aux/mdate-sh
build-aux/missing
build-aux/texinfo.tex
configure
configure.ac
crypt.c
deflate.c
doc/Makefile.am
doc/Makefile.in
doc/fdl.texi
doc/gzip.info
doc/gzip.texi
doc/stamp-vti
doc/version.texi
gunzip.in
gzexe.in
gzip.c
gzip.doc
gzip.h
inflate.c
lib/Makefile.am
lib/Makefile.in
lib/config.hin
lib/creat-safer.c
lib/dup-safer.c
lib/error.c
lib/error.h
lib/exitfail.c
lib/exitfail.h
lib/fcntl--.h
lib/fcntl-safer.h
lib/fd-safer.c
lib/getopt.c
lib/getopt1.c
lib/getopt_.h
lib/getopt_int.h
lib/gettext.h
lib/gnulib.mk
lib/match.c
lib/open-safer.c
lib/pipe-safer.c
lib/stat-time.h
lib/unistd--.h
lib/unistd-safer.h
lib/utimens.c
lib/utimens.h
lib/xalloc-die.c
lib/xalloc.h
lib/xmalloc.c
lib/yesno.c
lib/yesno.h
lzw.c
lzw.h
m4/error.m4
m4/exitfail.m4
m4/extensions.m4
m4/fcntl-safer.m4
m4/fcntl_h.m4
m4/getopt.m4
m4/gnulib-common.m4
m4/gnulib-comp.m4
m4/inline.m4
m4/shell.m4
m4/stat-time.m4
m4/stdbool.m4
m4/stdlib_h.m4
m4/sys_stat_h.m4
m4/sys_time_h.m4
m4/time_h.m4
m4/unistd-safer.m4
m4/unistd_h.m4
m4/utimbuf.m4
m4/utimens.m4
m4/utimes.m4
m4/xalloc.m4
m4/yesno.m4
revision.h
tailor.h
trees.c
unlzh.c
unlzw.c
unpack.c
unzip.c
util.c
zcat.in
zcmp.in
zdiff.in
zegrep.in
zfgrep.in
zforce.in
zgrep.in
zip.c
zless.1
zless.in
zmore.in
znew.in

34 files changed:
.gitignore [new file with mode: 0644]
INSTALL
Makefile.am
Makefile.in
build-aux/texinfo.tex
debian/README.build [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/gbp.conf [new file with mode: 0644]
debian/gzip-win32.dirs [new file with mode: 0644]
debian/gzip.lintian-overrides [new file with mode: 0644]
debian/rules [new file with mode: 0755]
debian/watch [new file with mode: 0644]
deflate.c
gzip.1
gzip.c
gzip.h
lib/.gitignore [new file with mode: 0644]
lib/error.c
lib/fcntl_.h [new file with mode: 0644]
lib/getopt.c
lib/getopt1.c
lib/getopt_.h [new file with mode: 0644]
lib/stat_.h [new file with mode: 0644]
lib/stdbool_.h [new file with mode: 0644]
lib/stdlib_.h [new file with mode: 0644]
lib/sys_time_.h [new file with mode: 0644]
lib/time_.h [new file with mode: 0644]
lib/unistd_.h [new file with mode: 0644]
m4/absolute-header.m4 [new file with mode: 0644]
trees.c

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..f76db97
--- /dev/null
@@ -0,0 +1,18 @@
+.deps
+Makefile
+*.o
+config.log
+config.status
+gunzip
+gzexe
+gzip
+zcat
+zcmp
+zdiff
+zegrep
+zfgrep
+zforce
+zgrep
+zless
+zmore
+znew
diff --git a/INSTALL b/INSTALL
index 81fd332cef8812df383d283d3f16cad10ff10f42..cbe97f5bbe3dd399e98c07d6879819643f4966a9 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -96,9 +96,9 @@ of `autoconf'.
 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.
+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 configuration parameters
 by setting variables in the command line or in the environment.  Here
@@ -111,7 +111,7 @@ is an example:
 Compiling For Multiple Architectures
 ====================================
 
-   You can compile the package for more than one kind of computer at the
+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 can use GNU `make'.  `cd' to the
 directory where you want the object files and executables to go and run
@@ -262,8 +262,7 @@ type, such as `sun4', or a canonical name which has the form:
 
 where SYSTEM can have one of these forms:
 
-     OS
-     KERNEL-OS
+     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
@@ -281,9 +280,9 @@ 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'.
+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.
@@ -311,8 +310,7 @@ an Autoconf bug.  Until the bug is fixed you can use this workaround:
 `configure' Invocation
 ======================
 
-   `configure' recognizes the following options to control how it
-operates.
+`configure' recognizes the following options to control how it operates.
 
 `--help'
 `-h'
index ac9561540504171b67cec3afae8ace8bf3d8eedd..3db0ee3d7deedf25b513f34fc68bb376751b7e29 100644 (file)
@@ -59,6 +59,9 @@ gzip.doc: gzip.1
 gzip.doc.gz: gzip.doc $(bin_PROGRAMS)
        $(AM_V_GEN)./gzip < $(srcdir)/gzip.doc >$@-t && mv $@-t $@
 
+gzip.doc.gz: gzip.doc
+       gzip <$? >$@
+
 SUFFIXES = .in
 .in:
        $(AM_V_GEN)sed \
@@ -112,6 +115,21 @@ TESTS =                                            \
 
 EXTRA_DIST += $(TESTS)
 
+# A simple test, just of gzip -- more of a sanity check than anything else.
+FILES_TO_CHECK = $(bin_SCRIPTS) $(gzip_LDADD) \
+  $(top_srcdir)/ChangeLog $(top_srcdir)/configure $(top_srcdir)/gzip.c
+check-local: $(FILES_TO_CHECK) gzip.doc.gz
+       { test '$(srcdir)' != . || GZIP_BINDIR=. ./zdiff -c gzip.doc.gz; }
+       GZIP_BINDIR=. ./zdiff -c $(srcdir)/gzip.doc $(srcdir)/gzip.doc
+       GZIP_BINDIR=. ./zdiff $(srcdir)/gzip.doc gzip.doc.gz
+       GZIP_BINDIR=. ./zdiff -c - $(srcdir)/gzip.doc <gzip.doc.gz
+       GZIP_BINDIR=. ./zdiff -c gzip.doc.gz gzip.doc.gz
+       GZIP_BINDIR=. ./zgrep -iV >/dev/null
+       for file in $(FILES_TO_CHECK); do \
+         ./gzip -cv -- "$$file" | ./gzip -d | cmp - "$$file" || exit; \
+       done
+       @echo 'Test succeeded.'
+
 install-exec-hook: remove-installed-links
 install-exec-hook remove-installed-links:
        @for prog_ext in $(bin_PROGRAMS) $(bin_SCRIPTS); do \
index 9176c71d72e5a1f89831450c1a01ff1bd50af571..7b1f8809139c6e3bd8bb811307b24fbfec56a9bf 100644 (file)
@@ -1134,6 +1134,22 @@ uninstall-binPROGRAMS:
 
 clean-binPROGRAMS:
        -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+
+installcheck-binPROGRAMS: $(bin_PROGRAMS)
+       bad=0; pid=$$$$; list="$(bin_PROGRAMS)"; for p in $$list; do \
+         case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \
+          *" $$p "* | *" $(srcdir)/$$p "*) continue;; \
+         esac; \
+         f=`echo "$$p" | \
+            sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
+         for opt in --help --version; do \
+           if "$(DESTDIR)$(bindir)/$$f" $$opt >c$${pid}_.out \
+                2>c$${pid}_.err </dev/null \
+                && test -n "`cat c$${pid}_.out`" \
+                && test -z "`cat c$${pid}_.err`"; then :; \
+           else echo "$$f does not support $$opt" 1>&2; bad=1; fi; \
+         done; \
+       done; rm -f c$${pid}_.???; exit $$bad
 gzip$(EXEEXT): $(gzip_OBJECTS) $(gzip_DEPENDENCIES) 
        @rm -f gzip$(EXEEXT)
        $(AM_V_CCLD)$(LINK) $(gzip_OBJECTS) $(gzip_LDADD) $(LIBS)
@@ -1172,6 +1188,21 @@ uninstall-binSCRIPTS:
        echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
        cd "$(DESTDIR)$(bindir)" && rm -f $$files
 
+installcheck-binSCRIPTS: $(bin_SCRIPTS)
+       bad=0; pid=$$$$; list="$(bin_SCRIPTS)"; for p in $$list; do \
+         case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \
+          *" $$p "* | *" $(srcdir)/$$p "*) continue;; \
+         esac; \
+         f=`echo "$$p" | sed 's,^.*/,,;$(transform)'`; \
+         for opt in --help --version; do \
+           if "$(DESTDIR)$(bindir)/$$f" $$opt >c$${pid}_.out \
+                2>c$${pid}_.err </dev/null \
+                && test -n "`cat c$${pid}_.out`" \
+                && test -z "`cat c$${pid}_.err`"; then :; \
+           else echo "$$f does not support $$opt" 1>&2; bad=1; fi; \
+         done; \
+       done; rm -f c$${pid}_.???; exit $$bad
+
 mostlyclean-compile:
        -rm -f *.$(OBJEXT)
 
index 91408263bc9c8ab0ad735c0974872d2f1cf58dc0..198ec194824cd3f9ed86a04a6ebb9c2f58d97f06 100644 (file)
@@ -2136,7 +2136,6 @@ end
 \setfont\defbf\bfshape{10}{\magstephalf}{OT1}
 \setfont\deftt\ttshape{10}{\magstephalf}{OT1TT}
 \setfont\defttsl\ttslshape{10}{\magstephalf}{OT1TT}
-\def\df{\let\tentt=\deftt \let\tenbf = \defbf \let\tenttsl=\defttsl \bf}
 
 % Fonts for indices, footnotes, small examples (9pt).
 \def\smallnominalsize{9pt}
diff --git a/debian/README.build b/debian/README.build
new file mode 100644 (file)
index 0000000..22892dd
--- /dev/null
@@ -0,0 +1,10 @@
+Note that using sudo during the build, such as with 'dpkg-buildpackage -rsudo'
+may fail because wine (which is needed to run mingw32) doesn't like being run
+as root when ~/.wine is owned by a normal user.  The fix for this is to either
+build gzip with another root-gaining tool (fakeroot works fine), or to run the
+entire build as root (ick!).  It may be possible to also solve this with some
+interesting set of wine options, but I'm not motivated to figure that out since
+fakeroot works.
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 15 Apr 2008 08:16:17 -0600
+
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..ee37282
--- /dev/null
@@ -0,0 +1,505 @@
+gzip (1.4-1) unstable; urgency=low
+
+  * new upstream version
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 20 Apr 2010 02:15:06 -0600
+
+gzip (1.3.12-9) unstable; urgency=high
+
+  * fix applied for CVE-2010-0001 which identified an integer underflow when 
+    decompressing files that are compressed using the LZW algorithm. This 
+    could lead to the execution of arbitrary code when trying to decompress 
+    a crafted LZW compressed gzip archive.
+  * switch to using dh_lintian for override delivery
+
+ -- Bdale Garbee <bdale@gag.com>  Thu, 21 Jan 2010 07:38:41 +1300
+
+gzip (1.3.12-8) unstable; urgency=low
+
+  * Add Carl Worth as an uploader.
+  * Fix "-f -" to work with zgrep, closes: #168606 
+  * Avoid creating undersized hufts table, closes: #507263 
+
+ -- Carl Worth <cworth@cworth.org>  Fri, 27 Feb 2009 12:54:37 -0800
+
+gzip (1.3.12-7) unstable; urgency=low
+
+  * improve package descriptions, remove ancient package relationship spec
+    in control file, closes: #484547
+
+ -- Bdale Garbee <bdale@gag.com>  Sun, 15 Feb 2009 10:54:48 -0700
+
+gzip (1.3.12-6) unstable; urgency=low
+
+  * strip the win32 gzip.exe binary during install, closes: #464455
+  * patch from Reuben Thomas for the zless.1 man page with pointers to 
+    lessfile and lesspipe, which are a better solution than zless in most
+    cases... closes: #46787, #51162
+  * fix FTBFS when using gcc-4.3, closes: #476031
+  * remove the preinst since the --assert-support-predepends check should
+    no longer be necessary
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 15 Apr 2008 14:03:26 -0600
+
+gzip (1.3.12-5) unstable; urgency=low
+
+  * patch for zgrep.in from Daniel Kobras, closes: #434429
+  * patch from upstream to fix compilation with mingw32, and patch from
+    Robert Millan to build a win32 executable if mingw32 is available, all
+    to fix a preseeding problem in the win32-loader for Debian Installer.
+    closes: #457867
+
+ -- Bdale Garbee <bdale@gag.com>  Mon, 04 Feb 2008 21:46:42 -0700
+
+gzip (1.3.12-4) unstable; urgency=low
+
+  * incorporate diffs from NMUs, closes: #434275, #433845, #438675
+  * define UNALIGNED_OK when building for amd64, closes: #386356
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 19 Dec 2007 17:48:37 -0700
+
+gzip (1.3.12-3.2) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Stop zdiff from dropping cmp's output. Patch thanks to Jorg-Volker Peetz
+    (Closes: Bug#434275)
+
+ -- Anthony Towns <aj@azure.humbug.org.au>  Sun, 14 Oct 2007 23:50:29 +1000
+
+gzip (1.3.12-3.1) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Rename futimens to gz_futimens, since glibc now defines an futimens
+    function with a different prototype.  Closes: #433845.
+  * Urgency medium for the RC bug fix.
+
+ -- Daniel Schepler <schepler@debian.org>  Sat, 18 Aug 2007 17:11:52 -0400
+
+gzip (1.3.12-3) unstable; urgency=low
+
+  * fix bindir so gunzip, et al, work again, closes: #429462
+
+ -- Bdale Garbee <bdale@gag.com>  Fri, 22 Jun 2007 01:08:59 +0100
+
+gzip (1.3.12-2) unstable; urgency=low
+
+  * fix typo in gzip fprintf, closes: #426965
+  * revert my zgrep.in patch since upstream handles alternates differently now
+
+ -- Bdale Garbee <bdale@gag.com>  Thu, 14 Jun 2007 00:17:37 -0400
+
+gzip (1.3.12-1) unstable; urgency=low
+
+  * new upstream version, closes: #177942, #225864, #362786, #366660, #367400, 
+    #383358, #402042, #404099, #404114, #419895
+  * fix delivery of upstream ChangeLog, closes: #404062
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 13 Jun 2007 18:55:42 -0400
+
+gzip (1.3.9-2) unstable; urgency=low
+
+  * change direntry ordering in gzip.texi to work around bug in install-info,
+    closes: #404048
+
+ -- Bdale Garbee <bdale@gag.com>  Thu, 21 Dec 2006 09:16:16 -0700
+
+gzip (1.3.9-1) unstable; urgency=low
+
+  * new upstream version, closes: #366660, #403308
+  * clean up a few gratuitous differences from new upstream, leaving
+    only the rsyncable patch and tweaks like zmore always using more
+  * fix spelling error in documentation, closes: #395450
+  * upstream patch for regression uncompressing null input, closes: #403970
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 20 Dec 2006 19:16:36 -0700
+
+gzip (1.3.5-15) unstable; urgency=high
+
+  * security update, covering the following alerts:
+    CVE-2006-4334 CVE-2006-4335 CVE-2006-4336 CVE-2006-4337 CVE-2006-4338
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 19 Sep 2006 06:35:26 -0600
+
+gzip (1.3.5-14) unstable; urgency=medium
+
+  * update section to match override
+  * patch from Matthew Chapman to avoid deleting input file before we're
+    sure the output file has been written without errors, closes: #366660
+  * patch from Reuben Thomas to fix zgrep return code, 
+    closes: #292896, #192891, #190442
+  * enable gzexe compressed files to work on systems where tempfile is not
+    available while retaining preference for tempfile, closes: #334540
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 20 Jun 2006 15:02:27 -0600
+
+gzip (1.3.5-13) unstable; urgency=low
+
+  * patch from Reuben Thomas fixes problem passing zgrep filenames starting
+    with dashes, closes: #342501
+  * fix a spelling error in gzip man page, closes: #356011
+  * document the fact that zless doesn't work with stdin, 
+    closes: #320226, #345036
+
+ -- Bdale Garbee <bdale@gag.com>  Sat, 15 Apr 2006 01:31:54 -0600
+
+gzip (1.3.5-12) unstable; urgency=low
+
+  * merge patch from Matt Zimmerman for futex hang due to improper signal
+    handling, closes: #310053, #315612
+  * merge patch to add --rsyncable to the man page, closes: #289616, #295721
+  * don't return failing result code on harmless warning, closes: #169669
+
+ -- Bdale Garbee <bdale@gag.com>  Mon, 11 Jul 2005 22:10:51 +0300
+
+gzip (1.3.5-11) unstable; urgency=low
+
+  * patch from Peter Samuelson for bashism in zgrep, 
+    closes: #314342, #314211, #312380, #310329
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 15 Jun 2005 14:39:11 -0600
+
+gzip (1.3.5-10) unstable; urgency=medium
+
+  * remove PAGER reference from zmore.1, closes: #263792
+  * patch to improve zgrep argument sanitizing (CAN-2005-0758),
+    closes: #308379
+  * patch isolated by Petter Reinholdtsen for CAN-2005-0988, closes: #303927
+  * patch for dir traversal bug (CAN-2005-1228), closes: #305255
+  * up the priority a click because of the security fixes
+  * patch to support cross building, closes: #283730
+
+ -- Bdale Garbee <bdale@gag.com>  Fri, 20 May 2005 22:34:49 -0600
+
+gzip (1.3.5-9) unstable; urgency=low
+
+  * eliminate the autoconf and automake build dependencies, since they are
+    no longer needed, closes: #250766
+  * improve temp file usage in gzexe, closes: #257314, #259043
+  * have zmore use 'more' instead of honoring $PAGER, to avoid violating 
+    the principle of least astonishment, closes: #234212
+  * fix zgrep choke on filenames including a pipe character, closes: #216211
+  * incorporate watch file, closes: #248722
+  * suggest less, since we provide zless, closes: #217925
+  * use signames instead of signumbers for trap calls, closes: #259284
+
+ -- Bdale Garbee <bdale@gag.com>  Sat, 24 Jul 2004 01:23:03 -0600
+
+gzip (1.3.5-8) unstable; urgency=low
+
+  * run autoreconf -i to address problem reported with dir.old.gz being
+    included on rebuilds, closes: #249519
+  * change automake build dependency from automake1.7 to automaken
+  * add lintian overrides to squelch the hardlink warnings
+  * fix typo in inflate.c comments, closes: #201881
+
+ -- Bdale Garbee <bdale@gag.com>  Sun, 23 May 2004 01:07:03 -0600
+
+gzip (1.3.5-7) unstable; urgency=low
+
+  * patch from David Mosberger to incorporate work done by Sverre Jarp on
+    an ia64 version of match.c content.
+
+ -- Bdale Garbee <bdale@gag.com>  Thu, 10 Jul 2003 08:45:27 -0600
+
+gzip (1.3.5-6) unstable; urgency=medium
+
+  * patch for insecure temp file usage in znew, closes: #193375
+
+ -- Bdale Garbee <bdale@gag.com>  Sat,  7 Jun 2003 09:05:11 -0600
+
+gzip (1.3.5-5) unstable; urgency=low
+
+  * apply patch from Anthony Towns that fixes seg faults on alpha during
+    build of Xfree86 at the expense of slightly decreasing the effectiveness
+    of the deflate implementation.  closes: #184057, #187417
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 16 Apr 2003 11:24:23 -0600
+
+gzip (1.3.5-4) unstable; urgency=low
+
+  * merge patch from Rusty Russell that adds --rsyncable option to gzip.  
+    This modifies the output stream to allow rsync to transfer updated .gz 
+    files much more effectively.  The resulting .gz files should be compatible
+    with the existing gunzip.  The plan is that if this works out well for 
+    Debian, the functionality will be included in a future upstream gzip 
+    release.  Closes: #116183, #118118, #134741
+
+ -- Bdale Garbee <bdale@gag.com>  Thu, 13 Feb 2003 23:50:23 -0700
+
+gzip (1.3.5-3) unstable; urgency=low
+
+  * upload a fresh version so m68k, et al, will rebuild, closes: #167790
+
+ -- Bdale Garbee <bdale@gag.com>  Wed,  6 Nov 2002 16:13:42 -0700
+
+gzip (1.3.5-2) unstable; urgency=low
+
+  * fix gzexe.in again as per what I did for 1.3.2-3 that accidentally got
+    lost when I merged 1.3.5 from upstream... sigh.  Closes: #167150
+  * hack on gzip.texi a little harder to squelch warning at install time from
+    Debian's install-info, closes: #164106
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 30 Oct 2002 20:21:42 -0700
+
+gzip (1.3.5-1) unstable; urgency=low
+
+  * new upstream version
+  * fixes a bug in the incorrect-suffix diagnostic, which can lead to a 
+    core dump, closes: #152579
+  * removes dangling output symlinks properly, closes: #144759
+  * zless no longer thinks it is zmore in usage message, closes: #121810
+  * zless replaced with a much simpler script, closes: #124097
+  * uses shell pattern matching instead of 'expr', closes: #123295
+  * man page suggests how to use gunzip on zip files, closes: #146019
+  * uses "trap -" to avoid bashism, closes: #140972, #157111
+  * accepts __i386 and __i386__ as synonyms for i386, closes: #152694
+  * fixes printing values greater than 10 * 2**32 bytes, closes: #141189
+  * includes fix for zforce needing -v, closes: #123294
+  * hack gzip.texi so that the Debian install-info doesn't choke on it (grrr),
+    and add texinfo as a build dependency
+  * eliminate things hard-coded in postinst and prerm now handled by debhelper
+
+ -- Bdale Garbee <bdale@gag.com>  Wed,  9 Oct 2002 09:05:27 -0600
+
+gzip (1.3.2-3) unstable; urgency=low
+
+  * modify gzexe.in to hard-code /bin/gzip instead of trying to use BINDIR
+    which yields /usr/bin/gzip.  Don't use PATH since we have no idea what it
+    might be when the gzexe'd executable gets run.  Closes: #119641
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 14 Nov 2001 23:00:59 -0700
+
+gzip (1.3.2-2) unstable; urgency=low
+
+  * fix silly mistake made when moving man pages from hard to soft links, so
+    man pages for zegrep, zfgrep, and uncompress work again, closes: #118325
+
+ -- Bdale Garbee <bdale@gag.com>  Mon,  5 Nov 2001 00:53:40 -0700
+
+gzip (1.3.2-1) unstable; urgency=low
+
+  * new upstream release, incorporating my diffs to 1.3.1
+
+ -- Bdale Garbee <bdale@gag.com>  Sun,  4 Nov 2001 09:47:40 -0700
+
+gzip (1.3.1-2) unstable; urgency=low
+
+  * add build dependencies on autoconf and automake
+  * fix infodir spec so we install in the build tree, not the system directory
+
+ -- Bdale Garbee <bdale@gag.com>  Sat,  3 Nov 2001 02:18:06 -0700
+
+gzip (1.3.1-1) unstable; urgency=low
+
+  * new upstream version!  From alpha.gnu.org, on the explicit advice of the 
+    current upstream maintainers, who are working with Debian to prepare a new
+    stable release that addresses many of the open issues in our BTS.  
+    .
+    large file support handled in configure, closes: #108612, #83061, #113000
+    it appears the subtle problem with concatenation is fixed, closes: #114591
+    various segfault problems appear fixed, closes: #46312
+    gzip -r issues fixed, closes: #53645, #106186
+    problem with --no-filename option fixed, closes: #59067
+    zgrep -r disallowed - "I did not use the patch as it was not a complete 
+    . fix for the problem and I thought it would cause more problems than
+    . it would cure.  Instead, I simply disallowed zgrep -r", closes: #81288
+    error message reworded, closes: #76238
+    compression factor output fixed, closes: #80362
+    zgrep -H fixed, closes: #84371
+    permission issue when forced to compress linked file fixed, closes: #88918
+    manpage hardlinks fixed, closes: #94733
+    gzip --help now goes to stdout, closes: #97020
+    zless no longer runs less if file doesn't exist, closes: #109097
+    problem with -best fixed, closes: #17650
+    zgrep now understands --, closes: #28475
+    file size output by gzip fixed for large files, closes: #40721
+  * fix location referenced for GPL on Debian systems, closes: #112095
+  * move install-info remove call from from postrm to prerm
+
+ -- Bdale Garbee <bdale@gag.com>  Sat,  3 Nov 2001 01:01:02 -0700
+
+gzip (1.2.4-33) unstable; urgency=low
+
+  * update to current policy
+
+ -- Bdale Garbee <bdale@gag.com>  Thu,  2 Dec 1999 01:10:58 -0700
+
+gzip (1.2.4-32) unstable; urgency=low
+
+  * update prototype for and definition of basename function for compatibility
+    with glibc2.0, still in use on m68k.  Closes: #45058
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 15 Sep 1999 02:01:47 -0600
+
+gzip (1.2.4-31) unstable; urgency=medium
+
+  * fix problems I induced while merging the upstream patch in the last upload,
+    most notably omitting zless from the package. 
+    Closes: #44883, #44885, #44890, #44882, #44887, #44895, #44896
+ -- Bdale Garbee <bdale@gag.com>  Sun, 12 Sep 1999 12:06:00 -0600
+
+gzip (1.2.4-30) unstable; urgency=low
+
+  * upstream patch, closes: #28872
+      1998-11-18  Paul Eggert  <eggert@twinsun.com>
+      gzip.c (get_method): Don't complain about trailing zeros at
+      the end of a gzipped file, as they're commonly appended to fill
+      out a block (e.g. by GNU tar).
+  * update to FHS compliance
+
+ -- Bdale Garbee <bdale@gag.com>  Fri, 10 Sep 1999 21:34:07 -0600
+
+gzip (1.2.4-29) unstable; urgency=low
+
+  * apply patch from Vincent Renardias that improves behavior when trying to
+    decompress a corrupted .gz file.  Closes 7472, 16385
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 27 Jan 1999 20:50:12 -0700
+
+gzip (1.2.4-28) frozen unstable; urgency=medium
+
+  * patch zforce to make it work at all, closes 22760
+  * patch to fix decompression of concatenated gzip files, closes 30537
+
+ -- Bdale Garbee <bdale@gag.com>  Fri, 22 Jan 1999 10:43:09 -0700
+
+gzip (1.2.4-27) frozen unstable; urgency=low
+
+  * patch from Jean-loup (upstream maintainer) for zgrep.in to fix the
+    problems with -A and -B successfully passing to grep.  Closes 21209.
+
+ -- Bdale Garbee <bdale@gag.com>  Sat, 25 Apr 1998 22:47:15 -0600
+
+gzip (1.2.4-26) frozen unstable; urgency=low
+
+  * fix FSF address in copyright file, lintian now reports no errors
+  * minor tweak to Makefile to fix warnings during dh_installmanpages run
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 24 Mar 1998 00:40:48 -0700
+
+gzip (1.2.4-25) frozen unstable; urgency=low
+
+  * update znew.in and zdiff.in to do save tempfile handling, closes 19794
+
+ -- Bdale Garbee <bdale@gag.com>  Sat, 21 Mar 1998 23:48:26 -0700
+
+gzip (1.2.4-24) unstable; urgency=low
+
+  * minor fix for complaints about short files, closes 19159
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 11 Mar 1998 02:21:50 -0700
+
+gzip (1.2.4-23) unstable; urgency=high
+
+  * respond to security advisory from Alan Cox via Christian Hudon, fixes
+    an obscure possibility to get gzip to execute code
+
+ -- Bdale Garbee <bdale@gag.com>  Wed, 11 Mar 1998 02:16:59 -0700
+
+gzip (1.2.4-22) unstable; urgency=high
+
+  * gzexe modified to use tempfile in response to security advisory
+
+ -- Bdale Garbee <bdale@gag.com>  Sat, 31 Jan 1998 14:30:20 -0700
+
+gzip (1.2.4-21) unstable; urgency=low
+
+  * fix from the upstream maintainer for voluminous "Broken Pipe" messages
+    when using 'zgrep -l' or equivalent.  Closes bug 15178.
+
+ -- Bdale Garbee <bdale@gag.com>  Sun,  4 Jan 1998 00:56:21 -0700
+
+gzip (1.2.4-20) unstable; urgency=low
+
+  * freshen rules file to match current debhelper
+  * improve handling of undocumented executables.  Closes bug 13578.
+
+ -- Bdale Garbee <bdale@gag.com>  Sun,  4 Jan 1998 00:56:21 -0700
+
+gzip (1.2.4-19) unstable; urgency=low
+
+  * change dependency to Pre-Depends, to keep dpkg from getting hosed during
+    libc6 upgrades.  Closes 15091.
+  * switch from debmake to debhelper.  In the process, closes 15412.
+
+ -- Bdale Garbee <bdale@gag.com>  Mon,  8 Dec 1997 23:42:49 -0700
+
+gzip (1.2.4-18) unstable; urgency=low
+
+  * don't install INSTALL in the doc directory, closes bug 13224.
+
+ -- Bdale Garbee <bdale@gag.com>  Fri,  5 Sep 1997 15:06:35 -0600
+
+gzip (1.2.4-17) unstable; urgency=low
+
+  * fix distribution problem in changelog file
+
+ -- Bdale Garbee <bdale@gag.com>  Fri,  5 Sep 1997 15:06:35 -0600
+
+gzip (1.2.4-16) stable frozen unstable; urgency=low
+
+  * libc6
+  * tweaks to rules file to install Changelog, closes bug 12488
+
+ -- Bdale Garbee <bdale@gag.com>  Thu,  4 Sep 1997 22:46:28 -0600
+
+gzip (1.2.4-15) stable frozen unstable; urgency=low
+
+  * fix minor security issue - race condition reported on bugtraq list
+  * rework debian/rules to build with debugging then strip
+
+ -- Bdale Garbee <bdale@gag.com>  Fri, 14 Mar 1997 21:14:44 -0700
+
+gzip (1.2.4-14) stable frozen unstable; urgency=medium
+
+  * The -13 upload was built against a libc5 too new for 'stable'.  
+
+ -- Bdale Garbee <bdale@gag.com>  Thu, 28 Nov 1996 11:37:31 -0700
+
+gzip (1.2.4-13) stable frozen unstable; urgency=medium
+
+  * Fix missing "essential" flag on package, lost during standards update.
+  * Push this version back into stable to solve the 'compress' link problem.
+
+ -- Bdale Garbee <bdale@gag.com>  Tue, 19 Nov 1996 09:14:14 -0700
+
+gzip (1.2.4-12) unstable; urgency=low
+
+  * New packag format.
+
+ -- Bdale Garbee <bdale@gag.com>  Sat, 02 Nov 1996 14:47:42 -0800
+
+
+Thu Jul 18 01:30:22 MDT 1996   Bdale Garbee    <bdale@gag.com>
+
+       * add zegrep and zfgrep links in /usr/bin (Bug#3326)
+       * add an extended description (Bug#3591)
+       * tweak control files to use dpkg-name, etc.
+
+Fri May 24 07:37:54 MDT 1996   Bdale Garbee    <bdale@gag.com>
+
+       * don't provide a 'compress' link since it breaks things, but provide
+         an 'uncompress' link since it's useful.
+       * fix some administrivia
+
+Sun Apr 14 20:39:19 MDT 1996   Bdale Garbee    <bdale@gag.com>
+
+       * change gzexe.in to not use BINDIR, but assume gzip is in PATH
+       * add Architecture field in the control file
+
+Wed Jan 17 00:07:00 MST 1996   Bdale Garbee    <bdale@gag.com>
+
+       * switch targets in the Makefile to also install the links called
+         'compress' and 'uncompress' since some utilities care about these,
+         and we're unlikely to ever have a 'compress' package because of the
+         intellectual property issues.
+
+Sat Dec  2 23:45:40 MST 1995   Bdale Garbee    <bdale@gag.com>
+
+       * building for ELF
+       * add 'zless' as a near-clone of 'zmore', closes bug 1776
+       * unable to duplicate bug 1090, something has improved since then?
+       * add libc5 dependency
+       * new maintainer
+
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..a2597c5
--- /dev/null
@@ -0,0 +1,27 @@
+Source: gzip
+Section: utils
+Priority: required
+Maintainer: Bdale Garbee <bdale@gag.com>
+Uploaders: Carl Worth <cworth@cworth.org>
+Build-Depends: debhelper (>= 5), texinfo
+Build-Depends-Indep: mingw32
+Standards-Version: 3.8.0
+
+Package: gzip
+Architecture: any
+Pre-Depends: ${shlibs:Depends}
+Essential: yes
+Suggests: less
+Description: GNU compression utilities
+ This package provides the standard GNU file compression utilities, which 
+ are also the default compression tools for Debian.  They typically operate 
+ on files with names ending in '.gz', but can also decompress files ending 
+ in '.Z' created with 'compress'.
+
+Package: gzip-win32
+Architecture: all
+Priority: extra
+Suggests: wine
+Description: The GNU compression utility (win32 build)
+ This is a win32 version of gzip, meant to be used by the win32-loader
+ component of Debian-Installer.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..b0e1c4a
--- /dev/null
@@ -0,0 +1,24 @@
+This package is maintained for Debian by Bdale Garbee <bdale@gag.com>, and
+was built from the sources found at:
+
+        ftp://ftp.gnu.org/gnu/gzip/
+
+Copyright (C) 1999, 2001, 2002, 2006, 2007 Free Software Foundation, Inc.
+Copyright (C) 1992-1993 Jean-loup Gailly
+
+   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.  */
+
+On Debian GNU/Linux systems, the complete text of the GNU General
+Public License can be found in `/usr/share/common-licenses/GPL'.
diff --git a/debian/dirs b/debian/dirs
new file mode 100644 (file)
index 0000000..b90abdd
--- /dev/null
@@ -0,0 +1,4 @@
+bin
+usr/share/info
+usr/share/lintian/overrides
+usr/share/man/man1
diff --git a/debian/gbp.conf b/debian/gbp.conf
new file mode 100644 (file)
index 0000000..d2bc639
--- /dev/null
@@ -0,0 +1,46 @@
+# Configuration file for git-buildpackage and friends
+
+[DEFAULT]
+# the default build command:
+#builder = debuild -i\.git/ -I.git
+# the default clean command:
+#cleaner = debuild clean
+# the default branch for upstream sources:
+upstream-branch = upstream
+# the default branch for the debian patch:
+debian-branch = master
+# the default tag formats used:
+#upstream-tag = upstream/%(version)s
+#debian-tag = debian/%(version)s
+# use pristine-tar:
+pristine-tar = True
+
+# Options only affecting git-buildpackage
+[git-buildpackage]
+#upstream-branch = dfsgclean
+# uncomment this to automatically GPG sign tags
+#sign-tags = True
+# keyid to GPG sign tags with
+#keyid = 0xdeadbeef
+# push to a remote repository after a successful tag: 
+posttag = git push --mirror
+# use this for more svn-buildpackage like behaviour:
+export-dir = ../build-area/gzip/
+#tarball-dir = ../tarballs/
+
+# Options only affecting git-import-orig
+[git-import-orig]
+#upstream-branch = newupstream
+#debian-branch = dfsgclean
+#filter = .svn
+
+# Options only affecting git-import-dsc
+[git-import-dsc]
+#upstream-branch = svn-upstream
+#filter = [ 'CVS', '.cvsignore' ]
+
+# Options only affecting git-dch
+[git-dch]
+#git-log = --no-merges
+#snapshot-number = snapshot + 1
+
diff --git a/debian/gzip-win32.dirs b/debian/gzip-win32.dirs
new file mode 100644 (file)
index 0000000..56f2ee8
--- /dev/null
@@ -0,0 +1 @@
+usr/share/win32
diff --git a/debian/gzip.lintian-overrides b/debian/gzip.lintian-overrides
new file mode 100644 (file)
index 0000000..61fcf9e
--- /dev/null
@@ -0,0 +1,6 @@
+gzip: package-contains-hardlink bin/gunzip
+gzip: package-contains-hardlink bin/zcat
+gzip: package-contains-hardlink bin/zcmp
+gzip: package-contains-hardlink bin/zegrep
+gzip: package-contains-hardlink bin/zfgrep
+gzip: package-contains-hardlink bin/uncompress
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..ff33835
--- /dev/null
@@ -0,0 +1,111 @@
+#!/usr/bin/make -f
+#      Debian rules file for gzip, requires the debhelper package.
+#      Crafted by Bdale Garbee, bdale@gag.com, 5 November 2000
+
+# Comment this to turn off debhelper verbose mode.
+export DH_VERBOSE=1
+
+DEB_BUILD_GNU_TYPE = $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+DEB_HOST_GNU_TYPE = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
+CONFARGS = --host=$(DEB_HOST_GNU_TYPE)
+endif
+
+buildarch := $(shell dpkg-architecture -qDEB_BUILD_ARCH)
+ifeq ($(buildarch),amd64)
+CFLAGS=-g -O2 -Wall -DUNALIGNED_OK
+else
+CFLAGS=-g -O2 -Wall
+endif
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       mkdir -p build
+       cd build && ../configure \
+               --prefix=/usr --bindir=/bin \
+               --infodir=`pwd`/debian/gzip/usr/share/info \
+               --mandir=`pwd`/debian/gzip/usr/share/man $(CONFARGS)
+       touch configure-stamp
+
+configure-win32: configure-win32-stamp
+configure-win32-stamp:
+       dh_testdir
+       mkdir -p build-win32
+       cd build-win32 && ../configure --host=i586-mingw32msvc
+       touch configure-win32-stamp
+
+build: build-stamp 
+build-stamp: configure-stamp
+       dh_testdir
+       $(MAKE) -C build
+       touch build-stamp
+
+build-win32: build-win32-stamp
+build-win32-stamp: configure-win32-stamp
+       dh_testdir
+       $(MAKE) -C build-win32
+       touch build-win32-stamp
+
+clean:
+       dh_testdir
+       dh_testroot
+       -rm -f build-stamp build-win32-stamp configure-stamp configure-win32-stamp
+       -rm -rf build build-win32
+       dh_clean
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k
+       dh_installdirs
+       $(MAKE) -C build install prefix=`pwd`/debian/gzip/usr bindir=`pwd`/debian/gzip/bin 
+
+install-win32: build-win32
+       dh_testdir
+       dh_testroot
+       dh_clean -k
+       dh_installdirs
+       i586-mingw32msvc-strip build-win32/gzip.exe
+       install -m 0755 build-win32/gzip.exe debian/gzip-win32/usr/share/win32/
+
+binary-indep:  build-win32 install-win32
+       dh_testdir -i
+       dh_testroot -i
+       dh_installdocs -i README* TODO
+       dh_installchangelogs -i ChangeLog
+       dh_lintian -i
+       dh_compress -i
+       dh_fixperms -i
+       dh_installdeb -i
+       dh_gencontrol -i
+       dh_md5sums -i
+       dh_builddeb -i
+
+binary-arch:   build install
+       dh_testdir -s
+       dh_testroot -s
+       dh_installdocs -s README* TODO
+       dh_installman *.1
+       dh_installinfo -s doc/gzip.info
+       dh_installchangelogs -s ChangeLog
+       dh_link -s
+       dh_lintian -s
+       dh_strip -s
+       dh_compress -s
+       ln -s gunzip.1.gz debian/gzip/usr/share/man/man1/uncompress.1.gz
+       ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zegrep.1.gz
+       ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zfgrep.1.gz
+       dh_fixperms -s
+       # You may want to make some executables suid here.
+       dh_makeshlibs -s
+       dh_installdeb -s
+       dh_shlibdeps -s
+       dh_gencontrol -s
+       dh_md5sums -s
+       dh_builddeb -s
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
+.PHONY: build-win32 install-win32 configure-win32
+
diff --git a/debian/watch b/debian/watch
new file mode 100644 (file)
index 0000000..8ee7a1b
--- /dev/null
@@ -0,0 +1,2 @@
+version=2
+ftp://ftp.gnu.org/gnu/gzip/gzip-([\d\.\d]+)\.tar\.gz
index 0950391ee88ba44a67a36ce4f1b14c87f79ebaa3..e83b5a383914aeb3a4d2626312aeb653a431e4d4 100644 (file)
--- a/deflate.c
+++ b/deflate.c
 #endif
 /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
 
+#ifndef RSYNC_WIN
+#  define RSYNC_WIN 4096
+#endif
+/* Size of rsync window, must be < MAX_DIST */
+
+#define RSYNC_SUM_MATCH(sum) ((sum) % RSYNC_WIN == 0)
+/* Whether window sum matches magic value */
+
 /* ===========================================================================
  * Local data used by the "longest match" routines.
  */
@@ -212,6 +220,8 @@ local int compr_level;
 unsigned near good_match;
 /* Use a faster search when the previous match is longer than this */
 
+local ulg rsync_sum;  /* rolling sum of rsync window */
+local ulg rsync_chunk_end; /* next rsync sequence point */
 
 /* Values for max_lazy_match, good_match and max_chain_length, depending on
  * the desired pack level (0..9). The values given below have been tuned to
@@ -307,6 +317,10 @@ void lm_init (pack_level, flags)
 #endif
     /* prev will be initialized on the fly */
 
+    /* rsync params */
+    rsync_chunk_end = 0xFFFFFFFFUL;
+    rsync_sum = 0;
+
     /* Set the default configuration parameters:
      */
     max_lazy_match   = configuration_table[pack_level].max_lazy;
@@ -543,6 +557,8 @@ local void fill_window()
         memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
         match_start -= WSIZE;
         strstart    -= WSIZE; /* we now have strstart >= MAX_DIST: */
+       if (rsync_chunk_end != 0xFFFFFFFFUL)
+           rsync_chunk_end -= WSIZE;
 
         block_start -= (long) WSIZE;
 
@@ -570,13 +586,46 @@ local void fill_window()
     }
 }
 
+local void rsync_roll(start, num)
+    unsigned start;
+    unsigned num;
+{
+    unsigned i;
+
+    if (start < RSYNC_WIN) {
+       /* before window fills. */
+       for (i = start; i < RSYNC_WIN; i++) {
+           if (i == start + num) return;
+           rsync_sum += (ulg)window[i];
+       }
+       num -= (RSYNC_WIN - start);
+       start = RSYNC_WIN;
+    }
+
+    /* buffer after window full */
+    for (i = start; i < start+num; i++) {
+       /* New character in */
+       rsync_sum += (ulg)window[i];
+       /* Old character out */
+       rsync_sum -= (ulg)window[i - RSYNC_WIN];
+       if (rsync_chunk_end == 0xFFFFFFFFUL && RSYNC_SUM_MATCH(rsync_sum))
+           rsync_chunk_end = i;
+    }
+}
+
+/* ===========================================================================
+ * Set rsync_chunk_end if window sum matches magic value.
+ */
+#define RSYNC_ROLL(s, n) \
+   do { if (rsync) rsync_roll((s), (n)); } while(0)
+
 /* ===========================================================================
  * Flush the current block, with given end-of-file flag.
  * IN assertion: strstart is set to the end of the current match.
  */
 #define FLUSH_BLOCK(eof) \
    flush_block(block_start >= 0L ? (char*)&window[(unsigned)block_start] : \
-                (char*)NULL, (long)strstart - block_start, (eof))
+                (char*)NULL, (long)strstart - block_start, flush-1, (eof))
 
 /* ===========================================================================
  * Processes a new input file and return its compressed length. This
@@ -587,7 +636,7 @@ local void fill_window()
 local off_t deflate_fast()
 {
     IPos hash_head; /* head of the hash chain */
-    int flush;      /* set if current block must be flushed */
+    int flush;      /* set if current block must be flushed, 2=>and padded  */
     unsigned match_length = 0;  /* length of best match */
 
     prev_length = MIN_MATCH-1;
@@ -617,6 +666,7 @@ local off_t deflate_fast()
 
             lookahead -= match_length;
 
+           RSYNC_ROLL(strstart, match_length);
            /* Insert new strings in the hash table only if the match length
              * is not too large. This saves time but degrades compression.
              */
@@ -645,9 +695,14 @@ local off_t deflate_fast()
             /* No match, output a literal byte */
             Tracevv((stderr,"%c",window[strstart]));
             flush = ct_tally (0, window[strstart]);
+           RSYNC_ROLL(strstart, 1);
             lookahead--;
            strstart++;
         }
+       if (rsync && strstart > rsync_chunk_end) {
+           rsync_chunk_end = 0xFFFFFFFFUL;
+           flush = 2;
+       } 
         if (flush) FLUSH_BLOCK(0), block_start = strstart;
 
         /* Make sure that we always have enough lookahead, except
@@ -721,6 +776,7 @@ off_t deflate()
              */
             lookahead -= prev_length-1;
             prev_length -= 2;
+           RSYNC_ROLL(strstart, prev_length+1);
             do {
                 strstart++;
                 INSERT_STRING(strstart, hash_head);
@@ -733,24 +789,39 @@ off_t deflate()
             match_available = 0;
             match_length = MIN_MATCH-1;
             strstart++;
-            if (flush) FLUSH_BLOCK(0), block_start = strstart;
 
+           if (rsync && strstart > rsync_chunk_end) {
+               rsync_chunk_end = 0xFFFFFFFFUL;
+               flush = 2;
+           }
+            if (flush) FLUSH_BLOCK(0), block_start = strstart;
         } else if (match_available) {
             /* If there was no match at the previous position, output a
              * single literal. If there was a match but the current match
              * is longer, truncate the previous match to a single literal.
              */
             Tracevv((stderr,"%c",window[strstart-1]));
-            if (ct_tally (0, window[strstart-1])) {
-                FLUSH_BLOCK(0), block_start = strstart;
-            }
+           flush = ct_tally (0, window[strstart-1]);
+           if (rsync && strstart > rsync_chunk_end) {
+               rsync_chunk_end = 0xFFFFFFFFUL;
+               flush = 2;
+           }
+            if (flush) FLUSH_BLOCK(0), block_start = strstart;
+           RSYNC_ROLL(strstart, 1);
             strstart++;
             lookahead--;
         } else {
             /* There is no previous match to compare with, wait for
              * the next step to decide.
              */
+           if (rsync && strstart > rsync_chunk_end) {
+               /* Reset huffman tree */
+               rsync_chunk_end = 0xFFFFFFFFUL;
+               flush = 2;
+               FLUSH_BLOCK(0), block_start = strstart;
+           }
             match_available = 1;
+           RSYNC_ROLL(strstart, 1);
             strstart++;
             lookahead--;
         }
diff --git a/gzip.1 b/gzip.1
index bdf69435c8c9ade9141b038a81e1445a82e898c0..d8fe0b99e81015ab92a9b5d6cd82c03aa18dce44 100644 (file)
--- a/gzip.1
+++ b/gzip.1
@@ -290,6 +290,15 @@ will descend into the directory and compress all the files it finds there
 .I gunzip
 ).
 .TP
+.B --rsyncable
+While compressing, synchronize the output occasionally based on the input.
+This increases size by less than 1 percent most cases, but means that the
+.BR rsync (1)
+program can much more efficiently synchronize files compressed with this flag.
+.I gunzip
+cannot tell the difference between a compressed file created with this option,
+and one created without it.
+.TP
 .B \-S .suf   --suffix .suf
 Use suffix .suf instead of .gz. Any suffix can be given, but suffixes
 other than .z and .gz should be avoided to avoid confusion when files
diff --git a/gzip.c b/gzip.c
index 9e2a890fc12040575a848a90f965ffe48d1ef1db..415ebc5fc758b8f149548e14a43c38ae6986aa96 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -218,6 +218,31 @@ int  ofd;                  /* output file descriptor */
 unsigned insize;           /* valid bytes in inbuf */
 unsigned inptr;            /* index of next byte to be processed in inbuf */
 unsigned outcnt;           /* bytes in output buffer */
+int rsync = 0;             /* make ryncable chunks */
+
+static int handled_sig[] =
+  {
+    /* SIGINT must be first, as 'foreground' depends on it.  */
+    SIGINT
+
+#ifdef SIGHUP
+    , SIGHUP
+#endif
+#ifdef SIGPIPE
+    , SIGPIPE
+#else
+# define SIGPIPE 0
+#endif
+#ifdef SIGTERM
+    , SIGTERM
+#endif
+#ifdef SIGXCPU
+    , SIGXCPU
+#endif
+#ifdef SIGXFSZ
+    , SIGXFSZ
+#endif
+  };
 
 static int handled_sig[] =
   {
@@ -271,6 +296,7 @@ struct option longopts[] =
     {"best",       0, 0, '9'}, /* compress better */
     {"lzw",        0, 0, 'Z'}, /* make output compatible with old compress */
     {"bits",       1, 0, 'b'}, /* max number of bits per code (implies -Z) */
+    {"rsyncable",  0, 0, 'R'}, /* make rsync-friendly archive */
     { 0, 0, 0, 0 }
 };
 
@@ -352,6 +378,7 @@ local void help()
  "  -Z, --lzw         produce output compatible with old compress",
  "  -b, --bits=BITS   max number of bits per code (implies -Z)",
 #endif
+ "    --rsyncable   Make rsync-friendly archive",
  "",
  "With no FILE, or when FILE is -, read standard input.",
  "",
@@ -478,7 +505,9 @@ int main (int argc, char **argv)
 #else
            recursive = 1;
 #endif
-           break;
+       case 'R':
+           rsync = 1; break;
+
        case 'S':
 #ifdef NO_MULTIPLE_DOTS
             if (*optarg == '.') optarg++;
diff --git a/gzip.h b/gzip.h
index 0c3dd6846eb90495b018414a60a242ceb7ba62db..642d6e05d5f45ba407a1abce57979e6f76df975a 100644 (file)
--- a/gzip.h
+++ b/gzip.h
@@ -146,6 +146,7 @@ EXTERN(uch, window);         /* Sliding window and suffix table (unlzw) */
 extern unsigned insize; /* valid bytes in inbuf */
 extern unsigned inptr;  /* index of next byte to be processed in inbuf */
 extern unsigned outcnt; /* bytes in output buffer */
+extern int rsync;  /* deflate into rsyncable chunks */
 
 extern off_t bytes_in;   /* number of input bytes */
 extern off_t bytes_out;  /* number of output bytes */
@@ -294,7 +295,7 @@ off_t deflate OF((void));
         /* in trees.c */
 void ct_init     OF((ush *attr, int *method));
 int  ct_tally    OF((int dist, int lc));
-off_t flush_block OF((char *buf, ulg stored_len, int eof));
+off_t flush_block OF((char *buf, ulg stored_len, int pad, int eof));
 
         /* in bits.c */
 void     bi_init    OF((file_t zipfile));
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644 (file)
index 0000000..2ed5198
--- /dev/null
@@ -0,0 +1,8 @@
+config.h
+fcntl.h
+libgzip.a
+stamp-h1
+stdlib.h
+time.h
+unistd.h
+sys/stat.h
index c79e8d42cb30f51c5284529dc2713065e9736a3c..7e7ac2a73c5995e52044ff4ae13f97fb6dc339b4 100644 (file)
@@ -261,6 +261,7 @@ error (int status, int errnum, const char *message, ...)
      cancellation.  Therefore disable cancellation for now.  */
   int state = PTHREAD_CANCEL_ENABLE;
   __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
+
                    0);
 #endif
 
diff --git a/lib/fcntl_.h b/lib/fcntl_.h
new file mode 100644 (file)
index 0000000..e16ad54
--- /dev/null
@@ -0,0 +1,116 @@
+/* Like <fcntl.h>, but with non-working flags defined to 0.
+
+   Copyright (C) 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.  */
+
+/* written by Paul Eggert */
+
+#ifndef _GL_FCNTL_H
+#define _GL_FCNTL_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include @ABSOLUTE_FCNTL_H@
+
+
+/* Declare overridden functions.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef FCHDIR_REPLACEMENT
+# define open rpl_open
+extern int open (const char *, int, ...);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+/* Fix up the O_* macros.  */
+
+#if !defined O_DIRECT && defined O_DIRECTIO
+/* Tru64 spells it `O_DIRECTIO'.  */
+# define O_DIRECT O_DIRECTIO
+#endif
+
+#ifndef O_DIRECT
+# define O_DIRECT 0
+#endif
+
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
+#ifndef O_DSYNC
+# define O_DSYNC 0
+#endif
+
+#ifndef O_NDELAY
+# define O_NDELAY 0
+#endif
+
+#ifndef O_NOATIME
+# define O_NOATIME 0
+#endif
+
+#ifndef O_NONBLOCK
+# define O_NONBLOCK O_NDELAY
+#endif
+
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
+#ifndef O_NOLINKS
+# define O_NOLINKS 0
+#endif
+
+#ifndef O_RSYNC
+# define O_RSYNC 0
+#endif
+
+#ifndef O_SYNC
+# define O_SYNC 0
+#endif
+
+/* For systems that distinguish between text and binary I/O.
+   O_BINARY is usually declared in fcntl.h  */
+#if !defined O_BINARY && defined _O_BINARY
+  /* For MSC-compatible compilers.  */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+
+#ifdef __BEOS__
+  /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+# define O_TEXT 0
+#endif
+
+#endif
index 406d5b71a3d18b9ea3213c1693bc7454ef59eeee..3580ad825c64792235a1d94f134235fc834c2b81 100644 (file)
@@ -1,23 +1,24 @@
 /* Getopt for GNU.
-   NOTE: getopt is part of the C library, so if you don't know what
+   NOTE: getopt is now part of the C library, so if you don't know what
    "Keep this file name-space clean" means, talk to drepper@gnu.org
    before changing it!
-   Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2010 Free Software
-   Foundation, Inc.
+   Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,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
+   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.
+   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, see <http://www.gnu.org/licenses/>.  */
+   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.  */
 \f
 #ifndef _LIBC
 # include <config.h>
 #include <string.h>
 #include <unistd.h>
 
+#ifdef __VMS
+# include <unixlib.h>
+#endif
+
 #ifdef _LIBC
 # include <libintl.h>
 #else
@@ -45,9 +50,8 @@
 # define attribute_hidden
 #endif
 
-/* This version of `getopt' appears to the caller like standard Unix `getopt'
-   but it behaves differently for the user, since it allows the user
-   to intersperse the options with the other arguments.
+/* Unlike standard Unix `getopt', functions like `getopt_long'
+   let the user intersperse the options with the other arguments.
 
    As `getopt_long' works, it permutes the elements of ARGV so that,
    when it is done, all the options precede everything else.  Thus
@@ -55,7 +59,7 @@
 
    Using `getopt' or setting the environment variable POSIXLY_CORRECT
    disables permutation.
-   Then the behavior is completely standard.
+   Then the application's behavior is completely standard.
 
    GNU application programs can use a third alternative mode in which
    they can distinguish the relative order of options and other arguments.  */
@@ -122,18 +126,18 @@ extern char *__getopt_nonoption_flags;
 
 # ifdef USE_NONOPTION_FLAGS
 #  define SWAP_FLAGS(ch1, ch2) \
-  if (d->__nonoption_flags_len > 0)                                           \
-    {                                                                         \
-      char __tmp = __getopt_nonoption_flags[ch1];                             \
-      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];          \
-      __getopt_nonoption_flags[ch2] = __tmp;                                  \
+  if (d->__nonoption_flags_len > 0)                                          \
+    {                                                                        \
+      char __tmp = __getopt_nonoption_flags[ch1];                            \
+      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];         \
+      __getopt_nonoption_flags[ch2] = __tmp;                                 \
     }
 # else
 #  define SWAP_FLAGS(ch1, ch2)
 # endif
-#else   /* !_LIBC */
+#else  /* !_LIBC */
 # define SWAP_FLAGS(ch1, ch2)
-#endif  /* _LIBC */
+#endif /* _LIBC */
 
 /* Exchange two adjacent subsequences of ARGV.
    One subsequence is elements [first_nonopt,last_nonopt)
@@ -164,57 +168,57 @@ exchange (char **argv, struct _getopt_data *d)
   if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
     {
       /* We must extend the array.  The user plays games with us and
-         presents new arguments.  */
+        presents new arguments.  */
       char *new_str = malloc (top + 1);
       if (new_str == NULL)
-        d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
+       d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
       else
-        {
-          memset (__mempcpy (new_str, __getopt_nonoption_flags,
-                             d->__nonoption_flags_max_len),
-                  '\0', top + 1 - d->__nonoption_flags_max_len);
-          d->__nonoption_flags_max_len = top + 1;
-          __getopt_nonoption_flags = new_str;
-        }
+       {
+         memset (__mempcpy (new_str, __getopt_nonoption_flags,
+                            d->__nonoption_flags_max_len),
+                 '\0', top + 1 - d->__nonoption_flags_max_len);
+         d->__nonoption_flags_max_len = top + 1;
+         __getopt_nonoption_flags = new_str;
+       }
     }
 #endif
 
   while (top > middle && middle > bottom)
     {
       if (top - middle > middle - bottom)
-        {
-          /* Bottom segment is the short one.  */
-          int len = middle - bottom;
-          register int i;
-
-          /* Swap it with the top part of the top segment.  */
-          for (i = 0; i < len; i++)
-            {
-              tem = argv[bottom + i];
-              argv[bottom + i] = argv[top - (middle - bottom) + i];
-              argv[top - (middle - bottom) + i] = tem;
-              SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
-            }
-          /* Exclude the moved bottom segment from further swapping.  */
-          top -= len;
-        }
+       {
+         /* Bottom segment is the short one.  */
+         int len = middle - bottom;
+         register int i;
+
+         /* Swap it with the top part of the top segment.  */
+         for (i = 0; i < len; i++)
+           {
+             tem = argv[bottom + i];
+             argv[bottom + i] = argv[top - (middle - bottom) + i];
+             argv[top - (middle - bottom) + i] = tem;
+             SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
+           }
+         /* Exclude the moved bottom segment from further swapping.  */
+         top -= len;
+       }
       else
-        {
-          /* Top segment is the short one.  */
-          int len = top - middle;
-          register int i;
-
-          /* Swap it with the bottom part of the bottom segment.  */
-          for (i = 0; i < len; i++)
-            {
-              tem = argv[bottom + i];
-              argv[bottom + i] = argv[middle + i];
-              argv[middle + i] = tem;
-              SWAP_FLAGS (bottom + i, middle + i);
-            }
-          /* Exclude the moved top segment from further swapping.  */
-          bottom += len;
-        }
+       {
+         /* Top segment is the short one.  */
+         int len = top - middle;
+         register int i;
+
+         /* Swap it with the bottom part of the bottom segment.  */
+         for (i = 0; i < len; i++)
+           {
+             tem = argv[bottom + i];
+             argv[bottom + i] = argv[middle + i];
+             argv[middle + i] = tem;
+             SWAP_FLAGS (bottom + i, middle + i);
+           }
+         /* Exclude the moved top segment from further swapping.  */
+         bottom += len;
+       }
     }
 
   /* Update records for the slots the non-options now occupy.  */
@@ -226,9 +230,8 @@ exchange (char **argv, struct _getopt_data *d)
 /* Initialize the internal data when the first call is made.  */
 
 static const char *
-_getopt_initialize (int argc _GL_UNUSED,
-                    char **argv _GL_UNUSED, const char *optstring,
-                    struct _getopt_data *d, int posixly_correct)
+_getopt_initialize (int argc, char **argv, const char *optstring,
+                   int posixly_correct, struct _getopt_data *d)
 {
   /* Start processing options with ARGV-element 1 (since ARGV-element 0
      is the program name); the sequence of previously skipped
@@ -262,25 +265,25 @@ _getopt_initialize (int argc _GL_UNUSED,
       && argc == __libc_argc && argv == __libc_argv)
     {
       if (d->__nonoption_flags_max_len == 0)
-        {
-          if (__getopt_nonoption_flags == NULL
-              || __getopt_nonoption_flags[0] == '\0')
-            d->__nonoption_flags_max_len = -1;
-          else
-            {
-              const char *orig_str = __getopt_nonoption_flags;
-              int len = d->__nonoption_flags_max_len = strlen (orig_str);
-              if (d->__nonoption_flags_max_len < argc)
-                d->__nonoption_flags_max_len = argc;
-              __getopt_nonoption_flags =
-                (char *) malloc (d->__nonoption_flags_max_len);
-              if (__getopt_nonoption_flags == NULL)
-                d->__nonoption_flags_max_len = -1;
-              else
-                memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
-                        '\0', d->__nonoption_flags_max_len - len);
-            }
-        }
+       {
+         if (__getopt_nonoption_flags == NULL
+             || __getopt_nonoption_flags[0] == '\0')
+           d->__nonoption_flags_max_len = -1;
+         else
+           {
+             const char *orig_str = __getopt_nonoption_flags;
+             int len = d->__nonoption_flags_max_len = strlen (orig_str);
+             if (d->__nonoption_flags_max_len < argc)
+               d->__nonoption_flags_max_len = argc;
+             __getopt_nonoption_flags =
+               (char *) malloc (d->__nonoption_flags_max_len);
+             if (__getopt_nonoption_flags == NULL)
+               d->__nonoption_flags_max_len = -1;
+             else
+               memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
+                       '\0', d->__nonoption_flags_max_len - len);
+           }
+       }
       d->__nonoption_flags_len = d->__nonoption_flags_max_len;
     }
   else
@@ -332,10 +335,6 @@ _getopt_initialize (int argc _GL_UNUSED,
    `flag' field is nonzero, the value of the option's `val' field
    if the `flag' field is zero.
 
-   The elements of ARGV aren't really const, because we permute them.
-   But we pretend they're const in the prototype to be compatible
-   with other systems.
-
    LONGOPTS is a vector of `struct option' terminated by an
    element containing a name which is zero.
 
@@ -344,12 +343,15 @@ _getopt_initialize (int argc _GL_UNUSED,
    recent call.
 
    If LONG_ONLY is nonzero, '-' as well as '--' can introduce
-   long-named options.  */
+   long-named options.
+
+   If POSIXLY_CORRECT is nonzero, behave as if the POSIXLY_CORRECT
+   environment variable were set.  */
 
 int
 _getopt_internal_r (int argc, char **argv, const char *optstring,
-                    const struct option *longopts, int *longind,
-                    int long_only, struct _getopt_data *d, int posixly_correct)
+                   const struct option *longopts, int *longind,
+                   int long_only, int posixly_correct, struct _getopt_data *d)
 {
   int print_errors = d->opterr;
   if (optstring[0] == ':')
@@ -363,9 +365,9 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
   if (d->optind == 0 || !d->__initialized)
     {
       if (d->optind == 0)
-        d->optind = 1;  /* Don't scan ARGV[0], the program name.  */
-      optstring = _getopt_initialize (argc, argv, optstring, d,
-                                      posixly_correct);
+       d->optind = 1;  /* Don't scan ARGV[0], the program name.  */
+      optstring = _getopt_initialize (argc, argv, optstring,
+                                     posixly_correct, d);
       d->__initialized = 1;
     }
 
@@ -375,8 +377,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
      is only used when the used in the GNU libc.  */
 #if defined _LIBC && defined USE_NONOPTION_FLAGS
 # define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
-                      || (d->optind < d->__nonoption_flags_len                \
-                          && __getopt_nonoption_flags[d->optind] == '1'))
+                     || (d->optind < d->__nonoption_flags_len                \
+                         && __getopt_nonoption_flags[d->optind] == '1'))
 #else
 # define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
 #endif
@@ -386,78 +388,78 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
       /* Advance to the next ARGV-element.  */
 
       /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
-         moved back by the user (who may also have changed the arguments).  */
+        moved back by the user (who may also have changed the arguments).  */
       if (d->__last_nonopt > d->optind)
-        d->__last_nonopt = d->optind;
+       d->__last_nonopt = d->optind;
       if (d->__first_nonopt > d->optind)
-        d->__first_nonopt = d->optind;
+       d->__first_nonopt = d->optind;
 
       if (d->__ordering == PERMUTE)
-        {
-          /* If we have just processed some options following some non-options,
-             exchange them so that the options come first.  */
+       {
+         /* If we have just processed some options following some non-options,
+            exchange them so that the options come first.  */
 
-          if (d->__first_nonopt != d->__last_nonopt
-              && d->__last_nonopt != d->optind)
-            exchange ((char **) argv, d);
-          else if (d->__last_nonopt != d->optind)
-            d->__first_nonopt = d->optind;
+         if (d->__first_nonopt != d->__last_nonopt
+             && d->__last_nonopt != d->optind)
+           exchange ((char **) argv, d);
+         else if (d->__last_nonopt != d->optind)
+           d->__first_nonopt = d->optind;
 
-          /* Skip any additional non-options
-             and extend the range of non-options previously skipped.  */
+         /* Skip any additional non-options
+            and extend the range of non-options previously skipped.  */
 
-          while (d->optind < argc && NONOPTION_P)
-            d->optind++;
-          d->__last_nonopt = d->optind;
-        }
+         while (d->optind < argc && NONOPTION_P)
+           d->optind++;
+         d->__last_nonopt = d->optind;
+       }
 
       /* The special ARGV-element `--' means premature end of options.
-         Skip it like a null option,
-         then exchange with previous non-options as if it were an option,
-         then skip everything else like a non-option.  */
+        Skip it like a null option,
+        then exchange with previous non-options as if it were an option,
+        then skip everything else like a non-option.  */
 
       if (d->optind != argc && !strcmp (argv[d->optind], "--"))
-        {
-          d->optind++;
+       {
+         d->optind++;
 
-          if (d->__first_nonopt != d->__last_nonopt
-              && d->__last_nonopt != d->optind)
-            exchange ((char **) argv, d);
-          else if (d->__first_nonopt == d->__last_nonopt)
-            d->__first_nonopt = d->optind;
-          d->__last_nonopt = argc;
+         if (d->__first_nonopt != d->__last_nonopt
+             && d->__last_nonopt != d->optind)
+           exchange ((char **) argv, d);
+         else if (d->__first_nonopt == d->__last_nonopt)
+           d->__first_nonopt = d->optind;
+         d->__last_nonopt = argc;
 
-          d->optind = argc;
-        }
+         d->optind = argc;
+       }
 
       /* If we have done all the ARGV-elements, stop the scan
-         and back over any non-options that we skipped and permuted.  */
+        and back over any non-options that we skipped and permuted.  */
 
       if (d->optind == argc)
-        {
-          /* Set the next-arg-index to point at the non-options
-             that we previously skipped, so the caller will digest them.  */
-          if (d->__first_nonopt != d->__last_nonopt)
-            d->optind = d->__first_nonopt;
-          return -1;
-        }
+       {
+         /* Set the next-arg-index to point at the non-options
+            that we previously skipped, so the caller will digest them.  */
+         if (d->__first_nonopt != d->__last_nonopt)
+           d->optind = d->__first_nonopt;
+         return -1;
+       }
 
       /* If we have come to a non-option and did not permute it,
-         either stop the scan or describe it to the caller and pass it by.  */
+        either stop the scan or describe it to the caller and pass it by.  */
 
       if (NONOPTION_P)
-        {
-          if (d->__ordering == REQUIRE_ORDER)
-            return -1;
-          d->optarg = argv[d->optind++];
-          return 1;
-        }
+       {
+         if (d->__ordering == REQUIRE_ORDER)
+           return -1;
+         d->optarg = argv[d->optind++];
+         return 1;
+       }
 
       /* We have found another option-ARGV-element.
-         Skip the initial punctuation.  */
+        Skip the initial punctuation.  */
 
       d->__nextchar = (argv[d->optind] + 1
-                  + (longopts != NULL && argv[d->optind][1] == '-'));
+                 + (longopts != NULL && argv[d->optind][1] == '-'));
     }
 
   /* Decode the current option-ARGV-element.  */
@@ -477,8 +479,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
 
   if (longopts != NULL
       && (argv[d->optind][1] == '-'
-          || (long_only && (argv[d->optind][2]
-                            || !strchr (optstring, argv[d->optind][1])))))
+         || (long_only && (argv[d->optind][2]
+                           || !strchr (optstring, argv[d->optind][1])))))
     {
       char *nameend;
       const struct option *p;
@@ -489,251 +491,251 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
       int option_index;
 
       for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
-        /* Do nothing.  */ ;
+       /* Do nothing.  */ ;
 
       /* Test all long options for either exact match
-         or abbreviated matches.  */
+        or abbreviated matches.  */
       for (p = longopts, option_index = 0; p->name; p++, option_index++)
-        if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
-          {
-            if ((unsigned int) (nameend - d->__nextchar)
-                == (unsigned int) strlen (p->name))
-              {
-                /* Exact match found.  */
-                pfound = p;
-                indfound = option_index;
-                exact = 1;
-                break;
-              }
-            else if (pfound == NULL)
-              {
-                /* First nonexact match found.  */
-                pfound = p;
-                indfound = option_index;
-              }
-            else if (long_only
-                     || pfound->has_arg != p->has_arg
-                     || pfound->flag != p->flag
-                     || pfound->val != p->val)
-              /* Second or later nonexact match found.  */
-              ambig = 1;
-          }
+       if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
+         {
+           if ((unsigned int) (nameend - d->__nextchar)
+               == (unsigned int) strlen (p->name))
+             {
+               /* Exact match found.  */
+               pfound = p;
+               indfound = option_index;
+               exact = 1;
+               break;
+             }
+           else if (pfound == NULL)
+             {
+               /* First nonexact match found.  */
+               pfound = p;
+               indfound = option_index;
+             }
+           else if (long_only
+                    || pfound->has_arg != p->has_arg
+                    || pfound->flag != p->flag
+                    || pfound->val != p->val)
+             /* Second or later nonexact match found.  */
+             ambig = 1;
+         }
 
       if (ambig && !exact)
-        {
-          if (print_errors)
-            {
+       {
+         if (print_errors)
+           {
 #if defined _LIBC && defined USE_IN_LIBIO
-              char *buf;
+             char *buf;
 
-              if (__asprintf (&buf, _("%s: option '%s' is ambiguous\n"),
-                              argv[0], argv[d->optind]) >= 0)
-                {
-                  _IO_flockfile (stderr);
+             if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
+                             argv[0], argv[d->optind]) >= 0)
+               {
+                 _IO_flockfile (stderr);
 
-                  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+                 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                  __fxprintf (NULL, "%s", buf);
+                 __fxprintf (NULL, "%s", buf);
 
-                  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                  _IO_funlockfile (stderr);
+                 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                 _IO_funlockfile (stderr);
 
-                  free (buf);
-                }
+                 free (buf);
+               }
 #else
-              fprintf (stderr, _("%s: option '%s' is ambiguous\n"),
-                       argv[0], argv[d->optind]);
+             fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
+                      argv[0], argv[d->optind]);
 #endif
-            }
-          d->__nextchar += strlen (d->__nextchar);
-          d->optind++;
-          d->optopt = 0;
-          return '?';
-        }
+           }
+         d->__nextchar += strlen (d->__nextchar);
+         d->optind++;
+         d->optopt = 0;
+         return '?';
+       }
 
       if (pfound != NULL)
-        {
-          option_index = indfound;
-          d->optind++;
-          if (*nameend)
-            {
-              /* Don't test has_arg with >, because some C compilers don't
-                 allow it to be used on enums.  */
-              if (pfound->has_arg)
-                d->optarg = nameend + 1;
-              else
-                {
-                  if (print_errors)
-                    {
+       {
+         option_index = indfound;
+         d->optind++;
+         if (*nameend)
+           {
+             /* Don't test has_arg with >, because some C compilers don't
+                allow it to be used on enums.  */
+             if (pfound->has_arg)
+               d->optarg = nameend + 1;
+             else
+               {
+                 if (print_errors)
+                   {
 #if defined _LIBC && defined USE_IN_LIBIO
-                      char *buf;
-                      int n;
+                     char *buf;
+                     int n;
 #endif
 
-                      if (argv[d->optind - 1][1] == '-')
-                        {
-                          /* --option */
+                     if (argv[d->optind - 1][1] == '-')
+                       {
+                         /* --option */
 #if defined _LIBC && defined USE_IN_LIBIO
-                          n = __asprintf (&buf, _("\
-%s: option '--%s' doesn't allow an argument\n"),
-                                          argv[0], pfound->name);
+                         n = __asprintf (&buf, _("\
+%s: option `--%s' doesn't allow an argument\n"),
+                                         argv[0], pfound->name);
 #else
-                          fprintf (stderr, _("\
-%s: option '--%s' doesn't allow an argument\n"),
-                                   argv[0], pfound->name);
+                         fprintf (stderr, _("\
+%s: option `--%s' doesn't allow an argument\n"),
+                                  argv[0], pfound->name);
 #endif
-                        }
-                      else
-                        {
-                          /* +option or -option */
+                       }
+                     else
+                       {
+                         /* +option or -option */
 #if defined _LIBC && defined USE_IN_LIBIO
-                          n = __asprintf (&buf, _("\
-%s: option '%c%s' doesn't allow an argument\n"),
-                                          argv[0], argv[d->optind - 1][0],
-                                          pfound->name);
+                         n = __asprintf (&buf, _("\
+%s: option `%c%s' doesn't allow an argument\n"),
+                                         argv[0], argv[d->optind - 1][0],
+                                         pfound->name);
 #else
-                          fprintf (stderr, _("\
-%s: option '%c%s' doesn't allow an argument\n"),
-                                   argv[0], argv[d->optind - 1][0],
-                                   pfound->name);
+                         fprintf (stderr, _("\
+%s: option `%c%s' doesn't allow an argument\n"),
+                                  argv[0], argv[d->optind - 1][0],
+                                  pfound->name);
 #endif
-                        }
+                       }
 
 #if defined _LIBC && defined USE_IN_LIBIO
-                      if (n >= 0)
-                        {
-                          _IO_flockfile (stderr);
+                     if (n >= 0)
+                       {
+                         _IO_flockfile (stderr);
 
-                          int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                          ((_IO_FILE *) stderr)->_flags2
-                            |= _IO_FLAGS2_NOTCANCEL;
+                         int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                         ((_IO_FILE *) stderr)->_flags2
+                           |= _IO_FLAGS2_NOTCANCEL;
 
-                          __fxprintf (NULL, "%s", buf);
+                         __fxprintf (NULL, "%s", buf);
 
-                          ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                          _IO_funlockfile (stderr);
+                         ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                         _IO_funlockfile (stderr);
 
-                          free (buf);
-                        }
+                         free (buf);
+                       }
 #endif
-                    }
-
-                  d->__nextchar += strlen (d->__nextchar);
-
-                  d->optopt = pfound->val;
-                  return '?';
-                }
-            }
-          else if (pfound->has_arg == 1)
-            {
-              if (d->optind < argc)
-                d->optarg = argv[d->optind++];
-              else
-                {
-                  if (print_errors)
-                    {
+                   }
+
+                 d->__nextchar += strlen (d->__nextchar);
+
+                 d->optopt = pfound->val;
+                 return '?';
+               }
+           }
+         else if (pfound->has_arg == 1)
+           {
+             if (d->optind < argc)
+               d->optarg = argv[d->optind++];
+             else
+               {
+                 if (print_errors)
+                   {
 #if defined _LIBC && defined USE_IN_LIBIO
-                      char *buf;
+                     char *buf;
 
-                      if (__asprintf (&buf, _("\
-%s: option '%s' requires an argument\n"),
-                                      argv[0], argv[d->optind - 1]) >= 0)
-                        {
-                          _IO_flockfile (stderr);
+                     if (__asprintf (&buf, _("\
+%s: option `%s' requires an argument\n"),
+                                     argv[0], argv[d->optind - 1]) >= 0)
+                       {
+                         _IO_flockfile (stderr);
 
-                          int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                          ((_IO_FILE *) stderr)->_flags2
-                            |= _IO_FLAGS2_NOTCANCEL;
+                         int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                         ((_IO_FILE *) stderr)->_flags2
+                           |= _IO_FLAGS2_NOTCANCEL;
 
-                          __fxprintf (NULL, "%s", buf);
+                         __fxprintf (NULL, "%s", buf);
 
-                          ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                          _IO_funlockfile (stderr);
+                         ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                         _IO_funlockfile (stderr);
 
-                          free (buf);
-                        }
+                         free (buf);
+                       }
 #else
-                      fprintf (stderr,
-                               _("%s: option '%s' requires an argument\n"),
-                               argv[0], argv[d->optind - 1]);
+                     fprintf (stderr,
+                              _("%s: option `%s' requires an argument\n"),
+                              argv[0], argv[d->optind - 1]);
 #endif
-                    }
-                  d->__nextchar += strlen (d->__nextchar);
-                  d->optopt = pfound->val;
-                  return optstring[0] == ':' ? ':' : '?';
-                }
-            }
-          d->__nextchar += strlen (d->__nextchar);
-          if (longind != NULL)
-            *longind = option_index;
-          if (pfound->flag)
-            {
-              *(pfound->flag) = pfound->val;
-              return 0;
-            }
-          return pfound->val;
-        }
+                   }
+                 d->__nextchar += strlen (d->__nextchar);
+                 d->optopt = pfound->val;
+                 return optstring[0] == ':' ? ':' : '?';
+               }
+           }
+         d->__nextchar += strlen (d->__nextchar);
+         if (longind != NULL)
+           *longind = option_index;
+         if (pfound->flag)
+           {
+             *(pfound->flag) = pfound->val;
+             return 0;
+           }
+         return pfound->val;
+       }
 
       /* Can't find it as a long option.  If this is not getopt_long_only,
-         or the option starts with '--' or is not a valid short
-         option, then it's an error.
-         Otherwise interpret it as a short option.  */
+        or the option starts with '--' or is not a valid short
+        option, then it's an error.
+        Otherwise interpret it as a short option.  */
       if (!long_only || argv[d->optind][1] == '-'
-          || strchr (optstring, *d->__nextchar) == NULL)
-        {
-          if (print_errors)
-            {
+         || strchr (optstring, *d->__nextchar) == NULL)
+       {
+         if (print_errors)
+           {
 #if defined _LIBC && defined USE_IN_LIBIO
-              char *buf;
-              int n;
+             char *buf;
+             int n;
 #endif
 
-              if (argv[d->optind][1] == '-')
-                {
-                  /* --option */
+             if (argv[d->optind][1] == '-')
+               {
+                 /* --option */
 #if defined _LIBC && defined USE_IN_LIBIO
-                  n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
-                                  argv[0], d->__nextchar);
+                 n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
+                                 argv[0], d->__nextchar);
 #else
-                  fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
-                           argv[0], d->__nextchar);
+                 fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
+                          argv[0], d->__nextchar);
 #endif
-                }
-              else
-                {
-                  /* +option or -option */
+               }
+             else
+               {
+                 /* +option or -option */
 #if defined _LIBC && defined USE_IN_LIBIO
-                  n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
-                                  argv[0], argv[d->optind][0], d->__nextchar);
+                 n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
+                                 argv[0], argv[d->optind][0], d->__nextchar);
 #else
-                  fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
-                           argv[0], argv[d->optind][0], d->__nextchar);
+                 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
+                          argv[0], argv[d->optind][0], d->__nextchar);
 #endif
-                }
+               }
 
 #if defined _LIBC && defined USE_IN_LIBIO
-              if (n >= 0)
-                {
-                  _IO_flockfile (stderr);
+             if (n >= 0)
+               {
+                 _IO_flockfile (stderr);
 
-                  int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                  ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+                 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                  __fxprintf (NULL, "%s", buf);
+                 __fxprintf (NULL, "%s", buf);
 
-                  ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                  _IO_funlockfile (stderr);
+                 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                 _IO_funlockfile (stderr);
 
-                  free (buf);
-                }
+                 free (buf);
+               }
 #endif
-            }
-          d->__nextchar = (char *) "";
-          d->optind++;
-          d->optopt = 0;
-          return '?';
-        }
+           }
+         d->__nextchar = (char *) "";
+         d->optind++;
+         d->optopt = 0;
+         return '?';
+       }
     }
 
   /* Look at and handle the next short option-character.  */
@@ -748,321 +750,335 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
 
     if (temp == NULL || c == ':')
       {
-        if (print_errors)
-          {
+       if (print_errors)
+         {
 #if defined _LIBC && defined USE_IN_LIBIO
-              char *buf;
-              int n;
+             char *buf;
+             int n;
 #endif
 
+           if (d->__posixly_correct)
+             {
+               /* 1003.2 specifies the format of this message.  */
+#if defined _LIBC && defined USE_IN_LIBIO
+               n = __asprintf (&buf, _("%s: illegal option -- %c\n"),
+                               argv[0], c);
+#else
+               fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
+#endif
+             }
+           else
+             {
 #if defined _LIBC && defined USE_IN_LIBIO
-              n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
-                              argv[0], c);
+               n = __asprintf (&buf, _("%s: invalid option -- %c\n"),
+                               argv[0], c);
 #else
-              fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
+               fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
 #endif
+             }
 
 #if defined _LIBC && defined USE_IN_LIBIO
-            if (n >= 0)
-              {
-                _IO_flockfile (stderr);
+           if (n >= 0)
+             {
+               _IO_flockfile (stderr);
 
-                int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+               int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+               ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                __fxprintf (NULL, "%s", buf);
+               __fxprintf (NULL, "%s", buf);
 
-                ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                _IO_funlockfile (stderr);
+               ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+               _IO_funlockfile (stderr);
 
-                free (buf);
-              }
+               free (buf);
+             }
 #endif
-          }
-        d->optopt = c;
-        return '?';
+         }
+       d->optopt = c;
+       return '?';
       }
     /* Convenience. Treat POSIX -W foo same as long option --foo */
     if (temp[0] == 'W' && temp[1] == ';')
       {
-        char *nameend;
-        const struct option *p;
-        const struct option *pfound = NULL;
-        int exact = 0;
-        int ambig = 0;
-        int indfound = 0;
-        int option_index;
-
-        /* This is an option that requires an argument.  */
-        if (*d->__nextchar != '\0')
-          {
-            d->optarg = d->__nextchar;
-            /* If we end this ARGV-element by taking the rest as an arg,
-               we must advance to the next element now.  */
-            d->optind++;
-          }
-        else if (d->optind == argc)
-          {
-            if (print_errors)
-              {
+       char *nameend;
+       const struct option *p;
+       const struct option *pfound = NULL;
+       int exact = 0;
+       int ambig = 0;
+       int indfound = 0;
+       int option_index;
+
+       /* This is an option that requires an argument.  */
+       if (*d->__nextchar != '\0')
+         {
+           d->optarg = d->__nextchar;
+           /* If we end this ARGV-element by taking the rest as an arg,
+              we must advance to the next element now.  */
+           d->optind++;
+         }
+       else if (d->optind == argc)
+         {
+           if (print_errors)
+             {
+               /* 1003.2 specifies the format of this message.  */
 #if defined _LIBC && defined USE_IN_LIBIO
-                char *buf;
+               char *buf;
 
-                if (__asprintf (&buf,
-                                _("%s: option requires an argument -- '%c'\n"),
-                                argv[0], c) >= 0)
-                  {
-                    _IO_flockfile (stderr);
+               if (__asprintf (&buf,
+                               _("%s: option requires an argument -- %c\n"),
+                               argv[0], c) >= 0)
+                 {
+                   _IO_flockfile (stderr);
 
-                    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+                   int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                   ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                    __fxprintf (NULL, "%s", buf);
+                   __fxprintf (NULL, "%s", buf);
 
-                    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                    _IO_funlockfile (stderr);
+                   ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                   _IO_funlockfile (stderr);
 
-                    free (buf);
-                  }
+                   free (buf);
+                 }
 #else
-                fprintf (stderr,
-                         _("%s: option requires an argument -- '%c'\n"),
-                         argv[0], c);
+               fprintf (stderr, _("%s: option requires an argument -- %c\n"),
+                        argv[0], c);
 #endif
-              }
-            d->optopt = c;
-            if (optstring[0] == ':')
-              c = ':';
-            else
-              c = '?';
-            return c;
-          }
-        else
-          /* We already incremented `d->optind' once;
-             increment it again when taking next ARGV-elt as argument.  */
-          d->optarg = argv[d->optind++];
-
-        /* optarg is now the argument, see if it's in the
-           table of longopts.  */
-
-        for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
-             nameend++)
-          /* Do nothing.  */ ;
-
-        /* Test all long options for either exact match
-           or abbreviated matches.  */
-        for (p = longopts, option_index = 0; p->name; p++, option_index++)
-          if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
-            {
-              if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
-                {
-                  /* Exact match found.  */
-                  pfound = p;
-                  indfound = option_index;
-                  exact = 1;
-                  break;
-                }
-              else if (pfound == NULL)
-                {
-                  /* First nonexact match found.  */
-                  pfound = p;
-                  indfound = option_index;
-                }
-              else
-                /* Second or later nonexact match found.  */
-                ambig = 1;
-            }
-        if (ambig && !exact)
-          {
-            if (print_errors)
-              {
+             }
+           d->optopt = c;
+           if (optstring[0] == ':')
+             c = ':';
+           else
+             c = '?';
+           return c;
+         }
+       else
+         /* We already incremented `d->optind' once;
+            increment it again when taking next ARGV-elt as argument.  */
+         d->optarg = argv[d->optind++];
+
+       /* optarg is now the argument, see if it's in the
+          table of longopts.  */
+
+       for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
+            nameend++)
+         /* Do nothing.  */ ;
+
+       /* Test all long options for either exact match
+          or abbreviated matches.  */
+       for (p = longopts, option_index = 0; p->name; p++, option_index++)
+         if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
+           {
+             if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
+               {
+                 /* Exact match found.  */
+                 pfound = p;
+                 indfound = option_index;
+                 exact = 1;
+                 break;
+               }
+             else if (pfound == NULL)
+               {
+                 /* First nonexact match found.  */
+                 pfound = p;
+                 indfound = option_index;
+               }
+             else
+               /* Second or later nonexact match found.  */
+               ambig = 1;
+           }
+       if (ambig && !exact)
+         {
+           if (print_errors)
+             {
 #if defined _LIBC && defined USE_IN_LIBIO
-                char *buf;
+               char *buf;
 
-                if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
-                                argv[0], argv[d->optind]) >= 0)
-                  {
-                    _IO_flockfile (stderr);
+               if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
+                               argv[0], argv[d->optind]) >= 0)
+                 {
+                   _IO_flockfile (stderr);
 
-                    int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                    ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+                   int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                   ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                    __fxprintf (NULL, "%s", buf);
+                   __fxprintf (NULL, "%s", buf);
 
-                    ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                    _IO_funlockfile (stderr);
+                   ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                   _IO_funlockfile (stderr);
 
-                    free (buf);
-                  }
+                   free (buf);
+                 }
 #else
-                fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
-                         argv[0], argv[d->optind]);
+               fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
+                        argv[0], argv[d->optind]);
 #endif
-              }
-            d->__nextchar += strlen (d->__nextchar);
-            d->optind++;
-            return '?';
-          }
-        if (pfound != NULL)
-          {
-            option_index = indfound;
-            if (*nameend)
-              {
-                /* Don't test has_arg with >, because some C compilers don't
-                   allow it to be used on enums.  */
-                if (pfound->has_arg)
-                  d->optarg = nameend + 1;
-                else
-                  {
-                    if (print_errors)
-                      {
+             }
+           d->__nextchar += strlen (d->__nextchar);
+           d->optind++;
+           return '?';
+         }
+       if (pfound != NULL)
+         {
+           option_index = indfound;
+           if (*nameend)
+             {
+               /* Don't test has_arg with >, because some C compilers don't
+                  allow it to be used on enums.  */
+               if (pfound->has_arg)
+                 d->optarg = nameend + 1;
+               else
+                 {
+                   if (print_errors)
+                     {
 #if defined _LIBC && defined USE_IN_LIBIO
-                        char *buf;
+                       char *buf;
 
-                        if (__asprintf (&buf, _("\
-%s: option '-W %s' doesn't allow an argument\n"),
-                                        argv[0], pfound->name) >= 0)
-                          {
-                            _IO_flockfile (stderr);
+                       if (__asprintf (&buf, _("\
+%s: option `-W %s' doesn't allow an argument\n"),
+                                       argv[0], pfound->name) >= 0)
+                         {
+                           _IO_flockfile (stderr);
 
-                            int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                            ((_IO_FILE *) stderr)->_flags2
-                              |= _IO_FLAGS2_NOTCANCEL;
+                           int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                           ((_IO_FILE *) stderr)->_flags2
+                             |= _IO_FLAGS2_NOTCANCEL;
 
-                            __fxprintf (NULL, "%s", buf);
+                           __fxprintf (NULL, "%s", buf);
 
-                            ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                            _IO_funlockfile (stderr);
+                           ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                           _IO_funlockfile (stderr);
 
-                            free (buf);
-                          }
+                           free (buf);
+                         }
 #else
-                        fprintf (stderr, _("\
-%s: option '-W %s' doesn't allow an argument\n"),
-                                 argv[0], pfound->name);
+                       fprintf (stderr, _("\
+%s: option `-W %s' doesn't allow an argument\n"),
+                                argv[0], pfound->name);
 #endif
-                      }
-
-                    d->__nextchar += strlen (d->__nextchar);
-                    return '?';
-                  }
-              }
-            else if (pfound->has_arg == 1)
-              {
-                if (d->optind < argc)
-                  d->optarg = argv[d->optind++];
-                else
-                  {
-                    if (print_errors)
-                      {
+                     }
+
+                   d->__nextchar += strlen (d->__nextchar);
+                   return '?';
+                 }
+             }
+           else if (pfound->has_arg == 1)
+             {
+               if (d->optind < argc)
+                 d->optarg = argv[d->optind++];
+               else
+                 {
+                   if (print_errors)
+                     {
 #if defined _LIBC && defined USE_IN_LIBIO
-                        char *buf;
+                       char *buf;
 
-                        if (__asprintf (&buf, _("\
-%s: option '%s' requires an argument\n"),
-                                        argv[0], argv[d->optind - 1]) >= 0)
-                          {
-                            _IO_flockfile (stderr);
+                       if (__asprintf (&buf, _("\
+%s: option `%s' requires an argument\n"),
+                                       argv[0], argv[d->optind - 1]) >= 0)
+                         {
+                           _IO_flockfile (stderr);
 
-                            int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                            ((_IO_FILE *) stderr)->_flags2
-                              |= _IO_FLAGS2_NOTCANCEL;
+                           int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                           ((_IO_FILE *) stderr)->_flags2
+                             |= _IO_FLAGS2_NOTCANCEL;
 
-                            __fxprintf (NULL, "%s", buf);
+                           __fxprintf (NULL, "%s", buf);
 
-                            ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                            _IO_funlockfile (stderr);
+                           ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                           _IO_funlockfile (stderr);
 
-                            free (buf);
-                          }
+                           free (buf);
+                         }
 #else
-                        fprintf (stderr,
-                                 _("%s: option '%s' requires an argument\n"),
-                                 argv[0], argv[d->optind - 1]);
+                       fprintf (stderr,
+                                _("%s: option `%s' requires an argument\n"),
+                                argv[0], argv[d->optind - 1]);
 #endif
-                      }
-                    d->__nextchar += strlen (d->__nextchar);
-                    return optstring[0] == ':' ? ':' : '?';
-                  }
-              }
-            d->__nextchar += strlen (d->__nextchar);
-            if (longind != NULL)
-              *longind = option_index;
-            if (pfound->flag)
-              {
-                *(pfound->flag) = pfound->val;
-                return 0;
-              }
-            return pfound->val;
-          }
-          d->__nextchar = NULL;
-          return 'W';   /* Let the application handle it.   */
+                     }
+                   d->__nextchar += strlen (d->__nextchar);
+                   return optstring[0] == ':' ? ':' : '?';
+                 }
+             }
+           d->__nextchar += strlen (d->__nextchar);
+           if (longind != NULL)
+             *longind = option_index;
+           if (pfound->flag)
+             {
+               *(pfound->flag) = pfound->val;
+               return 0;
+             }
+           return pfound->val;
+         }
+         d->__nextchar = NULL;
+         return 'W';   /* Let the application handle it.   */
       }
     if (temp[1] == ':')
       {
-        if (temp[2] == ':')
-          {
-            /* This is an option that accepts an argument optionally.  */
-            if (*d->__nextchar != '\0')
-              {
-                d->optarg = d->__nextchar;
-                d->optind++;
-              }
-            else
-              d->optarg = NULL;
-            d->__nextchar = NULL;
-          }
-        else
-          {
-            /* This is an option that requires an argument.  */
-            if (*d->__nextchar != '\0')
-              {
-                d->optarg = d->__nextchar;
-                /* If we end this ARGV-element by taking the rest as an arg,
-                   we must advance to the next element now.  */
-                d->optind++;
-              }
-            else if (d->optind == argc)
-              {
-                if (print_errors)
-                  {
+       if (temp[2] == ':')
+         {
+           /* This is an option that accepts an argument optionally.  */
+           if (*d->__nextchar != '\0')
+             {
+               d->optarg = d->__nextchar;
+               d->optind++;
+             }
+           else
+             d->optarg = NULL;
+           d->__nextchar = NULL;
+         }
+       else
+         {
+           /* This is an option that requires an argument.  */
+           if (*d->__nextchar != '\0')
+             {
+               d->optarg = d->__nextchar;
+               /* If we end this ARGV-element by taking the rest as an arg,
+                  we must advance to the next element now.  */
+               d->optind++;
+             }
+           else if (d->optind == argc)
+             {
+               if (print_errors)
+                 {
+                   /* 1003.2 specifies the format of this message.  */
 #if defined _LIBC && defined USE_IN_LIBIO
-                    char *buf;
+                   char *buf;
 
-                    if (__asprintf (&buf, _("\
-%s: option requires an argument -- '%c'\n"),
-                                    argv[0], c) >= 0)
-                      {
-                        _IO_flockfile (stderr);
+                   if (__asprintf (&buf, _("\
+%s: option requires an argument -- %c\n"),
+                                   argv[0], c) >= 0)
+                     {
+                       _IO_flockfile (stderr);
 
-                        int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
-                        ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+                       int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+                       ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
 
-                        __fxprintf (NULL, "%s", buf);
+                       __fxprintf (NULL, "%s", buf);
 
-                        ((_IO_FILE *) stderr)->_flags2 = old_flags2;
-                        _IO_funlockfile (stderr);
+                       ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+                       _IO_funlockfile (stderr);
 
-                        free (buf);
-                      }
+                       free (buf);
+                     }
 #else
-                    fprintf (stderr,
-                             _("%s: option requires an argument -- '%c'\n"),
-                             argv[0], c);
+                   fprintf (stderr,
+                            _("%s: option requires an argument -- %c\n"),
+                            argv[0], c);
 #endif
-                  }
-                d->optopt = c;
-                if (optstring[0] == ':')
-                  c = ':';
-                else
-                  c = '?';
-              }
-            else
-              /* We already incremented `optind' once;
-                 increment it again when taking next ARGV-elt as argument.  */
-              d->optarg = argv[d->optind++];
-            d->__nextchar = NULL;
-          }
+                 }
+               d->optopt = c;
+               if (optstring[0] == ':')
+                 c = ':';
+               else
+                 c = '?';
+             }
+           else
+             /* We already incremented `optind' once;
+                increment it again when taking next ARGV-elt as argument.  */
+             d->optarg = argv[d->optind++];
+           d->__nextchar = NULL;
+         }
       }
     return c;
   }
@@ -1070,17 +1086,16 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
 
 int
 _getopt_internal (int argc, char **argv, const char *optstring,
-                  const struct option *longopts, int *longind, int long_only,
-                  int posixly_correct)
+                 const struct option *longopts, int *longind,
+                 int long_only, int posixly_correct)
 {
   int result;
 
   getopt_data.optind = optind;
   getopt_data.opterr = opterr;
 
-  result = _getopt_internal_r (argc, argv, optstring, longopts,
-                               longind, long_only, &getopt_data,
-                               posixly_correct);
+  result = _getopt_internal_r (argc, argv, optstring, longopts, longind,
+                              long_only, posixly_correct, &getopt_data);
 
   optind = getopt_data.optind;
   optarg = getopt_data.optarg;
@@ -1100,23 +1115,10 @@ enum { POSIXLY_CORRECT = 1 };
 int
 getopt (int argc, char *const *argv, const char *optstring)
 {
-  return _getopt_internal (argc, (char **) argv, optstring,
-                           (const struct option *) 0,
-                           (int *) 0,
-                           0, POSIXLY_CORRECT);
+  return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0,
+                          POSIXLY_CORRECT);
 }
 
-#ifdef _LIBC
-int
-__posix_getopt (int argc, char *const *argv, const char *optstring)
-{
-  return _getopt_internal (argc, argv, optstring,
-                           (const struct option *) 0,
-                           (int *) 0,
-                           0, 1);
-}
-#endif
-
 \f
 #ifdef TEST
 
@@ -1135,51 +1137,51 @@ main (int argc, char **argv)
 
       c = getopt (argc, argv, "abc:d:0123456789");
       if (c == -1)
-        break;
+       break;
 
       switch (c)
-        {
-        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 '?':
-          break;
-
-        default:
-          printf ("?? getopt returned character code 0%o ??\n", c);
-        }
+       {
+       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 '?':
+         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 ("%s ", argv[optind++]);
       printf ("\n");
     }
 
index 046d69f940f619bab7c922ba7d9e1f2e6d8c7c47..cc0746ea43cecc504f6313f6683eee4ff30bcd20 100644 (file)
@@ -1,20 +1,21 @@
 /* getopt_long and getopt_long_only entry points for GNU getopt.
-   Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
-   1998, 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
+   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
+   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.
+   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, see <http://www.gnu.org/licenses/>.  */
+   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.  */
 \f
 #ifdef _LIBC
 # include <getopt.h>
 #include <stdlib.h>
 #endif
 
-#ifndef NULL
+#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)
+            const struct option *long_options, int *opt_index)
 {
   return _getopt_internal (argc, (char **) argv, options, long_options,
-                           opt_index, 0, 0);
+                          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)
+               const struct option *long_options, int *opt_index,
+               struct _getopt_data *d)
 {
   return _getopt_internal_r (argc, argv, options, long_options, opt_index,
-                             0, d, 0);
+                            0, 0, d);
 }
 
 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
@@ -60,20 +61,20 @@ _getopt_long_r (int argc, char **argv, const char *options,
 
 int
 getopt_long_only (int argc, char *__getopt_argv_const *argv,
-                  const char *options,
-                  const struct option *long_options, int *opt_index)
+                 const char *options,
+                 const struct option *long_options, int *opt_index)
 {
   return _getopt_internal (argc, (char **) argv, options, long_options,
-                           opt_index, 1, 0);
+                          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)
+                    const struct option *long_options, int *opt_index,
+                    struct _getopt_data *d)
 {
   return _getopt_internal_r (argc, argv, options, long_options, opt_index,
-                             1, d, 0);
+                            1, 0, d);
 }
 
 \f
@@ -91,76 +92,76 @@ main (int argc, char **argv)
     {
       int this_option_optind = optind ? optind : 1;
       int option_index = 0;
-      static const struct option long_options[] =
+      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}
+       {"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);
+                      long_options, &option_index);
       if (c == -1)
-        break;
+       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);
-        }
+       {
+       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 ("%s ", argv[optind++]);
       printf ("\n");
     }
 
diff --git a/lib/getopt_.h b/lib/getopt_.h
new file mode 100644 (file)
index 0000000..615ef9a
--- /dev/null
@@ -0,0 +1,226 @@
+/* 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 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 _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 */
diff --git a/lib/stat_.h b/lib/stat_.h
new file mode 100644 (file)
index 0000000..de3add5
--- /dev/null
@@ -0,0 +1,275 @@
+/* Provide a more complete sys/stat header file.
+   Copyright (C) 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 Eric Blake, Paul Eggert, and Jim Meyering.  */
+
+#ifndef _GL_SYS_STAT_H
+#define _GL_SYS_STAT_H
+
+/* This file is supposed to be used on platforms where <sys/stat.h> is
+   incomplete.  It is intended to provide definitions and prototypes
+   needed by an application.  Start with what the system provides.  */
+#include @ABSOLUTE_SYS_STAT_H@
+
+#ifndef S_IFMT
+# define S_IFMT 0170000
+#endif
+
+#if STAT_MACROS_BROKEN
+# undef S_ISBLK
+# undef S_ISCHR
+# undef S_ISDIR
+# undef S_ISFIFO
+# undef S_ISLNK
+# undef S_ISNAM
+# undef S_ISMPB
+# undef S_ISMPC
+# undef S_ISNWK
+# undef S_ISREG
+# undef S_ISSOCK
+#endif
+
+#ifndef S_ISBLK
+# ifdef S_IFBLK
+#  define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+# else
+#  define S_ISBLK(m) 0
+# endif
+#endif
+
+#ifndef S_ISCHR
+# ifdef S_IFCHR
+#  define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+# else
+#  define S_ISCHR(m) 0
+# endif
+#endif
+
+#ifndef S_ISDIR
+# ifdef S_IFDIR
+#  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+# else
+#  define S_ISDIR(m) 0
+# endif
+#endif
+
+#ifndef S_ISDOOR /* Solaris 2.5 and up */
+# define S_ISDOOR(m) 0
+#endif
+
+#ifndef S_ISFIFO
+# ifdef S_IFIFO
+#  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+# else
+#  define S_ISFIFO(m) 0
+# endif
+#endif
+
+#ifndef S_ISLNK
+# ifdef S_IFLNK
+#  define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+# else
+#  define S_ISLNK(m) 0
+# endif
+#endif
+
+#ifndef S_ISMPB /* V7 */
+# ifdef S_IFMPB
+#  define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
+#  define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
+# else
+#  define S_ISMPB(m) 0
+#  define S_ISMPC(m) 0
+# endif
+#endif
+
+#ifndef S_ISNAM /* Xenix */
+# ifdef S_IFNAM
+#  define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
+# else
+#  define S_ISNAM(m) 0
+# endif
+#endif
+
+#ifndef S_ISNWK /* HP/UX */
+# ifdef S_IFNWK
+#  define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
+# else
+#  define S_ISNWK(m) 0
+# endif
+#endif
+
+#ifndef S_ISPORT /* Solaris 10 and up */
+# define S_ISPORT(m) 0
+#endif
+
+#ifndef S_ISREG
+# ifdef S_IFREG
+#  define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+# else
+#  define S_ISREG(m) 0
+# endif
+#endif
+
+#ifndef S_ISSOCK
+# ifdef S_IFSOCK
+#  define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+# else
+#  define S_ISSOCK(m) 0
+# endif
+#endif
+
+
+#ifndef S_TYPEISMQ
+# define S_TYPEISMQ(p) 0
+#endif
+
+#ifndef S_TYPEISTMO
+# define S_TYPEISTMO(p) 0
+#endif
+
+
+#ifndef S_TYPEISSEM
+# ifdef S_INSEM
+#  define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
+# else
+#  define S_TYPEISSEM(p) 0
+# endif
+#endif
+
+#ifndef S_TYPEISSHM
+# ifdef S_INSHD
+#  define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
+# else
+#  define S_TYPEISSHM(p) 0
+# endif
+#endif
+
+/* high performance ("contiguous data") */
+#ifndef S_ISCTG
+# define S_ISCTG(p) 0
+#endif
+
+/* Cray DMF (data migration facility): off line, with data  */
+#ifndef S_ISOFD
+# define S_ISOFD(p) 0
+#endif
+
+/* Cray DMF (data migration facility): off line, with no data  */
+#ifndef S_ISOFL
+# define S_ISOFL(p) 0
+#endif
+
+/* 4.4BSD whiteout */
+#ifndef S_ISWHT
+# define S_ISWHT(m) 0
+#endif
+
+/* If any of the following are undefined,
+   define them to their de facto standard values.  */
+#if !S_ISUID
+# define S_ISUID 04000
+#endif
+#if !S_ISGID
+# define S_ISGID 02000
+#endif
+
+/* S_ISVTX is a common extension to POSIX.  */
+#ifndef S_ISVTX
+# define S_ISVTX 01000
+#endif
+
+#if !S_IRUSR && S_IREAD
+# define S_IRUSR S_IREAD
+#endif
+#if !S_IRUSR
+# define S_IRUSR 00400
+#endif
+#if !S_IRGRP
+# define S_IRGRP (S_IRUSR >> 3)
+#endif
+#if !S_IROTH
+# define S_IROTH (S_IRUSR >> 6)
+#endif
+
+#if !S_IWUSR && S_IWRITE
+# define S_IWUSR S_IWRITE
+#endif
+#if !S_IWUSR
+# define S_IWUSR 00200
+#endif
+#if !S_IWGRP
+# define S_IWGRP (S_IWUSR >> 3)
+#endif
+#if !S_IWOTH
+# define S_IWOTH (S_IWUSR >> 6)
+#endif
+
+#if !S_IXUSR && S_IEXEC
+# define S_IXUSR S_IEXEC
+#endif
+#if !S_IXUSR
+# define S_IXUSR 00100
+#endif
+#if !S_IXGRP
+# define S_IXGRP (S_IXUSR >> 3)
+#endif
+#if !S_IXOTH
+# define S_IXOTH (S_IXUSR >> 6)
+#endif
+
+#if !S_IRWXU
+# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
+#endif
+#if !S_IRWXG
+# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
+#endif
+#if !S_IRWXO
+# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
+#endif
+
+/* S_IXUGO is a common extension to POSIX.  */
+#if !S_IXUGO
+# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
+#endif
+
+#ifndef S_IRWXUGO
+# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
+#endif
+
+/* mingw does not support symlinks, therefore it does not have lstat.  But
+   without links, stat does just fine.  */
+#if ! HAVE_LSTAT
+# define lstat stat
+#endif
+
+/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
+   Additionally, it declares _mkdir (and depending on compile flags, an
+   alias mkdir), only in the nonstandard io.h.  */
+#if ! HAVE_DECL_MKDIR && HAVE_IO_H
+# include <io.h>
+
+static inline int
+rpl_mkdir (char const *name, mode_t mode)
+{
+  return _mkdir (name);
+}
+
+# define mkdir rpl_mkdir
+#endif
+
+#endif /* _GL_SYS_STAT_H */
diff --git a/lib/stdbool_.h b/lib/stdbool_.h
new file mode 100644 (file)
index 0000000..150a010
--- /dev/null
@@ -0,0 +1,118 @@
+/* Copyright (C) 2001, 2002, 2003, 2006, 2007 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.  */
+#ifdef __BEOS__
+# 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__
+  /* 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".
+        The only benefit of the enum type, debuggability, is not important
+        with these compilers.  So use 'signed char' and no typedef.  */
+#  define _Bool signed char
+enum { false = 0, true = 1 };
+# 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 */
diff --git a/lib/stdlib_.h b/lib/stdlib_.h
new file mode 100644 (file)
index 0000000..0581509
--- /dev/null
@@ -0,0 +1,148 @@
+/* A GNU-like <stdlib.h>.
+
+   Copyright (C) 1995, 2001-2002, 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.  */
+
+#if defined __need_malloc_and_calloc
+/* Special invocation convention inside glibc header files.  */
+
+/* This #pragma avoids a warning with "gcc -Wall" on some glibc systems
+   on which <stdlib.h> has an inappropriate declaration, see
+   <http://sourceware.org/bugzilla/show_bug.cgi?id=1079>.  */
+#ifdef __GNUC__
+# pragma GCC system_header
+#endif
+
+#include @ABSOLUTE_STDLIB_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifdef __DECC
+# include_next <stdlib.h>
+#endif
+
+#ifndef _GL_STDLIB_H
+#define _GL_STDLIB_H
+
+/* This #pragma avoids a warning with "gcc -Wall" on some glibc systems
+   on which <stdlib.h> has an inappropriate declaration, see
+   <http://sourceware.org/bugzilla/show_bug.cgi?id=1079>.  */
+#ifdef __GNUC__
+# pragma GCC system_header
+#endif
+
+#ifndef __DECC
+# include @ABSOLUTE_STDLIB_H@
+#endif
+
+
+/* The definition of GL_LINK_WARNING is copied here.  */
+
+
+/* Some systems do not define EXIT_*, despite otherwise supporting C89.  */
+#ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+#endif
+/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
+   with proper operation of xargs.  */
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#elif EXIT_FAILURE != 1
+# undef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if @GNULIB_GETSUBOPT@
+/* Assuming *OPTIONP is a comma separated list of elements of the form
+   "token" or "token=value", getsubopt parses the first of these elements.
+   If the first element refers to a "token" that is member of the given
+   NULL-terminated array of tokens:
+     - It replaces the comma with a NUL byte, updates *OPTIONP to point past
+       the first option and the comma, sets *VALUEP to the value of the
+       element (or NULL if it doesn't contain an "=" sign),
+     - It returns the index of the "token" in the given array of tokens.
+   Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
+   For more details see the POSIX:2001 specification.
+   http://www.opengroup.org/susv3xsh/getsubopt.html */
+# if !@HAVE_GETSUBOPT@
+extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getsubopt
+# define getsubopt(o,t,v) \
+    (GL_LINK_WARNING ("getsubopt is unportable - " \
+                      "use gnulib module getsubopt for portability"), \
+     getsubopt (o, t, v))
+#endif
+
+
+#if @GNULIB_MKDTEMP@
+# if !@HAVE_MKDTEMP@
+/* Create a unique temporary directory from TEMPLATE.
+   The last six characters of TEMPLATE must be "XXXXXX";
+   they are replaced with a string that makes the directory name unique.
+   Returns TEMPLATE, or a null pointer if it cannot get a unique name.
+   The directory is created mode 700.  */
+extern char * mkdtemp (char *template);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mkdtemp
+# define mkdtemp(t) \
+    (GL_LINK_WARNING ("mkdtemp is unportable - " \
+                      "use gnulib module mkdtemp for portability"), \
+     mkdtemp (t))
+#endif
+
+
+#if @GNULIB_MKSTEMP@
+# if @REPLACE_MKSTEMP@
+/* Create a unique temporary file from TEMPLATE.
+   The last six characters of TEMPLATE must be "XXXXXX";
+   they are replaced with a string that makes the file name unique.
+   The file is then created, ensuring it didn't exist before.
+   The file is created read-write (mask at least 0600 & ~umask), but it may be
+   world-readable and world-writable (mask 0666 & ~umask), depending on the
+   implementation.
+   Returns the open file descriptor if successful, otherwise -1 and errno
+   set.  */
+#  define mkstemp rpl_mkstemp
+extern int mkstemp (char *template);
+# else
+/* On MacOS X 10.3, only <unistd.h> declares mkstemp.  */
+#  include <unistd.h>
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mkstemp
+# define mkstemp(t) \
+    (GL_LINK_WARNING ("mkstemp is unportable - " \
+                      "use gnulib module mkstemp for portability"), \
+     mkstemp (t))
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GL_STDLIB_H */
+#endif
diff --git a/lib/sys_time_.h b/lib/sys_time_.h
new file mode 100644 (file)
index 0000000..9337be3
--- /dev/null
@@ -0,0 +1,44 @@
+/* Provide a more complete sys/time.h.
+
+   Copyright (C) 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 Paul Eggert.  */
+
+#ifndef _GL_SYS_TIME_H
+#define _GL_SYS_TIME_H
+
+#if @HAVE_SYS_TIME_H@
+# include @ABSOLUTE_SYS_TIME_H@
+#else
+# include <time.h>
+#endif
+
+#if ! @HAVE_STRUCT_TIMEVAL@
+struct timeval
+{
+  time_t tv_sec;
+  long int tv_usec;
+};
+#endif
+
+#if @REPLACE_GETTIMEOFDAY@
+# undef gettimeofday
+# define gettimeofday rpl_gettimeofday
+int gettimeofday (struct timeval *restrict, void *restrict);
+#endif
+
+#endif /* _GL_SYS_TIME_H */
diff --git a/lib/time_.h b/lib/time_.h
new file mode 100644 (file)
index 0000000..28fb04d
--- /dev/null
@@ -0,0 +1,118 @@
+/* A more-standard <time.h>.
+
+   Copyright (C) 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.  */
+
+/* Don't get in the way of glibc when it includes time.h merely to
+   declare a few standard symbols, rather than to declare all the
+   symbols.  */
+#if defined __need_time_t || defined __need_clock_t || defined __need_timespec
+# include @ABSOLUTE_TIME_H@
+
+#else
+/* Normal invocation convention.  */
+
+# ifdef __DECC
+#  include_next <time.h>
+# endif
+
+# if ! defined _GL_TIME_H
+#  define _GL_TIME_H
+
+#  ifndef __DECC
+#   include @ABSOLUTE_TIME_H@
+#  endif
+
+#  ifdef __cplusplus
+extern "C" {
+#  endif
+
+/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
+   Or they define it with the wrong member names or define it in <sys/time.h>
+   (e.g., FreeBSD circa 1997).  */
+#  if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
+#   if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
+#    include <sys/time.h>
+#   else
+#    undef timespec
+#    define timespec rpl_timespec
+struct timespec
+{
+  time_t tv_sec;
+  long int tv_nsec;
+};
+#   endif
+#  endif
+
+/* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
+   return -1 and store the remaining time into RMTP.  See
+   <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
+#  if @REPLACE_NANOSLEEP@
+#   define nanosleep rpl_nanosleep
+int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp);
+#  endif
+
+/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
+   <http://www.opengroup.org/susv3xsh/localtime_r.html> and
+   <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
+#  if @REPLACE_LOCALTIME_R@
+#   undef localtime_r
+#   define localtime_r rpl_localtime_r
+#   undef gmtime_r
+#   define gmtime_r rpl_gmtime_r
+struct tm *localtime_r (time_t const *restrict __timer,
+                       struct tm *restrict __result);
+struct tm *gmtime_r (time_t const *restrict __timer,
+                    struct tm *restrict __result);
+#  endif
+
+/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
+   the resulting broken-down time into TM.  See
+   <http://www.opengroup.org/susv3xsh/strptime.html>.  */
+#  if @REPLACE_STRPTIME@
+#   undef strptime
+#   define strptime rpl_strptime
+char *strptime (char const *restrict __buf, char const *restrict __format,
+               struct tm *restrict __tm);
+#  endif
+
+/* Convert TM to a time_t value, assuming UTC.  */
+#  if @REPLACE_TIMEGM@
+#   undef timegm
+#   define timegm rpl_timegm
+time_t timegm (struct tm *__tm);
+#  endif
+
+/* Encourage applications to avoid unsafe functions that can overrun
+   buffers when given outlandish struct tm values.  Portable
+   applications should use strftime (or even sprintf) instead.  */
+#  if GNULIB_PORTCHECK
+#   undef asctime
+#   define asctime eschew_asctime
+#   undef asctime_r
+#   define asctime_r eschew_asctime_r
+#   undef ctime
+#   define ctime eschew_ctime
+#   undef ctime_r
+#   define ctime_r eschew_ctime_r
+#  endif
+
+#  ifdef __cplusplus
+}
+#  endif
+
+# endif
+#endif
diff --git a/lib/unistd_.h b/lib/unistd_.h
new file mode 100644 (file)
index 0000000..77df861
--- /dev/null
@@ -0,0 +1,192 @@
+/* Substitute for and wrapper around <unistd.h>.
+   Copyright (C) 2004-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.  */
+
+#ifndef _GL_UNISTD_H
+#define _GL_UNISTD_H
+
+#if @HAVE_UNISTD_H@
+# include @ABSOLUTE_UNISTD_H@
+#endif
+
+
+/* The definition of GL_LINK_WARNING is copied here.  */
+
+
+/* Declare overridden functions.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if @GNULIB_CHOWN@
+# if @REPLACE_CHOWN@
+/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
+   to GID (if GID is not -1).
+   Return 0 if successful, otherwise -1 and errno set.
+   See the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/chown.html>.  */
+#  define chown rpl_chown
+extern int chown (const char *file, uid_t uid, gid_t gid);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef chown
+# define chown(f,u,g) \
+    (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
+                      "doesn't treat a uid or gid of -1 on some systems - " \
+                      "use gnulib module chown for portability"), \
+     chown (f, u, g))
+#endif
+
+
+#if @GNULIB_DUP2@
+# if !@HAVE_DUP2@
+/* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
+   NEWFD = OLDFD, otherwise close NEWFD first if it is open.
+   Return 0 if successful, otherwise -1 and errno set.
+   See the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/dup2.html>.  */
+extern int dup2 (int oldfd, int newfd);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef dup2
+# define dup2(o,n) \
+    (GL_LINK_WARNING ("dup2 is unportable - " \
+                      "use gnulib module dup2 for portability"), \
+     dup2 (o, n))
+#endif
+
+
+#if @GNULIB_FCHDIR@
+# if @REPLACE_FCHDIR@
+
+/* Change the process' current working directory to the directory on which
+   the given file descriptor is open.
+   Return 0 if successful, otherwise -1 and errno set.
+   See the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
+extern int fchdir (int /*fd*/);
+
+#  define close rpl_close
+extern int close (int);
+#  define dup rpl_dup
+extern int dup (int);
+#  define dup2 rpl_dup2
+extern int dup2 (int, int);
+
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef fchdir
+# define fchdir(f) \
+    (GL_LINK_WARNING ("fchdir is unportable - " \
+                      "use gnulib module fchdir for portability"), \
+     fchdir (f))
+#endif
+
+
+#if @GNULIB_FTRUNCATE@
+# if !@HAVE_FTRUNCATE@
+/* Change the size of the file to which FD is opened to become equal to LENGTH.
+   Return 0 if successful, otherwise -1 and errno set.
+   See the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
+extern int ftruncate (int fd, off_t length);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef ftruncate
+# define ftruncate(f,l) \
+    (GL_LINK_WARNING ("ftruncate is unportable - " \
+                      "use gnulib module ftruncate for portability"), \
+     ftruncate (f, l))
+#endif
+
+
+#if @GNULIB_GETCWD@
+/* Include the headers that might declare getcwd so that they will not
+   cause confusion if included after this file.  */
+# include <stdlib.h>
+# if @REPLACE_GETCWD@
+/* Get the name of the current working directory, and put it in SIZE bytes
+   of BUF.
+   Return BUF if successful, or NULL if the directory couldn't be determined
+   or SIZE was too small.
+   See the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/getcwd.html>.
+   Additionally, the gnulib module 'getcwd' guarantees the following GNU
+   extension: If BUF is NULL, an array is allocated with 'malloc'; the array
+   is SIZE bytes long, unless SIZE == 0, in which case it is as big as
+   necessary.  */
+#  define getcwd rpl_getcwd
+extern char * getcwd (char *buf, size_t size);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getcwd
+# define getcwd(b,s) \
+    (GL_LINK_WARNING ("getcwd is unportable - " \
+                      "use gnulib module getcwd for portability"), \
+     getcwd (b, s))
+#endif
+
+
+#if @GNULIB_GETLOGIN_R@
+/* Copies the user's login name to NAME.
+   The array pointed to by NAME has room for SIZE bytes.
+
+   Returns 0 if successful.  Upon error, an error number is returned, or -1 in
+   the case that the login name cannot be found but no specific error is
+   provided (this case is hopefully rare but is left open by the POSIX spec).
+
+   See <http://www.opengroup.org/susv3xsh/getlogin.html>.
+ */
+# if !@HAVE_DECL_GETLOGIN_R@
+#  include <stddef.h>
+extern int getlogin_r (char *name, size_t size);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getlogin_r
+# define getlogin_r(n,s) \
+    (GL_LINK_WARNING ("getlogin_r is unportable - " \
+                      "use gnulib module getlogin_r for portability"), \
+     getlogin_r (n, s))
+#endif
+
+
+#if @GNULIB_READLINK@
+/* Read the contents of the symbolic link FILE and place the first BUFSIZE
+   bytes of it into BUF.  Return the number of bytes placed into BUF if
+   successful, otherwise -1 and errno set.
+   See the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/readlink.html>.  */
+# if !@HAVE_READLINK@
+#  include <stddef.h>
+extern int readlink (const char *file, char *buf, size_t bufsize);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef readlink
+# define readlink(f,b,s) \
+    (GL_LINK_WARNING ("readlink is unportable - " \
+                      "use gnulib module readlink for portability"), \
+     readlink (f, b, s))
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _GL_UNISTD_H */
diff --git a/m4/absolute-header.m4 b/m4/absolute-header.m4
new file mode 100644 (file)
index 0000000..c649df0
--- /dev/null
@@ -0,0 +1,44 @@
+# absolute-header.m4 serial 6
+dnl Copyright (C) 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 Derek Price.
+
+# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...)
+# ---------------------------------------
+# Find the absolute name of a header file, assuming the header exists.
+# If the header were sys/inttypes.h, this macro would define
+# ABSOLUTE_SYS_INTTYPES_H to the `""' quoted absolute name of sys/inttypes.h
+# in config.h
+# (e.g. `#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"').
+# The three "///" are to pacify Sun C 5.8, which otherwise would say
+# "warning: #include of /usr/include/... may be non-portable".
+# Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
+AC_DEFUN([gl_ABSOLUTE_HEADER],
+[AC_LANG_PREPROC_REQUIRE()dnl
+AC_FOREACH([gl_HEADER_NAME], [$1],
+  [AS_VAR_PUSHDEF([gl_absolute_header],
+                  [gl_cv_absolute_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl
+  AC_CACHE_CHECK([absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
+    m4_quote(m4_defn([gl_absolute_header])),
+    [AS_VAR_PUSHDEF([ac_header_exists],
+                    [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl
+    AC_CHECK_HEADERS_ONCE(m4_quote(m4_defn([gl_HEADER_NAME])))dnl
+    if test AS_VAR_GET(ac_header_exists) = yes; then
+      AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]])])
+dnl eval is necessary to expand ac_cpp.
+dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
+      AS_VAR_SET(gl_absolute_header,
+[`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
+sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#;s#^/[^/]#//&#;p;q;}'`])
+    fi
+    AS_VAR_POPDEF([ac_header_exists])dnl
+    ])dnl
+  AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_quote(m4_defn([gl_HEADER_NAME]))),
+                     ["AS_VAR_GET(gl_absolute_header)"],
+                     [Define this to an absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>.])
+  AS_VAR_POPDEF([gl_absolute_header])dnl
+])dnl
+])# gl_ABSOLUTE_HEADER
diff --git a/trees.c b/trees.c
index 3896cf5541682ea7aee6514c6c5cc182aeff8fb2..03c7c02c52e7d3cfd038145b5fb0c2d9b705c9e3 100644 (file)
--- a/trees.c
+++ b/trees.c
  *      void ct_tally (int dist, int lc);
  *          Save the match info and tally the frequency counts.
  *
- *      off_t flush_block (char *buf, ulg stored_len, int eof)
+ *      off_t flush_block (char *buf, ulg stored_len, int pad, int eof)
  *          Determine the best encoding for the current block: dynamic trees,
  *          static trees or store, and output the encoded block to the zip
- *          file. Returns the total compressed length for the file so far.
- *
- */
+ *          file. If pad is set, pads the block to the next
+ *          byte. Returns the total compressed length for the file so
+ *          far.
+ * */
 
 #include <config.h>
 #include <ctype.h>
@@ -856,9 +857,10 @@ local void send_all_trees(lcodes, dcodes, blcodes)
  * trees or store, and output the encoded block to the zip file. This function
  * returns the total compressed length for the file so far.
  */
-off_t flush_block(buf, stored_len, eof)
+off_t flush_block(buf, stored_len, pad, eof)
     char *buf;        /* input block, or NULL if too old */
     ulg stored_len;   /* length of input block */
+    int pad;          /* pad output to byte boundary */
     int eof;          /* true if this is the last block for a file */
 {
     ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
@@ -951,6 +953,10 @@ off_t flush_block(buf, stored_len, eof)
         Assert (input_len == bytes_in, "bad input size");
         bi_windup();
         compressed_len += 7;  /* align on byte boundary */
+    } else if (pad && (compressed_len % 8) != 0) {
+        send_bits((STORED_BLOCK<<1)+eof, 3);  /* send block type */
+        compressed_len = (compressed_len + 3 + 7) & ~7L;
+        copy_block(buf, 0, 1); /* with header */
     }
 
     return compressed_len >> 3;