diff options
38 files changed, 838 insertions, 461 deletions
diff --git a/config/ChangeLog b/config/ChangeLog index c8838cd35..7431203b1 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,7 @@ +2004-08-05 Paul Eggert <eggert@cs.ucla.edu> + + * config.guess, config.sub, install-sh, texinfo.tex: Sync from gnulib. + 2004-03-30 Paul Eggert <eggert@twinsun.com> * config.guess, config.sub, install-sh, texinfo.tex: Sync from gnulib. diff --git a/config/config.guess b/config/config.guess index 51fab4770..664145662 100644 --- a/config/config.guess +++ b/config/config.guess @@ -1,9 +1,9 @@ #! /bin/sh # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +# 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. -timestamp='2004-03-12' +timestamp='2004-07-19' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -53,7 +53,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -212,6 +212,9 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in hp300:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; + luna88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; mac68k:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; @@ -227,9 +230,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in mvmeppc:OpenBSD:*:*) echo powerpc-unknown-openbsd${UNAME_RELEASE} exit 0 ;; - pegasos:OpenBSD:*:*) - echo powerpc-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; pmax:OpenBSD:*:*) echo mipsel-unknown-openbsd${UNAME_RELEASE} exit 0 ;; @@ -307,9 +307,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # 1.2 uses "1.2" for uname -r. echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` exit 0 ;; - Alpha*:OpenVMS:*:*) - echo alpha-hp-vms - exit 0 ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead @@ -764,7 +761,7 @@ EOF echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit 0 ;; *:UNICOS/mp:*:*) - echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit 0 ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` @@ -787,21 +784,7 @@ EOF echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit 0 ;; *:FreeBSD:*:*) - # Determine whether the default compiler uses glibc. - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include <features.h> - #if __GLIBC__ >= 2 - LIBC=gnu - #else - LIBC= - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - # GNU/KFreeBSD systems have a "k" prefix to indicate we are using - # FreeBSD's kernel, but not the complete OS. - case ${LIBC} in gnu) kernel_only='k' ;; esac - echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit 0 ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin @@ -1096,9 +1079,9 @@ EOF M680?0:D-NIX:5.3:*) echo m68k-diab-dnix exit 0 ;; - M68*:*:R3V[567]*:*) + M68*:*:R3V[5678]*:*) test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0) + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` @@ -1260,6 +1243,13 @@ EOF *:DragonFly:*:*) echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit 0 ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms && exit 0 ;; + I*) echo ia64-dec-vms && exit 0 ;; + V*) echo vax-dec-vms && exit 0 ;; + esac esac #echo '(No uname command or uname output not recognized.)' 1>&2 diff --git a/config/config.sub b/config/config.sub index ba331039b..ac6de9869 100644 --- a/config/config.sub +++ b/config/config.sub @@ -1,9 +1,9 @@ #! /bin/sh # Configuration validation subroutine script. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +# 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. -timestamp='2004-03-12' +timestamp='2004-06-24' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -70,7 +70,7 @@ Report bugs and patches to <config-patches@gnu.org>." version="\ GNU config.sub ($timestamp) -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -145,7 +145,7 @@ case $os in -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis) + -apple | -axis | -knuth | -cray) os= basic_machine=$1 ;; @@ -300,7 +300,7 @@ case $basic_machine in | avr-* \ | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | cydra-* \ + | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ @@ -326,8 +326,9 @@ case $basic_machine in | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ + | mmix-* \ | msp430-* \ - | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ @@ -445,6 +446,10 @@ case $basic_machine in basic_machine=j90-cray os=-unicos ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; cr16c) basic_machine=cr16c-unknown os=-elf @@ -659,10 +664,6 @@ case $basic_machine in mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; - mmix*) - basic_machine=mmix-knuth - os=-mmixware - ;; monitor) basic_machine=m68k-rom68k os=-coff @@ -743,10 +744,6 @@ case $basic_machine in np1) basic_machine=np1-gould ;; - nv1) - basic_machine=nv1-cray - os=-unicosmp - ;; nsr-tandem) basic_machine=nsr-tandem ;; @@ -1059,6 +1056,9 @@ case $basic_machine in romp) basic_machine=romp-ibm ;; + mmix) + basic_machine=mmix-knuth + ;; rs6000) basic_machine=rs6000-ibm ;; @@ -1374,6 +1374,9 @@ case $basic_machine in *-ibm) os=-aix ;; + *-knuth) + os=-mmixware + ;; *-wec) os=-proelf ;; diff --git a/config/install-sh b/config/install-sh index e4160c991..b777f1244 100755 --- a/config/install-sh +++ b/config/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2004-04-01.17 +scriptversion=2004-07-05.00 # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -58,9 +58,6 @@ stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" -transformbasename= -transform_arg= -instcmd="$mvprog" chmodcmd="$chmodprog 0755" chowncmd= chgrpcmd= @@ -70,23 +67,27 @@ mvcmd="$mvprog" src= dst= dir_arg= +dstarg= +no_target_directory= -usage="Usage: $0 [OPTION]... SRCFILE DSTFILE +usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY - or: $0 -d DIRECTORIES... + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... -In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default. -In the second, create the directory path DIR. +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. Options: --b=TRANSFORMBASENAME --c copy source (using $cpprog) instead of moving (using $mvprog). +-c (ignored) -d create directories instead of installing files. --g GROUP $chgrp installed files to GROUP. --m MODE $chmod installed files to MODE. --o USER $chown installed files to USER. --s strip installed files (using $stripprog). --t=TRANSFORM +-g GROUP $chgrpprog installed files to GROUP. +-m MODE $chmodprog installed files to MODE. +-o USER $chownprog installed files to USER. +-s $stripprog installed files. +-t DIRECTORY install into DIRECTORY. +-T report an error if DSTFILE is a directory. --help display this help and exit. --version display version info and exit. @@ -96,12 +97,7 @@ Environment variables override the default commands: while test -n "$1"; do case $1 in - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - -c) instcmd=$cpprog - shift + -c) shift continue;; -d) dir_arg=true @@ -129,14 +125,20 @@ while test -n "$1"; do shift continue;; - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; + -t) dstarg=$2 + shift + shift + continue;; + + -T) no_target_directory=true + shift + continue;; --version) echo "$0 $scriptversion"; exit 0;; *) # When -d is used, all remaining arguments are directories to create. - test -n "$dir_arg" && break + # When -t is used, the destination is already specified. + test -n "$dir_arg$dstarg" && break # Otherwise, the last argument is the destination. Remove it from $@. for arg do @@ -174,13 +176,13 @@ do src= if test -d "$dst"; then - instcmd=: + mkdircmd=: chmodcmd= else - instcmd=$mkdirprog + mkdircmd=$mkdirprog fi else - # Waiting for this to be detected by the "$instcmd $src $dsttmp" command + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then @@ -202,6 +204,10 @@ do # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dstarg: Is a directory" >&2 + exit 1 + fi dst=$dst/`basename "$src"` fi fi @@ -229,34 +235,25 @@ do pathcomp=$pathcomp$1 shift if test ! -d "$pathcomp"; then - $mkdirprog "$pathcomp" || lasterr=$? + $mkdirprog "$pathcomp" # mkdir can fail with a `File exist' error in case several # install-sh are creating the directory concurrently. This # is OK. - test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; } + test -d "$pathcomp" || exit fi pathcomp=$pathcomp/ done fi if test -n "$dir_arg"; then - $doit $instcmd "$dst" \ + $doit $mkdircmd "$dst" \ && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } else - # If we're going to rename the final executable, determine the name now. - if test -z "$transformarg"; then - dstfile=`basename "$dst"` - else - dstfile=`basename "$dst" $transformbasename \ - | sed $transformarg`$transformbasename - fi - - # don't allow the sed command to completely eliminate the filename. - test -z "$dstfile" && dstfile=`basename "$dst"` + dstfile=`basename "$dst"` # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ @@ -266,14 +263,14 @@ do trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 trap '(exit $?); exit' 1 2 13 15 - # Move or copy the file name to the temp name - $doit $instcmd "$src" "$dsttmp" && + # Copy the file name to the temp name. + $doit $cpprog "$src" "$dsttmp" && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore - # errors from the above "$doit $instcmd $src $dsttmp" command. + # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ diff --git a/config/texinfo.tex b/config/texinfo.tex index 0617e965e..67d9fd869 100644 --- a/config/texinfo.tex +++ b/config/texinfo.tex @@ -3,7 +3,7 @@ % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2004-03-21.11} +\def\texinfoversion{2004-07-31.11} % % Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995, % 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software @@ -608,7 +608,7 @@ % The \TeX{} logo, as in plain, but resetting the spacing so that a % period following counts as ending a sentence. (Idea found in latex.) % -\edef\TeX{\TeX \spacefactor=3000 } +\edef\TeX{\TeX \spacefactor=1000 } % @LaTeX{} logo. Not quite the same results as the definition in % latex.ltx, since we use a different font for the raised A; it's most @@ -1715,6 +1715,7 @@ where each line of input produces a line of output.} \def\cite#1{{\sl #1}\futurelet\next\smartitalicx} \let\i=\smartitalic +\let\slanted=\smartslanted \let\var=\smartslanted \let\dfn=\smartslanted \let\emph=\smartitalic @@ -1851,8 +1852,8 @@ where each line of input produces a line of output.} \else{\tclose{\kbdfont\look}}\fi \else{\tclose{\kbdfont\look}}\fi} -% For @url, @env, @command quotes seem unnecessary, so use \code. -\let\url=\code +% For @indicateurl, @env, @command quotes seem unnecessary, so use \code. +\let\indicateurl=\code \let\env=\code \let\command=\code @@ -1884,6 +1885,10 @@ where each line of input produces a line of output.} \endlink \endgroup} +% @url synonym for @uref, since that's how everyone uses it. +% +\let\url=\uref + % rms does not like angle brackets --karl, 17may97. % So now @email is just like @uref, unless we are pdf. % @@ -1925,6 +1930,10 @@ where each line of input produces a line of output.} \def\sc#1{{\smallcaps#1}} % smallcaps font \def\ii#1{{\it #1}} % italic font +% @acronym for "FBI", "NATO", and the like. +% We print this one point size smaller, since it's intended for +% all-uppercase. +% \def\acronym#1{\doacronym #1,,\finish} \def\doacronym#1,#2,#3\finish{% {\selectfonts\lsize #1}% @@ -1934,7 +1943,19 @@ where each line of input produces a line of output.} \fi } -% @pounds{} is a sterling sign, which is in the CM italic font. +% @abbr for "Comput. J." and the like. +% No font change, but don't do end-of-sentence spacing. +% +\def\abbr#1{\doabbr #1,,\finish} +\def\doabbr#1,#2,#3\finish{% + {\frenchspacing #1}% + \def\temp{#2}% + \ifx\temp\empty \else + \space ({\unsepspaces \ignorespaces \temp \unskip})% + \fi +} + +% @pounds{} is a sterling sign, which Knuth put in the CM italic font. % \def\pounds{{\it\$}} @@ -1948,6 +1969,14 @@ where each line of input produces a line of output.} }$% } +% Laurent Siebenmann reports \Orb undefined with: +% Textures 1.7.7 (preloaded format=plain 93.10.14) (68K) 16 APR 2004 02:38 +% so we'll define it if necessary. +% +\ifx\Orb\undefined +\def\Orb{\mathhexbox20D} +\fi + \message{page headings,} @@ -2253,17 +2282,13 @@ where each line of input produces a line of output.} % \parskip glue -- logically it's part of the @item we just started. \nobreak \vskip-\parskip % - % Stop a page break at the \parskip glue coming up. (Unfortunately - % we can't prevent a possible page break at the following - % \baselineskip glue.) However, if what follows is an environment - % such as @example, there will be no \parskip glue; then - % the negative vskip we just would cause the example and the item to - % crash together. So we use this bizarre value of 10001 as a signal - % to \aboveenvbreak to insert \parskip glue after all. - % (Possibly there are other commands that could be followed by - % @example which need the same treatment, but not section titles; or - % maybe section titles are the only special case and they should be - % penalty 10001...) + % Stop a page break at the \parskip glue coming up. However, if + % what follows is an environment such as @example, there will be no + % \parskip glue; then the negative vskip we just inserted would + % cause the example and the item to crash together. So we use this + % bizarre value of 10001 as a signal to \aboveenvbreak to insert + % \parskip glue after all. Section titles are handled this way also. + % \penalty 10001 \endgroup \itemxneedsnegativevskipfalse @@ -2774,14 +2799,14 @@ width0pt\relax} \fi \doignorecount = 0 % % Swallow text until we reach the matching `@end #1'. - \dodoignore {#1}% + \dodoignore{#1}% } { \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source. \obeylines % % \gdef\dodoignore#1{% - % #1 contains the string `ifinfo'. + % #1 contains the command name as a string, e.g., `ifinfo'. % % Define a command to find the next `@end #1', which must be on a line % by itself. @@ -3050,6 +3075,7 @@ width0pt\relax} \fi \def\definedummyletter##1{% \expandafter\def\csname ##1\endcsname{\realbackslash ##1}% }% + \let\definedummyaccent\definedummyletter % % Do the redefinitions. \commondummies @@ -3072,6 +3098,7 @@ width0pt\relax} \fi \def\definedummyletter##1{% \expandafter\def\csname ##1\endcsname{@##1}% }% + \let\definedummyaccent\definedummyletter % % Do the redefinitions. \commondummies @@ -3120,6 +3147,7 @@ width0pt\relax} \fi % % Assorted special characters. \definedummyword{bullet}% + \definedummyword{comma}% \definedummyword{copyright}% \definedummyword{registeredsymbol}% \definedummyword{dots}% @@ -3152,18 +3180,18 @@ width0pt\relax} \fi \gdef\commondummiesnofonts{% % Control letters and accents. \definedummyletter{!}% - \definedummyletter{"}% - \definedummyletter{'}% + \definedummyaccent{"}% + \definedummyaccent{'}% \definedummyletter{*}% - \definedummyletter{,}% + \definedummyaccent{,}% \definedummyletter{.}% \definedummyletter{/}% \definedummyletter{:}% - \definedummyletter{=}% + \definedummyaccent{=}% \definedummyletter{?}% - \definedummyletter{^}% - \definedummyletter{`}% - \definedummyletter{~}% + \definedummyaccent{^}% + \definedummyaccent{`}% + \definedummyaccent{~}% \definedummyword{u}% \definedummyword{v}% \definedummyword{H}% @@ -3211,13 +3239,16 @@ width0pt\relax} \fi % would be for a given command (usually its argument). % \def\indexnofonts{% - \def\definedummyword##1{% + % Accent commands should become @asis. + \def\definedummyaccent##1{% \expandafter\let\csname ##1\endcsname\asis }% - % We can just ignore the accent commands and other control letters. + % We can just ignore other control letters. \def\definedummyletter##1{% \expandafter\def\csname ##1\endcsname{}% }% + % Hopefully, all control words can become @asis. + \let\definedummyword\definedummyaccent % \commondummiesnofonts % @@ -3254,6 +3285,7 @@ width0pt\relax} \fi % Assorted special characters. % (The following {} will end up in the sort string, but that's ok.) \def\bullet{bullet}% + \def\comma{,}% \def\copyright{copyright}% \def\registeredsymbol{R}% \def\dots{...}% @@ -3266,6 +3298,9 @@ width0pt\relax} \fi \def\point{.}% \def\print{-|}% \def\result{=>}% + % + % Don't write macro names. + \emptyusermacros } \let\indexbackslash=0 %overridden during \printindex. @@ -3386,17 +3421,18 @@ width0pt\relax} \fi \dosubindwrite % \ifx\lastskipmacro\zeroskipmacro - % if \lastskip was zero, perhaps the last item was a - % penalty, and perhaps it was >=10000, e.g., a \nobreak. - % In that case, we want to re-insert the penalty; since we - % just inserted a non-discardable item, any following glue - % (such as a \parskip) would be a breakpoint. For example: + % If \lastskip was zero, perhaps the last item was a penalty, and + % perhaps it was >=10000, e.g., a \nobreak. In that case, we want + % to re-insert the same penalty (values >10000 are used for various + % signals); since we just inserted a non-discardable item, any + % following glue (such as a \parskip) would be a breakpoint. For example: + % % @deffn deffn-whatever % @vindex index-whatever % Description. % would allow a break between the index-whatever whatsit % and the "Description." paragraph. - \ifnum\count255>9999 \nobreak \fi + \ifnum\count255>9999 \penalty\count255 \fi \else % On the other hand, if we had a nonzero \lastskip, % this make-up glue would be preceded by a non-discardable item @@ -4328,14 +4364,14 @@ width0pt\relax} \fi % glue accumulate. (Not a breakpoint because it's preceded by a % discardable item.) \vskip-\parskip - % - % This \nobreak is purely so the last item on the list is a \penalty - % of 10000. This is so other code, for instance \parsebodycommon, can - % check for and avoid allowing breakpoints. Otherwise, it would - % insert a valid breakpoint between: + % + % This is purely so the last item on the list is a known \penalty > + % 10000. This is so \startdefun can avoid allowing breakpoints after + % section headings. Otherwise, it would insert a valid breakpoint between: + % % @section sec-whatever % @deffn def-whatever - \nobreak + \penalty 10001 } @@ -4680,7 +4716,8 @@ width0pt\relax} \fi % start of the next paragraph will insert \parskip. % \def\aboveenvbreak{{% - % =10000 instead of <10000 because of a special case in \itemzzz, q.v. + % =10000 instead of <10000 because of a special case in \itemzzz and + % \sectionheading, q.v. \ifnum \lastpenalty=10000 \else \advance\envskipamount by \parskip \endgraf @@ -5041,8 +5078,7 @@ width0pt\relax} \fi } % @copying ... @end copying. -% Save the text away for @insertcopying later. Many commands won't be -% allowed in this context, but that's ok. +% Save the text away for @insertcopying later. % % We save the uninterpreted tokens, rather than creating a box. % Saving the text in a box would be much easier, but then all the @@ -5051,62 +5087,14 @@ width0pt\relax} \fi % file; b) letting users define the frontmatter in as flexible order as % possible is very desirable. % -\def\copying{\begingroup - % Define a command to swallow text until we reach `@end copying'. - % \ is the escape char in this texinfo.tex file, so it is the - % delimiter for the command; @ will be the escape char when we read - % it, but that doesn't matter. - \long\def\docopying##1\end copying{\gdef\copyingtext{##1}\enddocopying}% - % - % We must preserve ^^M's in the input file; see \insertcopying below. - \catcode`\^^M = \active - \docopying -} - -% What we do to finish off the copying text. -% -\def\enddocopying{\endgroup\ignorespaces} - -% @insertcopying. Here we must play games with ^^M's. On the one hand, -% we need them to delimit commands such as `@end quotation', so they -% must be active. On the other hand, we certainly don't want every -% end-of-line to be a \par, as would happen with the normal active -% definition of ^^M. On the third hand, two ^^M's in a row should still -% generate a \par. -% -% Our approach is to make ^^M insert a space and a penalty1 normally; -% then it can also check if \lastpenalty=1. If it does, then manually -% do \par. -% -% This messes up the normal definitions of @c[omment], so we redefine -% it. Similarly for @ignore. (These commands are used in the gcc -% manual for man page generation.) -% -% Seems pretty fragile, most line-oriented commands will presumably -% fail, but for the limited use of getting the copying text (which -% should be quite simple) inserted, we can hope it's ok. -% -{\catcode`\^^M=\active % -\gdef\insertcopying{\begingroup % - \parindent = 0pt % looks wrong on title page - \def^^M{% - \ifnum \lastpenalty=1 % - \par % - \else % - \space \penalty 1 % - \fi % - }% - % - % Fix @c[omment] for catcode 13 ^^M's. - \def\c##1^^M{\ignorespaces}% - \let\comment = \c % - % - % Don't bother jumping through all the hoops that \doignore does, it - % would be very hard since the catcodes are already set. - \long\def\ignore##1\end ignore{\ignorespaces}% - % - \copyingtext % -\endgroup}% +\def\copying{\checkenv{}\begingroup\scanargctxt\docopying} +\def\docopying#1@end copying{\endgroup\def\copyingtext{#1}} +% +\def\insertcopying{% + \begingroup + \parindent = 0pt % paragraph indentation looks wrong on title page + \scanexp\copyingtext + \endgroup } \message{defuns,} @@ -5124,10 +5112,11 @@ width0pt\relax} \fi % If there are two @def commands in a row, we'll have a \nobreak, % which is there to keep the function description together with its % header. But if there's nothing but headers, we need to allow a - % break somewhere. Check for penalty 10002 (inserted by - % \defargscommonending) instead of 10000, since the sectioning - % commands insert a \penalty10000, and we don't want to allow a break - % between a section heading and a defun. + % break somewhere. Check specifically for penalty 10002, inserted + % by \defargscommonending, instead of 10000, since the sectioning + % commands also insert a nobreak penalty, and we don't want to allow + % a break between a section heading and a defun. + % \ifnum\lastpenalty=10002 \penalty2000 \fi % % Similarly, after a section heading, do not allow a break. @@ -5451,7 +5440,7 @@ width0pt\relax} \fi \ifx\eTeXversion\undefined \newwrite\macscribble \def\scantokens#1{% - \toks0={#1\endinput}% + \toks0={#1}% \immediate\openout\macscribble=\jobname.tmp \immediate\write\macscribble{\the\toks0}% \immediate\closeout\macscribble @@ -5476,6 +5465,11 @@ width0pt\relax} \fi \endgroup } +\def\scanexp#1{% + \edef\temp{\noexpand\scanmacro{#1}}% + \temp +} + \newcount\paramno % Count of parameters \newtoks\macname % Macro name \newif\ifrecursive % Is it recursive? @@ -5516,7 +5510,7 @@ width0pt\relax} \fi % done by making ^^M (\endlinechar) catcode 12 when reading the macro % body, and then making it the \newlinechar in \scanmacro. -\def\macrobodyctxt{% +\def\scanctxt{% \catcode`\~=\other \catcode`\^=\other \catcode`\_=\other @@ -5524,22 +5518,27 @@ width0pt\relax} \fi \catcode`\<=\other \catcode`\>=\other \catcode`\+=\other + \catcode`\@=\other +} + +\def\scanargctxt{% + \scanctxt + \catcode`\\=\other + \catcode`\^^M=\other +} + +\def\macrobodyctxt{% + \scanctxt \catcode`\{=\other \catcode`\}=\other - \catcode`\@=\other \catcode`\^^M=\other - \usembodybackslash} + \usembodybackslash +} \def\macroargctxt{% - \catcode`\~=\other - \catcode`\^=\other - \catcode`\_=\other - \catcode`\|=\other - \catcode`\<=\other - \catcode`\>=\other - \catcode`\+=\other - \catcode`\@=\other - \catcode`\\=\other} + \scanctxt + \catcode`\\=\other +} % \mbodybackslash is the definition of \ in @macro bodies. % It maps \foo\ => \csname macarg.foo\endcsname => #N @@ -5721,11 +5720,25 @@ width0pt\relax} \fi \expandafter\parsearg \fi \next} -% We mant to disable all macros during \shipout so that they are not +% We want to disable all macros during \shipout so that they are not % expanded by \write. \def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}% \edef\next{\macrolist}\expandafter\endgroup\next} +% For \indexnofonts, we need to get rid of all macros, leaving only the +% arguments (if present). Of course this is not nearly correct, but it +% is the best we can do for now. makeinfo does not expand macros in the +% argument to @deffn, which ends up writing an index entry, and texindex +% isn't prepared for an index sort entry that starts with \. +% +% Since macro invocations are followed by braces, we can just redefine them +% to take a single TeX argument. The case of a macro invocation that +% goes to end-of-line is not handled. +% +\def\emptyusermacros{\begingroup + \def\do##1{\let\noexpand##1=\noexpand\asis}% + \edef\next{\macrolist}\expandafter\endgroup\next} + % @alias. % We need some trickery to remove the optional spaces around the equal @@ -5754,9 +5767,18 @@ width0pt\relax} \fi node \samp{\ignorespaces#1{}}} % @node's only job in TeX is to define \lastnode, which is used in -% cross-references. -\parseargdef\node{\checkenv{}\nodexxx #1,\finishnodeparse} -\def\nodexxx#1,#2\finishnodeparse{\gdef\lastnode{#1}} +% cross-references. The @node line might or might not have commas, and +% might or might not have spaces before the first comma, like: +% @node foo , bar , ... +% We don't want such trailing spaces in the node name. +% +\parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse} +% +% also remove a trailing comma, in case of something like this: +% @node Help-Cross, , , Cross-refs +\def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse} +\def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}} + \let\nwnode=\node \let\lastnode=\empty @@ -6322,11 +6344,14 @@ width0pt\relax} \fi \endgroup} -% @float FLOATTYPE,LOC ... @end float for displayed figures, tables, etc. -% We don't actually implement floating yet, we just plop the float "here". -% But it seemed the best name for the future. +% @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables, +% etc. We don't actually implement floating yet, we always include the +% float "here". But it seemed the best name for the future. % -\envparseargdef\float{\dofloat #1,,,\finish} +\envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish} + +% There may be a space before second and/or third parameter; delete it. +\def\eatcommaspace#1, {#1,} % #1 is the optional FLOATTYPE, the text label for this float, typically % "Figure", "Table", "Example", etc. Can't contain commas. If omitted, @@ -6347,6 +6372,10 @@ width0pt\relax} \fi \let\thisshortcaption=\empty % % don't lose footnotes inside @float. + % + % BEWARE: when the floats start float, we have to issue warning whenever an + % insert appears inside a float which could possibly float. --kasal, 26may04 + % \startsavinginserts % % We can't be used inside a paragraph. @@ -6431,7 +6460,7 @@ width0pt\relax} \fi \fi % % caption text. - \appendtomacro\captionline\thiscaption + \appendtomacro\captionline{\scanexp\thiscaption}% \fi % % If we have anything to print, print it, with space before. @@ -6463,23 +6492,27 @@ width0pt\relax} \fi % Space below caption, if we printed anything. \ifx\printedsomething\empty \else \vskip\parskip \fi \egroup % end of \vtop + % + % place the captured inserts + % + % BEWARE: when the floats start float, we have to issue warning whenever an + % insert appears inside a float which could possibly float. --kasal, 26may04 + % \checkinserts } % Append the tokens #2 to the definition of macro #1, not expanding either. % -\newtoks\appendtomacroAtoks -\newtoks\appendtomacroBtoks \def\appendtomacro#1#2{% - \appendtomacroAtoks = \expandafter{#1}% - \appendtomacroBtoks = {#2}% - \edef#1{\the\appendtomacroAtoks \the\appendtomacroBtoks}% + \expandafter\def\expandafter#1\expandafter{#1#2}% } -% @caption, @shortcaption are easy. +% @caption, @shortcaption % -\long\def\caption#1{\checkenv\float \def\thiscaption{#1}} -\def\shortcaption#1{\checkenv\float \def\thisshortcaption{#1}} +\def\caption{\docaption\thiscaption} +\def\shortcaption{\docaption\thisshortcaption} +\def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption} +\def\defcaption#1#2{\egroup \def#1{#2}} % The parameter is the control sequence identifying the counter we are % going to use. Create it if it doesn't exist and assign it to \floatno. diff --git a/lib/.cppi-disable b/lib/.cppi-disable index 11a9ea9f2..afd50d090 100644 --- a/lib/.cppi-disable +++ b/lib/.cppi-disable @@ -2,7 +2,7 @@ alloca_.h allocsa.h error.h exit.h -fnmatch.h +fnmatch_.h fts.c fts_.h getndelim2.h diff --git a/lib/.cvsignore b/lib/.cvsignore index 615f8c8dc..807a9e8ad 100644 --- a/lib/.cvsignore +++ b/lib/.cvsignore @@ -4,12 +4,12 @@ alloca.h charset.alias getdate.c getdate.tab.c +fnmatch.h lstat.c +poll.h ref-add.sed ref-del.sed -safe-lstat.c -safe-lstat.h -safe-stat.c -safe-stat.h stat.c +stdbool.h +sysexit.h unlocked-io.h diff --git a/lib/ChangeLog b/lib/ChangeLog index 442792602..5cddfbdb6 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,28 @@ +2004-08-05 Paul Eggert <eggert@cs.ucla.edu> + + Merge with gnulib and deal with some minor cleanups resulting. + + * .cppi-disable: Change fnmatch.h to fnmatch_.h. + * .cvs-ignore: Add fnmatch.h, poll.h, stdbool.h, sysexit.h. + Remove safe-lstat.c, safe-lstat.h, safe-stat.c, safe-stat.h. + + * backupfile.h, closeout.h, full-write.h, mbswidth.h, xalloc.h: + Add extern "C" wrappers for C++. + + * dirname.h (IS_ABSOLUTE_FILE_NAME): Port to DOS. + + * gettime.c (gettime): Fall back on `time' if `gettimeofday' + doesn't work. + * settime.c: Include <unistd.h>, for stime (on Solaris 8, anyway). + (ENOSYS): Define if not defined. + (settime): Fall back on stime if it exists and settimeofday fails. + But don't bother with fallbacks if a method fails with errno == EPERM. + + * obstack.h: Add white space. + + * printf-parse.c, printf-parse.h, vasnprintf.c: Merge changes from + gnulib, but rewrite to avoid "xsize.h". + 2004-08-04 Paul Eggert <eggert@cs.ucla.edu> * mountlist.c (SIZE_MAX): Define after including files, to avoid diff --git a/lib/backupfile.h b/lib/backupfile.h index f330f51cd..346b60c3e 100644 --- a/lib/backupfile.h +++ b/lib/backupfile.h @@ -21,6 +21,11 @@ #ifndef BACKUPFILE_H_ # define BACKUPFILE_H_ +# ifdef __cplusplus +extern "C" { +# endif + + /* When to make backup files. */ enum backup_type { @@ -49,5 +54,11 @@ extern char const *simple_backup_suffix; char *find_backup_file_name (char const *, enum backup_type); enum backup_type get_version (char const *context, char const *arg); enum backup_type xget_version (char const *context, char const *arg); +void addext (char *, char const *, int); + + +# ifdef __cplusplus +} +# endif #endif /* ! BACKUPFILE_H_ */ diff --git a/lib/closeout.h b/lib/closeout.h index d27d7601e..1b715ee30 100644 --- a/lib/closeout.h +++ b/lib/closeout.h @@ -1,6 +1,6 @@ /* Close standard output. - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,7 +19,15 @@ #ifndef CLOSEOUT_H # define CLOSEOUT_H 1 +# ifdef __cplusplus +extern "C" { +# endif + void close_stdout_set_file_name (const char *file); void close_stdout (void); +# ifdef __cplusplus +} +# endif + #endif diff --git a/lib/dirname.h b/lib/dirname.h index 91479ad9a..bc2400a7d 100644 --- a/lib/dirname.h +++ b/lib/dirname.h @@ -34,8 +34,8 @@ # define FILE_SYSTEM_PREFIX_LEN(Filename) 0 # endif -# define IS_ABSOLUTE_FILE_NAME(Name) (ISSLASH (*Name)) -# define IS_RELATIVE_FILE_NAME(Name) ( ! IS_ABSOLUTE_FILE_NAME (Name)) +# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) +# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) char *base_name (char const *path); char *dir_name (char const *path); diff --git a/lib/full-write.h b/lib/full-write.h index 8cd2e8157..2637903ec 100644 --- a/lib/full-write.h +++ b/lib/full-write.h @@ -1,6 +1,6 @@ /* An interface to write() that writes all it is asked to write. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,18 @@ #include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + + /* Write COUNT bytes at BUF to descriptor FD, retrying if interrupted or if partial writes occur. Return the number of bytes successfully written, setting errno if that is less than COUNT. */ extern size_t full_write (int fd, const void *buf, size_t count); + + +#ifdef __cplusplus +} +#endif diff --git a/lib/gettime.c b/lib/gettime.c index 528060733..715d1916a 100644 --- a/lib/gettime.c +++ b/lib/gettime.c @@ -1,5 +1,5 @@ /* gettime -- get the system clock - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,14 +33,27 @@ gettime (struct timespec *ts) return 0; #endif +#if HAVE_GETTIMEOFDAY { struct timeval tv; - int r = gettimeofday (&tv, 0); - if (r == 0) + if (gettimeofday (&tv, 0) == 0) { ts->tv_sec = tv.tv_sec; ts->tv_nsec = tv.tv_usec * 1000; + return 0; } - return r; } +#endif + + { + time_t t = time (0); + if (t != (time_t) -1) + { + ts->tv_sec = t; + ts->tv_nsec = 0; + return 0; + } + } + + return -1; } diff --git a/lib/mbswidth.h b/lib/mbswidth.h index 6fec3f490..4fcdb2096 100644 --- a/lib/mbswidth.h +++ b/lib/mbswidth.h @@ -30,6 +30,11 @@ #endif +#ifdef __cplusplus +extern "C" { +#endif + + /* Optional flags to influence mbswidth/mbsnwidth behavior. */ /* If this bit is set, return -1 upon finding an invalid or incomplete @@ -49,3 +54,8 @@ extern int mbswidth (const char *string, int flags); /* Returns the number of screen columns needed for the NBYTES bytes starting at BUF. */ extern int mbsnwidth (const char *buf, size_t nbytes, int flags); + + +#ifdef __cplusplus +} +#endif diff --git a/lib/obstack.h b/lib/obstack.h index dec18aca8..d46b0544a 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -206,7 +206,7 @@ extern int obstack_exit_failure; Note that this might not be the final address of the object because a new chunk might be needed to hold the final size. */ -#define obstack_base(h) ((void *)(h)->object_base) +#define obstack_base(h) ((void *) (h)->object_base) /* Size for allocating ordinary chunks. */ diff --git a/lib/printf-parse.c b/lib/printf-parse.c index 51b08bbb0..4663a7269 100644 --- a/lib/printf-parse.c +++ b/lib/printf-parse.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,7 +20,11 @@ #endif /* Specification. */ -#include "printf-parse.h" +#if WIDE_CHAR_VERSION +# include "wprintf-parse.h" +#else +# include "printf-parse.h" +#endif /* Get size_t, NULL. */ #include <stddef.h> @@ -36,22 +40,38 @@ /* malloc(), realloc(), free(). */ #include <stdlib.h> +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif + +#if WIDE_CHAR_VERSION +# define PRINTF_PARSE wprintf_parse +# define CHAR_T wchar_t +# define DIRECTIVE wchar_t_directive +# define DIRECTIVES wchar_t_directives +#else +# define PRINTF_PARSE printf_parse +# define CHAR_T char +# define DIRECTIVE char_directive +# define DIRECTIVES char_directives +#endif + #ifdef STATIC STATIC #endif int -printf_parse (const char *format, char_directives *d, arguments *a) +PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { - const char *cp = format; /* pointer into format */ - int arg_posn = 0; /* number of regular arguments consumed */ - unsigned int d_allocated; /* allocated elements of d->dir */ - unsigned int a_allocated; /* allocated elements of a->arg */ - unsigned int max_width_length = 0; - unsigned int max_precision_length = 0; + const CHAR_T *cp = format; /* pointer into format */ + size_t arg_posn = 0; /* number of regular arguments consumed */ + size_t d_allocated; /* allocated elements of d->dir */ + size_t a_allocated; /* allocated elements of a->arg */ + size_t max_width_length = 0; + size_t max_precision_length = 0; d->count = 0; d_allocated = 1; - d->dir = malloc (d_allocated * sizeof (char_directive)); + d->dir = malloc (d_allocated * sizeof (DIRECTIVE)); if (d->dir == NULL) /* Out of memory. */ return -1; @@ -62,16 +82,22 @@ printf_parse (const char *format, char_directives *d, arguments *a) #define REGISTER_ARG(_index_,_type_) \ { \ - unsigned int n = (_index_); \ + size_t n = (_index_); \ if (n >= a_allocated) \ { \ + size_t memory_size; \ argument *memory; \ - a_allocated = 2 * a_allocated; \ + \ + a_allocated *= 2; \ if (a_allocated <= n) \ a_allocated = n + 1; \ + if (SIZE_MAX / sizeof (argument) < a_allocated) \ + /* Overflow, would lead to out of memory. */ \ + goto error; \ + memory_size = a_allocated * sizeof (argument); \ memory = (a->arg \ - ? realloc (a->arg, a_allocated * sizeof (argument)) \ - : malloc (a_allocated * sizeof (argument))); \ + ? realloc (a->arg, memory_size) \ + : malloc (memory_size)); \ if (memory == NULL) \ /* Out of memory. */ \ goto error; \ @@ -88,36 +114,40 @@ printf_parse (const char *format, char_directives *d, arguments *a) while (*cp != '\0') { - char c = *cp++; + CHAR_T c = *cp++; if (c == '%') { - int arg_index = -1; - char_directive *dp = &d->dir[d->count];/* pointer to next directive */ + size_t arg_index = ARG_NONE; + DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */ /* Initialize the next directive. */ dp->dir_start = cp - 1; dp->flags = 0; dp->width_start = NULL; dp->width_end = NULL; - dp->width_arg_index = -1; + dp->width_arg_index = ARG_NONE; dp->precision_start = NULL; dp->precision_end = NULL; - dp->precision_arg_index = -1; - dp->arg_index = -1; + dp->precision_arg_index = ARG_NONE; + dp->arg_index = ARG_NONE; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { - const char *np; + const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { - unsigned int n = 0; + size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) - n = 10 * n + (*np - '0'); + if (n < SIZE_MAX / 10) + n = 10 * n + (*np - '0'); + else + /* n too large for memory. */ + goto error; if (n == 0) /* Positional argument 0. */ goto error; @@ -175,16 +205,20 @@ printf_parse (const char *format, char_directives *d, arguments *a) /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { - const char *np; + const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { - unsigned int n = 0; + size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) - n = 10 * n + (*np - '0'); + if (n < SIZE_MAX / 10) + n = 10 * n + (*np - '0'); + else + /* n too large for memory. */ + goto error; if (n == 0) /* Positional argument 0. */ goto error; @@ -192,13 +226,18 @@ printf_parse (const char *format, char_directives *d, arguments *a) cp = np + 1; } } - if (dp->width_arg_index < 0) - dp->width_arg_index = arg_posn++; + if (dp->width_arg_index == ARG_NONE) + { + dp->width_arg_index = arg_posn++; + if (dp->width_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } REGISTER_ARG (dp->width_arg_index, TYPE_INT); } else if (*cp >= '0' && *cp <= '9') { - unsigned int width_length; + size_t width_length; dp->width_start = cp; for (; *cp >= '0' && *cp <= '9'; cp++) @@ -224,16 +263,20 @@ printf_parse (const char *format, char_directives *d, arguments *a) /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { - const char *np; + const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { - unsigned int n = 0; + size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) - n = 10 * n + (*np - '0'); + if (n < SIZE_MAX / 10) + n = 10 * n + (*np - '0'); + else + /* n too large for memory. */ + goto error; if (n == 0) /* Positional argument 0. */ goto error; @@ -241,13 +284,18 @@ printf_parse (const char *format, char_directives *d, arguments *a) cp = np + 1; } } - if (dp->precision_arg_index < 0) - dp->precision_arg_index = arg_posn++; + if (dp->precision_arg_index == ARG_NONE) + { + dp->precision_arg_index = arg_posn++; + if (dp->precision_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } REGISTER_ARG (dp->precision_arg_index, TYPE_INT); } else { - unsigned int precision_length; + size_t precision_length; dp->precision_start = cp - 1; for (; *cp >= '0' && *cp <= '9'; cp++) @@ -439,8 +487,13 @@ printf_parse (const char *format, char_directives *d, arguments *a) if (type != TYPE_NONE) { dp->arg_index = arg_index; - if (dp->arg_index < 0) - dp->arg_index = arg_posn++; + if (dp->arg_index == ARG_NONE) + { + dp->arg_index = arg_posn++; + if (dp->arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } REGISTER_ARG (dp->arg_index, type); } dp->conversion = c; @@ -450,10 +503,13 @@ printf_parse (const char *format, char_directives *d, arguments *a) d->count++; if (d->count >= d_allocated) { - char_directive *memory; + DIRECTIVE *memory; - d_allocated = 2 * d_allocated; - memory = realloc (d->dir, d_allocated * sizeof (char_directive)); + if (SIZE_MAX / (2 * sizeof (DIRECTIVE)) < d_allocated) + /* Overflow, would lead to out of memory. */ + goto error; + d_allocated *= 2; + memory = realloc (d->dir, d_allocated * sizeof (DIRECTIVE)); if (memory == NULL) /* Out of memory. */ goto error; @@ -474,3 +530,8 @@ error: free (d->dir); return -1; } + +#undef DIRECTIVES +#undef DIRECTIVE +#undef CHAR_T +#undef PRINTF_PARSE diff --git a/lib/printf-parse.h b/lib/printf-parse.h index 54b429f12..f3f458660 100644 --- a/lib/printf-parse.h +++ b/lib/printf-parse.h @@ -1,5 +1,5 @@ /* Parse printf format string. - Copyright (C) 1999, 2002 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,6 +29,9 @@ #define FLAG_ALT 16 /* # flag */ #define FLAG_ZERO 32 +/* arg_index value indicating that no argument is consumed. */ +#define ARG_NONE (~(size_t)0) + /* A parsed directive. */ typedef struct { @@ -37,22 +40,22 @@ typedef struct int flags; const char* width_start; const char* width_end; - int width_arg_index; + size_t width_arg_index; const char* precision_start; const char* precision_end; - int precision_arg_index; + size_t precision_arg_index; char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ - int arg_index; + size_t arg_index; } char_directive; /* A parsed format string. */ typedef struct { - unsigned int count; + size_t count; char_directive *dir; - unsigned int max_width_length; - unsigned int max_precision_length; + size_t max_width_length; + size_t max_precision_length; } char_directives; diff --git a/lib/settime.c b/lib/settime.c index 277c80583..e989a6db6 100644 --- a/lib/settime.c +++ b/lib/settime.c @@ -1,5 +1,5 @@ /* settime -- set the system clock - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,21 +23,52 @@ #include "timespec.h" +#if HAVE_UNISTD_H +# include <unistd.h> +#endif + +#include <errno.h> + +/* Some systems don't have ENOSYS. */ +#ifndef ENOSYS +# ifdef ENOTSUP +# define ENOSYS ENOTSUP +# else +/* Some systems don't have ENOTSUP either. */ +# define ENOSYS EINVAL +# endif +#endif + /* Set the system time. */ int settime (struct timespec const *ts) { #if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME - if (clock_settime (CLOCK_REALTIME, ts) == 0) - return 0; + { + int r = clock_settime (CLOCK_REALTIME, ts); + if (r == 0 || errno == EPERM) + return r; + } #endif +#if HAVE_SETTIMEOFDAY { struct timeval tv; + int r; tv.tv_sec = ts->tv_sec; tv.tv_usec = ts->tv_nsec / 1000; - return settimeofday (&tv, 0); + r = settimeofday (&tv, 0); + if (r == 0 || errno == EPERM) + return r; } +#endif + +#if HAVE_STIME + return stime (&ts->tv_sec); +#endif + + errno = ENOSYS; + return -1; } diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index f416c1240..e24e4cd86 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -1,5 +1,5 @@ /* vsprintf with automatic memory allocation. - Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,10 +25,16 @@ #ifdef HAVE_CONFIG_H # include <config.h> #endif -#include <alloca.h> +#ifndef IN_LIBINTL +# include <alloca.h> +#endif /* Specification. */ -#include "vasnprintf.h" +#if WIDE_CHAR_VERSION +# include "vasnwprintf.h" +#else +# include "vasnprintf.h" +#endif #include <stdio.h> /* snprintf(), sprintf() */ #include <stdlib.h> /* abort(), malloc(), realloc(), free() */ @@ -36,15 +42,14 @@ #include <errno.h> /* errno */ #include <limits.h> /* CHAR_BIT */ #include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */ -#include "printf-parse.h" - -/* For those losing systems which don't have 'alloca' we have to add - some additional code emulating it. */ -#ifdef HAVE_ALLOCA -# define freea(p) /* nothing */ +#if WIDE_CHAR_VERSION +# include "wprintf-parse.h" #else -# define alloca(n) malloc (n) -# define freea(p) free (p) +# include "printf-parse.h" +#endif + +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) #endif #ifdef HAVE_WCHAR_T @@ -52,7 +57,11 @@ # define local_wcslen wcslen # else /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid - a dependency towards this library, here is a local substitute. */ + a dependency towards this library, here is a local substitute. + Define this substitute only once, even if this file is included + twice in the same compilation unit. */ +# ifndef local_wcslen_defined +# define local_wcslen_defined 1 static size_t local_wcslen (const wchar_t *s) { @@ -62,16 +71,48 @@ local_wcslen (const wchar_t *s) ; return ptr - s; } +# endif # endif #endif -char * -vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) +#if WIDE_CHAR_VERSION +# define VASNPRINTF vasnwprintf +# define CHAR_T wchar_t +# define DIRECTIVE wchar_t_directive +# define DIRECTIVES wchar_t_directives +# define PRINTF_PARSE wprintf_parse +# define USE_SNPRINTF 1 +# if HAVE_DECL__SNWPRINTF + /* On Windows, the function swprintf() has a different signature than + on Unix; we use the _snwprintf() function instead. */ +# define SNPRINTF _snwprintf +# else + /* Unix. */ +# define SNPRINTF swprintf +# endif +#else +# define VASNPRINTF vasnprintf +# define CHAR_T char +# define DIRECTIVE char_directive +# define DIRECTIVES char_directives +# define PRINTF_PARSE printf_parse +# define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) +# if HAVE_DECL__SNPRINTF + /* Windows. */ +# define SNPRINTF _snprintf +# else + /* Unix. */ +# define SNPRINTF snprintf +# endif +#endif + +CHAR_T * +VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args) { - char_directives d; + DIRECTIVES d; arguments a; - if (printf_parse (format, &d, &a) < 0) + if (PRINTF_PARSE (format, &d, &a) < 0) { errno = EINVAL; return NULL; @@ -90,16 +131,37 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) } { - char *buf = - (char *) alloca (7 + d.max_width_length + d.max_precision_length + 6); - const char *cp; - unsigned int i; - char_directive *dp; + size_t buf_neededlength; + CHAR_T *buf; + CHAR_T *buf_malloced; + const CHAR_T *cp; + size_t i; + DIRECTIVE *dp; /* Output string accumulator. */ - char *result; + CHAR_T *result; size_t allocated; size_t length; + /* Allocate a small buffer that will hold a directive passed to + sprintf or snprintf. */ + buf_neededlength = 7 + d.max_width_length + d.max_precision_length + 6; +#if HAVE_ALLOCA + if (buf_neededlength < 4000 / sizeof (CHAR_T)) + { + buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T)); + buf_malloced = NULL; + } + else +#endif + { + if (SIZE_MAX / sizeof (CHAR_T) < buf_neededlength) + goto out_of_memory_1; + buf = (CHAR_T *) malloc (buf_neededlength * sizeof (CHAR_T)); + if (buf == NULL) + goto out_of_memory_1; + buf_malloced = buf; + } + if (resultbuf != NULL) { result = resultbuf; @@ -115,32 +177,35 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ -#define ENSURE_ALLOCATION(needed) \ - if ((needed) > allocated) \ - { \ - char *memory; \ - \ - allocated = (allocated > 0 ? 2 * allocated : 12); \ - if ((needed) > allocated) \ - allocated = (needed); \ - if (result == resultbuf || result == NULL) \ - memory = (char *) malloc (allocated); \ - else \ - memory = (char *) realloc (result, allocated); \ - \ - if (memory == NULL) \ - { \ - if (!(result == resultbuf || result == NULL)) \ - free (result); \ - freea (buf); \ - CLEANUP (); \ - errno = ENOMEM; \ - return NULL; \ - } \ - if (result == resultbuf && length > 0) \ - memcpy (memory, result, length); \ - result = memory; \ - } + /* Ensures that allocated >= length + extra. Aborts through a jump to + out_of_memory if size is too big. */ +#define ENSURE_ALLOCATION(extra) \ + { \ + size_t needed = length + (extra); \ + if (needed < length) \ + goto out_of_memory; \ + if (needed > allocated) \ + { \ + size_t memory_size; \ + CHAR_T *memory; \ + \ + allocated = (allocated > 0 ? 2 * allocated : 12); \ + if (needed > allocated) \ + allocated = needed; \ + if (SIZE_MAX / sizeof (CHAR_T) < allocated) \ + goto out_of_memory; \ + memory_size = allocated * sizeof (CHAR_T); \ + if (result == resultbuf || result == NULL) \ + memory = (CHAR_T *) malloc (memory_size); \ + else \ + memory = (CHAR_T *) realloc (result, memory_size); \ + if (memory == NULL) \ + goto out_of_memory; \ + if (result == resultbuf && length > 0) \ + memcpy (memory, result, length * sizeof (CHAR_T)); \ + result = memory; \ + } \ + } for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) { @@ -148,8 +213,8 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) { size_t n = dp->dir_start - cp; - ENSURE_ALLOCATION (length + n); - memcpy (result + length, cp, n); + ENSURE_ALLOCATION (n); + memcpy (result + length, cp, n * sizeof (CHAR_T)); length += n; } if (i == d.count) @@ -158,15 +223,15 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) /* Execute a single directive. */ if (dp->conversion == '%') { - if (!(dp->arg_index < 0)) + if (!(dp->arg_index == ARG_NONE)) abort (); - ENSURE_ALLOCATION (length + 1); + ENSURE_ALLOCATION (1); result[length] = '%'; length += 1; } else { - if (!(dp->arg_index >= 0)) + if (!(dp->arg_index != ARG_NONE)) abort (); if (dp->conversion == 'n') @@ -197,38 +262,42 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) else { arg_type type = a.arg[dp->arg_index].type; - char *p; + CHAR_T *p; unsigned int prefix_count; int prefixes[2]; -#if !HAVE_SNPRINTF - unsigned int tmp_length; - char tmpbuf[700]; - char *tmp; +#if !USE_SNPRINTF + size_t tmp_length; + CHAR_T tmpbuf[700]; + CHAR_T *tmp; /* Allocate a temporary buffer of sufficient size for calling sprintf. */ { - unsigned int width; - unsigned int precision; + size_t width; + size_t precision; width = 0; if (dp->width_start != dp->width_end) { - if (dp->width_arg_index >= 0) + if (dp->width_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->width_arg_index].a.a_int; - width = (arg < 0 ? -arg : arg); + width = (arg < 0 ? (unsigned int) (-arg) : arg); } else { - const char *digitp = dp->width_start; + const CHAR_T *digitp = dp->width_start; do - width = width * 10 + (*digitp++ - '0'); + { + if (SIZE_MAX / 10 <= width) + goto out_of_memory; + width = width * 10 + (*digitp++ - '0'); + } while (digitp != dp->width_end); } } @@ -236,7 +305,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) precision = 6; if (dp->precision_start != dp->precision_end) { - if (dp->precision_arg_index >= 0) + if (dp->precision_arg_index != ARG_NONE) { int arg; @@ -247,12 +316,16 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) } else { - const char *digitp = dp->precision_start + 1; + const CHAR_T *digitp = dp->precision_start + 1; precision = 0; - do - precision = precision * 10 + (*digitp++ - '0'); - while (digitp != dp->precision_end); + while (digitp != dp->precision_end) + { + size_t p1 = 10 * precision + (*digitp++ - '0'); + precision = ((SIZE_MAX / 10 < precision + || p1 < precision) + ? SIZE_MAX : p1); + } } } @@ -352,7 +425,6 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ - + precision + 10; /* sign, decimal point etc. */ else # endif @@ -362,19 +434,23 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ - + precision + 10; /* sign, decimal point etc. */ + tmp_length += precision; + if (tmp_length < precision) + goto out_of_memory; break; case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': tmp_length = - precision - + 12; /* sign, decimal point, exponent etc. */ + 12; /* sign, decimal point, exponent etc. */ + tmp_length += precision; + if (tmp_length < precision) + goto out_of_memory; break; case 'c': -# ifdef HAVE_WINT_T +# if defined HAVE_WINT_T && !WIDE_CHAR_VERSION if (type == TYPE_WIDE_CHAR) tmp_length = MB_CUR_MAX; else @@ -385,9 +461,16 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) case 's': # ifdef HAVE_WCHAR_T if (type == TYPE_WIDE_STRING) - tmp_length = - local_wcslen (a.arg[dp->arg_index].a.a_wide_string) - * MB_CUR_MAX; + { + tmp_length = + local_wcslen (a.arg[dp->arg_index].a.a_wide_string); + +# if !WIDE_CHAR_VERSION + if (SIZE_MAX / MB_CUR_MAX < tmp_length) + goto out_of_memory; + tmp_length *= MB_CUR_MAX; +# endif + } else # endif tmp_length = strlen (a.arg[dp->arg_index].a.a_string); @@ -410,23 +493,21 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) tmp_length = width; tmp_length++; /* account for trailing NUL */ + if (!tmp_length) + goto out_of_memory; } - if (tmp_length <= sizeof (tmpbuf)) + if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T)) tmp = tmpbuf; else { - tmp = (char *) malloc (tmp_length); + if (SIZE_MAX / sizeof (CHAR_T) < tmp_length) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (CHAR_T *) malloc (tmp_length * sizeof (CHAR_T)); if (tmp == NULL) - { - /* Out of memory. */ - if (!(result == resultbuf || result == NULL)) - free (result); - freea (buf); - CLEANUP (); - errno = ENOMEM; - return NULL; - } + /* Out of memory. */ + goto out_of_memory; } #endif @@ -449,13 +530,13 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) if (dp->width_start != dp->width_end) { size_t n = dp->width_end - dp->width_start; - memcpy (p, dp->width_start, n); + memcpy (p, dp->width_start, n * sizeof (CHAR_T)); p += n; } if (dp->precision_start != dp->precision_end) { size_t n = dp->precision_end - dp->precision_start; - memcpy (p, dp->precision_start, n); + memcpy (p, dp->precision_start, n * sizeof (CHAR_T)); p += n; } @@ -486,7 +567,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) break; } *p = dp->conversion; -#if HAVE_SNPRINTF +#if USE_SNPRINTF p[1] = '%'; p[2] = 'n'; p[3] = '\0'; @@ -496,23 +577,23 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) /* Construct the arguments for calling snprintf or sprintf. */ prefix_count = 0; - if (dp->width_arg_index >= 0) + if (dp->width_arg_index != ARG_NONE) { if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; } - if (dp->precision_arg_index >= 0) + if (dp->precision_arg_index != ARG_NONE) { if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; } -#if HAVE_SNPRINTF +#if USE_SNPRINTF /* Prepare checking whether snprintf returns the count via %n. */ - ENSURE_ALLOCATION (length + 1); + ENSURE_ALLOCATION (1); result[length] = '\0'; #endif @@ -526,20 +607,20 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) count = -1; retcount = 0; -#if HAVE_SNPRINTF +#if USE_SNPRINTF # define SNPRINTF_BUF(arg) \ switch (prefix_count) \ { \ case 0: \ - retcount = snprintf (result + length, maxlen, buf, \ + retcount = SNPRINTF (result + length, maxlen, buf, \ arg, &count); \ break; \ case 1: \ - retcount = snprintf (result + length, maxlen, buf, \ + retcount = SNPRINTF (result + length, maxlen, buf, \ prefixes[0], arg, &count); \ break; \ case 2: \ - retcount = snprintf (result + length, maxlen, buf, \ + retcount = SNPRINTF (result + length, maxlen, buf, \ prefixes[0], prefixes[1], arg, \ &count); \ break; \ @@ -681,7 +762,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) abort (); } -#if HAVE_SNPRINTF +#if USE_SNPRINTF /* Portability: Not all implementations of snprintf() are ISO C 99 compliant. Determine the number of bytes that snprintf() has produced or would have @@ -707,23 +788,24 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) p[1] = '\0'; continue; } - else if (retcount < 0) + else { - /* The system's snprintf is sorely deficient: - it doesn't recognize the `%n' directive, and it - returns -1 (rather than the length that would - have been required) when the buffer is too small. - This is the case at with least HPUX 10.20. - Double the memory allocation. */ - size_t n = allocated; - if (n < 2 * allocated) + /* Look at the snprintf() return value. */ + if (retcount < 0) { - n = 2 * allocated; - ENSURE_ALLOCATION (n); + /* HP-UX 10.20 snprintf() is doubly deficient: + It doesn't understand the '%n' directive, + *and* it returns -1 (rather than the length + that would have been required) when the + buffer is too small. */ + size_t bigger_need = + (allocated > 12 ? allocated : 12); + ENSURE_ALLOCATION (bigger_need); continue; } + else + count = retcount; } - count = retcount; } #endif @@ -732,13 +814,14 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) { if (!(result == resultbuf || result == NULL)) free (result); - freea (buf); + if (buf_malloced != NULL) + free (buf_malloced); CLEANUP (); errno = EINVAL; return NULL; } -#if !HAVE_SNPRINTF +#if !USE_SNPRINTF if (count >= tmp_length) /* tmp_length was incorrectly calculated - fix the code above! */ @@ -751,22 +834,18 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) /* Need at least count bytes. But allocate proportionally, to avoid looping eternally if snprintf() reports a too small count. */ - size_t n = length + count; - - if (n < 2 * allocated) - n = 2 * allocated; - - ENSURE_ALLOCATION (n); -#if HAVE_SNPRINTF + ENSURE_ALLOCATION (count < allocated + ? allocated : count); +#if USE_SNPRINTF continue; #endif } -#if HAVE_SNPRINTF +#if USE_SNPRINTF /* The snprintf() result did fit. */ #else /* Append the sprintf() result. */ - memcpy (result + length, tmp, count); + memcpy (result + length, tmp, count * sizeof (CHAR_T)); if (tmp != tmpbuf) free (tmp); #endif @@ -779,22 +858,41 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) } /* Add the final NUL. */ - ENSURE_ALLOCATION (length + 1); + ENSURE_ALLOCATION (1); result[length] = '\0'; if (result != resultbuf && length + 1 < allocated) { /* Shrink the allocated memory if possible. */ - char *memory; + CHAR_T *memory; - memory = (char *) realloc (result, length + 1); + memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T)); if (memory != NULL) result = memory; } - freea (buf); + if (buf_malloced != NULL) + free (buf_malloced); CLEANUP (); *lengthp = length; return result; + + out_of_memory: + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + out_of_memory_1: + CLEANUP (); + errno = ENOMEM; + return NULL; } } + +#undef SNPRINTF +#undef USE_SNPRINTF +#undef PRINTF_PARSE +#undef DIRECTIVES +#undef DIRECTIVE +#undef CHAR_T +#undef VASNPRINTF diff --git a/lib/xalloc.h b/lib/xalloc.h index 4b6585811..5985892c9 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -1,7 +1,7 @@ /* xalloc.h -- malloc with out-of-memory checking Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2003 Free Software Foundation, Inc. + 1999, 2000, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,6 +22,12 @@ # include <stddef.h> + +# ifdef __cplusplus +extern "C" { +# endif + + # ifndef __attribute__ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ # define __attribute__(x) @@ -32,6 +38,7 @@ # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) # endif + /* If this pointer is non-zero, run the specified function upon each allocation failure. It is initialized to zero. */ extern void (*xalloc_fail_func) (void); @@ -84,4 +91,10 @@ char *xstrdup (const char *str); # define XREALLOC(p, type, n) xnrealloc (p, n, sizeof (type)) # define XFREE(p) free (p) + +# ifdef __cplusplus +} +# endif + + #endif /* !XALLOC_H_ */ diff --git a/m4/ChangeLog b/m4/ChangeLog index d1977ab45..47ba2e09c 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,24 @@ +2004-08-05 Paul Eggert <eggert@cs.ucla.edu> + + Merge from gnulib. + + * alloca.m4 (gl_FUNC_ALLOCA): Define HAVE_ALLOCA_H always, + for backward compatibility with older code. We need our own + alloca.h if _AIX is defined. Define HAVE_ALLOCA if we discover + it under some other name, and our alloca.h will define it. + * backupfile.m4, calloc.m4, strtoimax.m4, strtoumax.m4: + Bump serial number only. + * dirfd.m4, intmax_t.m4, inttypes_h.m4, mbrtowc.m4, stdint_h.m4, + uintmax_t.m4: Finish renaming jm_ to gl_. + * dos.m4 (gl_AC_DOS): Check for _WIN32, __WIN32__, and __MSDOS__. + * host-os.m4: s/KNetBSD/kNetBSD/g and s/KFreeBSD/kFreeBSD/g. + * prereq.m4 (gl_PREREQ): Add gl_GETTIME, AC_FUNC_CALLOC. + * gettime.m4: New file. + * settime.m4: Require gl_TIMESPEC; check for settimeofday, stime. + * unlocked-io.m4: Remove -*- autoconf -*-. + * xalloc.m4: No longer require AC_FUNC_CALLOC, AC_FUNC_MALLOC, + AC_FUNC_REALLOC. + 2004-08-04 Paul Eggert <eggert@cs.ucla.edu> OpenBSD porting fixes. diff --git a/m4/alloca.m4 b/m4/alloca.m4 index 793cf0ac0..6fcb205e9 100644 --- a/m4/alloca.m4 +++ b/m4/alloca.m4 @@ -1,5 +1,5 @@ -# alloca.m4 serial 3 -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. +# alloca.m4 serial 4 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -18,15 +18,25 @@ AC_DEFUN([gl_FUNC_ALLOCA], fi # Define an additional variable used in the Makefile substitution. - - AC_EGREP_CPP([Need own alloca], [ -#if defined __GNUC__ || defined _MSC_VER || !HAVE_ALLOCA_H - Need own alloca + if test $ac_cv_working_alloca_h = yes; then + AC_EGREP_CPP([Need own alloca], [ +#if defined __GNUC__ || defined _AIX || defined _MSC_VER + Need own alloca #endif - ], - ALLOCA_H=alloca.h, - ALLOCA_H=) + ], + [AC_DEFINE(HAVE_ALLOCA, 1, + [Define to 1 if you have `alloca' after including <alloca.h>, + a header that may be supplied by this distribution.]) + ALLOCA_H=alloca.h], + [ALLOCA_H=]) + else + ALLOCA_H=alloca.h + fi AC_SUBST([ALLOCA_H]) + + AC_DEFINE(HAVE_ALLOCA_H, 1, + [Define HAVE_ALLOCA_H for backward compatibility with older code + that includes <alloca.h> only if HAVE_ALLOCA_H is defined.]) ]) # Prerequisites of lib/alloca.c. diff --git a/m4/backupfile.m4 b/m4/backupfile.m4 index cc35f512e..0793f1f00 100644 --- a/m4/backupfile.m4 +++ b/m4/backupfile.m4 @@ -1,4 +1,4 @@ -# backupfile.m4 serial 4 +# backupfile.m4 serial 5 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General diff --git a/m4/calloc.m4 b/m4/calloc.m4 index 88861f9d4..5d03ed271 100644 --- a/m4/calloc.m4 +++ b/m4/calloc.m4 @@ -1,6 +1,6 @@ -#serial 1 +#serial 2 -# Determine whether calloc (N, S) works when N*S is zero. +# Determine whether calloc (N, S) returns non-NULL when N*S is zero. # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc # and arrange to use a calloc wrapper function that does work in that case. diff --git a/m4/dirfd.m4 b/m4/dirfd.m4 index 5f1a9a81b..f84d63fac 100644 --- a/m4/dirfd.m4 +++ b/m4/dirfd.m4 @@ -1,4 +1,4 @@ -#serial 7 +#serial 8 dnl Find out how to get the file descriptor associated with an open DIR*. dnl From Jim Meyering @@ -30,17 +30,17 @@ AC_DEFUN([gl_FUNC_DIRFD], AC_CHECK_DECLS([dirfd], , , $dirfd_headers) AC_CACHE_CHECK([whether dirfd is a macro], - jm_cv_func_dirfd_macro, + gl_cv_func_dirfd_macro, [AC_EGREP_CPP([dirent_header_defines_dirfd], [$dirfd_headers #ifdef dirfd dirent_header_defines_dirfd #endif], - jm_cv_func_dirfd_macro=yes, - jm_cv_func_dirfd_macro=no)]) + gl_cv_func_dirfd_macro=yes, + gl_cv_func_dirfd_macro=no)]) # Use the replacement only if we have no function, macro, # or declaration with that name. - if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$jm_cv_func_dirfd_macro \ + if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$gl_cv_func_dirfd_macro \ = no,no,no; then AC_REPLACE_FUNCS([dirfd]) AC_CACHE_CHECK( @@ -1,8 +1,25 @@ -#serial 7 +#serial 8 # Define some macros required for proper operation of code in lib/*.c # on MSDOS/Windows systems. +# Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 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., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + # From Jim Meyering. AC_DEFUN([gl_AC_DOS], @@ -10,7 +27,7 @@ AC_DEFUN([gl_AC_DOS], AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], [ AC_TRY_COMPILE([], - [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ + [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ neither MSDOS nor Windows #endif], [ac_cv_win_or_dos=yes], diff --git a/m4/host-os.m4 b/m4/host-os.m4 index 52905f4d9..e8fe07214 100644 --- a/m4/host-os.m4 +++ b/m4/host-os.m4 @@ -1,5 +1,23 @@ #serial 4 +# Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +# Written by Paul Eggert. + dnl From Paul Eggert. # Define HOST_OPERATING_SYSTEM to a name for the host operating system. @@ -32,8 +50,8 @@ AC_DEFUN([gl_HOST_OS], nonstopux*) os='NonStop-UX';; netbsd*-gnu*) os='GNU/NetBSD';; # NetBSD kernel+libc, GNU userland netbsd*) os='NetBSD';; - knetbsd*-gnu) os='GNU/KNetBSD';; # NetBSD kernel, GNU libc+userland - kfreebsd*-gnu) os='GNU/KFreeBSD';; # FreeBSD kernel, GNU libc+userland + knetbsd*-gnu) os='GNU/kNetBSD';; # NetBSD kernel, GNU libc+userland + kfreebsd*-gnu) os='GNU/kFreeBSD';; # FreeBSD kernel, GNU libc+userland msdosdjgpp*) os='DJGPP';; mpeix*) os='MPE/iX';; mint*) os='MiNT';; diff --git a/m4/intmax_t.m4 b/m4/intmax_t.m4 index 1dc61927d..859db1495 100644 --- a/m4/intmax_t.m4 +++ b/m4/intmax_t.m4 @@ -1,4 +1,4 @@ -# intmax_t.m4 serial 3 +# intmax_t.m4 serial 4 dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -19,7 +19,7 @@ AC_DEFUN([gl_AC_TYPE_INTMAX_T], dnl only if it defines 'uintmax_t'. AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - if test $jm_ac_cv_header_inttypes_h = no && test $jm_ac_cv_header_stdint_h = no; then + if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) test $ac_cv_type_long_long = yes \ && ac_type='long long' \ diff --git a/m4/inttypes_h.m4 b/m4/inttypes_h.m4 index 954a86c27..79bba8763 100644 --- a/m4/inttypes_h.m4 +++ b/m4/inttypes_h.m4 @@ -13,14 +13,14 @@ dnl From Paul Eggert. AC_DEFUN([gl_AC_HEADER_INTTYPES_H], [ - AC_CACHE_CHECK([for inttypes.h], jm_ac_cv_header_inttypes_h, + AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, [AC_TRY_COMPILE( [#include <sys/types.h> #include <inttypes.h>], [uintmax_t i = (uintmax_t) -1;], - jm_ac_cv_header_inttypes_h=yes, - jm_ac_cv_header_inttypes_h=no)]) - if test $jm_ac_cv_header_inttypes_h = yes; then + gl_cv_header_inttypes_h=yes, + gl_cv_header_inttypes_h=no)]) + if test $gl_cv_header_inttypes_h = yes; then AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1, [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and declares uintmax_t. ]) diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4 index ac08c1cc9..3d8768ecb 100644 --- a/m4/mbrtowc.m4 +++ b/m4/mbrtowc.m4 @@ -1,4 +1,4 @@ -# mbrtowc.m4 serial 6 +# mbrtowc.m4 serial 7 dnl Copyright (C) 2001-2002, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -14,13 +14,13 @@ dnl AC_FUNC_MBRTOWC, when autoconf 2.57 can be assumed everywhere. AC_DEFUN([gl_FUNC_MBRTOWC], [ AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], - jm_cv_func_mbrtowc, + gl_cv_func_mbrtowc, [AC_TRY_LINK( [#include <wchar.h>], [mbstate_t state; return ! (sizeof state && mbrtowc);], - jm_cv_func_mbrtowc=yes, - jm_cv_func_mbrtowc=no)]) - if test $jm_cv_func_mbrtowc = yes; then + gl_cv_func_mbrtowc=yes, + gl_cv_func_mbrtowc=no)]) + if test $gl_cv_func_mbrtowc = yes; then AC_DEFINE(HAVE_MBRTOWC, 1, [Define to 1 if mbrtowc and mbstate_t are properly declared.]) fi diff --git a/m4/prereq.m4 b/m4/prereq.m4 index 787786ff4..79b7586f7 100644 --- a/m4/prereq.m4 +++ b/m4/prereq.m4 @@ -1,4 +1,4 @@ -#serial 43 +#serial 44 dnl We use gl_ for non Autoconf macros. m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl @@ -70,6 +70,7 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_GETNDELIM2]) AC_REQUIRE([gl_GETOPT]) AC_REQUIRE([gl_GETPAGESIZE]) + AC_REQUIRE([gl_GETTIME]) AC_REQUIRE([gl_GETUGROUPS]) AC_REQUIRE([gl_HARD_LOCALE]) AC_REQUIRE([gl_HASH]) @@ -115,6 +116,7 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_XSTRTOD]) AC_REQUIRE([gl_XSTRTOL]) AC_REQUIRE([gl_YESNO]) + AC_REQUIRE([AC_FUNC_CALLOC]) AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO]) AC_REQUIRE([gl_FUNC_GNU_STRFTIME]) AC_REQUIRE([gl_FUNC_LSTAT]) diff --git a/m4/settime.m4 b/m4/settime.m4 index 3751af564..89c030cd0 100644 --- a/m4/settime.m4 +++ b/m4/settime.m4 @@ -1,5 +1,5 @@ -# settime.m4 serial 1 -dnl Copyright (C) 2002 Free Software Foundation, Inc. +# settime.m4 serial 2 +dnl Copyright (C) 2002, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -9,6 +9,7 @@ dnl the same distribution terms as the rest of that program. AC_DEFUN([gl_SETTIME], [ dnl Prerequisites of lib/settime.c. - # Need clock_settime. AC_REQUIRE([gl_CLOCK_TIME]) + AC_REQUIRE([gl_TIMESPEC]) + AC_CHECK_FUNCS_ONCE(settimeofday stime) ]) diff --git a/m4/stdint_h.m4 b/m4/stdint_h.m4 index e48e210a0..063c4344e 100644 --- a/m4/stdint_h.m4 +++ b/m4/stdint_h.m4 @@ -1,4 +1,4 @@ -# stdint_h.m4 serial 4 +# stdint_h.m4 serial 5 dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -13,14 +13,14 @@ dnl From Paul Eggert. AC_DEFUN([gl_AC_HEADER_STDINT_H], [ - AC_CACHE_CHECK([for stdint.h], jm_ac_cv_header_stdint_h, + AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, [AC_TRY_COMPILE( [#include <sys/types.h> #include <stdint.h>], [uintmax_t i = (uintmax_t) -1;], - jm_ac_cv_header_stdint_h=yes, - jm_ac_cv_header_stdint_h=no)]) - if test $jm_ac_cv_header_stdint_h = yes; then + gl_cv_header_stdint_h=yes, + gl_cv_header_stdint_h=no)]) + if test $gl_cv_header_stdint_h = yes; then AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1, [Define if <stdint.h> exists, doesn't clash with <sys/types.h>, and declares uintmax_t. ]) diff --git a/m4/strtoimax.m4 b/m4/strtoimax.m4 index a9607f67e..84e57a876 100644 --- a/m4/strtoimax.m4 +++ b/m4/strtoimax.m4 @@ -1,5 +1,5 @@ -# strtoimax.m4 serial 3 -dnl Copyright (C) 2002-2004 Free Software Foundation, Inc. +# strtoimax.m4 serial 4 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program diff --git a/m4/strtoumax.m4 b/m4/strtoumax.m4 index f63ed5e97..84d42ff16 100644 --- a/m4/strtoumax.m4 +++ b/m4/strtoumax.m4 @@ -1,5 +1,5 @@ -# strtoumax.m4 serial 3 -dnl Copyright (C) 2002-2004 Free Software Foundation, Inc. +# strtoumax.m4 serial 4 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program diff --git a/m4/uintmax_t.m4 b/m4/uintmax_t.m4 index 41e0edf80..a2bc218ce 100644 --- a/m4/uintmax_t.m4 +++ b/m4/uintmax_t.m4 @@ -1,4 +1,4 @@ -# uintmax_t.m4 serial 8 +# uintmax_t.m4 serial 9 dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -17,7 +17,7 @@ AC_DEFUN([gl_AC_TYPE_UINTMAX_T], [ AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - if test $jm_ac_cv_header_inttypes_h = no && test $jm_ac_cv_header_stdint_h = no; then + if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG]) test $ac_cv_type_unsigned_long_long = yes \ && ac_type='unsigned long long' \ diff --git a/m4/unlocked-io.m4 b/m4/unlocked-io.m4 index ab16e0ada..cd1c5f4ef 100644 --- a/m4/unlocked-io.m4 +++ b/m4/unlocked-io.m4 @@ -1,4 +1,4 @@ -#serial 9 -*- autoconf -*- +#serial 9 dnl From Jim Meyering. dnl diff --git a/m4/xalloc.m4 b/m4/xalloc.m4 index b2b9abaa1..4d9383509 100644 --- a/m4/xalloc.m4 +++ b/m4/xalloc.m4 @@ -21,9 +21,6 @@ AC_DEFUN([gl_PREREQ_XALLOC], [ # Prerequisites of lib/xmalloc.c. AC_DEFUN([gl_PREREQ_XMALLOC], [ AC_REQUIRE([AC_C_INLINE]) - AC_REQUIRE([AC_FUNC_CALLOC]) - AC_REQUIRE([AC_FUNC_MALLOC]) - AC_REQUIRE([AC_FUNC_REALLOC]) : ]) |