diff options
Diffstat (limited to 'lib/sh')
66 files changed, 2406 insertions, 731 deletions
diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in index bf95d19..80f6cc5 100644 --- a/lib/sh/Makefile.in +++ b/lib/sh/Makefile.in @@ -2,21 +2,20 @@ # Makefile for the Bash library # # -# Copyright (C) 1998-2005 Free Software Foundation, Inc. +# Copyright (C) 1998-2009 Free Software Foundation, Inc. -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# 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 USA. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. PACKAGE = @PACKAGE_NAME@ VERSION = @PACKAGE_VERSION@ @@ -40,6 +39,8 @@ INTL_BUILDDIR = ${LIBBUILD}/intl INTL_INC = @INTL_INC@ LIBINTL_H = @LIBINTL_H@ +datarootdir = @datarootdir@ + INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ @@ -85,11 +86,12 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \ vprint.c itos.c rename.c zread.c zwrite.c shtty.c \ inet_aton.c netconn.c netopen.c strpbrk.c timeval.c makepath.c \ pathcanon.c pathphys.c tmpfile.c stringlist.c stringvec.c spell.c \ - shquote.c strtrans.c strindex.c snprintf.c mailstat.c \ + shquote.c strtrans.c strcasestr.c snprintf.c mailstat.c \ fmtulong.c fmtullong.c fmtumax.c shmatch.c strnlen.c \ strtoll.c strtoull.c strtoimax.c strtoumax.c memset.c strstr.c \ - mktime.c strftime.c xstrchr.c zcatfd.c winsize.c eaccess.c \ - wcsdup.c + mktime.c strftime.c mbschr.c zcatfd.c zmapfd.c winsize.c eaccess.c \ + wcsdup.c fpurge.c zgetline.c mbscmp.c uconvert.c ufuncs.c \ + casemod.c fdprintf.c input_avail.c mbscasecmp.c fnxform.c # The header files for this library. HSOURCES = @@ -100,9 +102,10 @@ OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o strnlen.o \ itos.o zread.o zwrite.o shtty.o shmatch.o eaccess.o \ netconn.o netopen.o timeval.o makepath.o pathcanon.o \ pathphys.o tmpfile.o stringlist.o stringvec.o spell.o shquote.o \ - strtrans.o strindex.o snprintf.o mailstat.o fmtulong.o \ - fmtullong.o fmtumax.o xstrchr.o zcatfd.o winsize.o wcsdup.o \ - ${LIBOBJS} + strtrans.o snprintf.o mailstat.o fmtulong.o \ + fmtullong.o fmtumax.o zcatfd.o zmapfd.o winsize.o wcsdup.o \ + fpurge.o zgetline.o mbscmp.o uconvert.o ufuncs.o casemod.o \ + fdprintf.o input_avail.o mbscasecmp.o fnxform.o ${LIBOBJS} SUPPORT = Makefile @@ -133,19 +136,29 @@ mostlyclean: clean ${BUILD_DIR}/version.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile -( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} version.h ) +${BUILD_DIR}/pathnames.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile + -( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} pathnames.h ) + # rules for losing makes, like SunOS +casemod.o: casemod.c clktck.o: clktck.c clock.o: clock.c eaccess.o: eaccess.c +fdprintf.o: fdprintf.c fmtullong.o: fmtullong.c fmtulong.o: fmtulong.c fmtumax.o: fmtumax.c +fnxform.o: fnxform.c +fpurge.o: fpurge.c getcwd.o: getcwd.c getenv.o: getenv.c inet_aton.o: inet_aton.c +input_avail.o: input_avail.c itos.o: itos.c mailstat.o: mailstat.c makepath.o: makepath.c +mbscasecmp.o: mbscasecmp.c +mbscmp.o: mbscmp.c memset.o: memset.c mktime.o: mktime.c netconn.o: netconn.c @@ -162,7 +175,7 @@ spell.o: spell.c strcasecmp.o: strcasecmp.c strerror.o: strerror.c strftime.o: strftime.c -strindex.o: strindex.c +strcasestr.o: strcasestr.c stringlist.o: stringlist.c stringvec.o: stringvec.c strnlen.o: strnlen.c @@ -178,10 +191,14 @@ strtrans.o: strtrans.c times.o: times.c timeval.o: timeval.c tmpfile.o: tmpfile.c +uconvert.o: uconvert.c +ufuncs.o: ufuncs.c vprint.o: vprint.c wcsdup.o: wcsdup.c -xstrchr.o: xstrchr.c +mbschr.o: mbschr.c zcatfd.o: zcatfd.c +zmapfd.o: zmapfd.c +zgetline.o: zgetline.c zread.o: zread.c zwrite.o: zwrite.c @@ -193,18 +210,25 @@ strtoul.o: strtol.c strtoull.o: strtol.c # all files in the library depend on config.h +casemod.o: ${BUILD_DIR}/config.h clktck.o: ${BUILD_DIR}/config.h clock.o: ${BUILD_DIR}/config.h eaccess.o: ${BUILD_DIR}/config.h +fdprintf.o: ${BUILD_DIR}/config.h fmtullong.o: ${BUILD_DIR}/config.h fmtulong.o: ${BUILD_DIR}/config.h fmtumax.o: ${BUILD_DIR}/config.h +fnxform.o: ${BUILD_DIR}/config.h +fpurge.o: ${BUILD_DIR}/config.h getcwd.o: ${BUILD_DIR}/config.h getenv.o: ${BUILD_DIR}/config.h inet_aton.o: ${BUILD_DIR}/config.h +input_avail.o: ${BUILD_DIR}/config.h itos.o: ${BUILD_DIR}/config.h mailstat.o: ${BUILD_DIR}/config.h makepath.o: ${BUILD_DIR}/config.h +mbscasecmp.o: ${BUILD_DIR}/config.h +mbscmp.o: ${BUILD_DIR}/config.h memset.o: ${BUILD_DIR}/config.h mktime.o: ${BUILD_DIR}/config.h netconn.o: ${BUILD_DIR}/config.h @@ -221,7 +245,7 @@ spell.o: ${BUILD_DIR}/config.h strcasecmp.o: ${BUILD_DIR}/config.h strerror.o: ${BUILD_DIR}/config.h strftime.o: ${BUILD_DIR}/config.h -strindex.o: ${BUILD_DIR}/config.h +strcasestr.o: ${BUILD_DIR}/config.h stringlist.o: ${BUILD_DIR}/config.h stringvec.o: ${BUILD_DIR}/config.h strnlen.o: ${BUILD_DIR}/config.h @@ -237,10 +261,14 @@ strtrans.o: ${BUILD_DIR}/config.h times.o: ${BUILD_DIR}/config.h timeval.o: ${BUILD_DIR}/config.h tmpfile.o: ${BUILD_DIR}/config.h +uconvert.o: ${BUILD_DIR}/config.h +ufuncs.o: ${BUILD_DIR}/config.h vprint.o: ${BUILD_DIR}/config.h wcsdup.o: ${BUILD_DIR}/config.h -xstrchr.o: ${BUILD_DIR}/config.h +mbschr.o: ${BUILD_DIR}/config.h zcatfd.o: ${BUILD_DIR}/config.h +zgetline.o: ${BUILD_DIR}/config.h +zmapfd.o: ${BUILD_DIR}/config.h zread.o: ${BUILD_DIR}/config.h zwrite.o: ${BUILD_DIR}/config.h @@ -372,8 +400,8 @@ strerror.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h strerror.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h strerror.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h -strindex.o: ${BASHINCDIR}/stdc.h ${topdir}/bashansi.h -strindex.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h +strcasestr.o: ${BASHINCDIR}/stdc.h ${topdir}/bashansi.h +strcasestr.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h stringlist.o: ${topdir}/bashansi.h stringlist.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h @@ -439,6 +467,10 @@ tmpfile.o: ${topdir}/bashtypes.h tmpfile.o: ${BASHINCDIR}/posixstat.h tmpfile.o: ${BASHINCDIR}/filecntl.h +uconvert.o: ${topdir}/bashtypes.h + +ufuncs.o: ${topdir}/bashtypes.h + clock.o: ${BASHINCDIR}/posixtime.h mailstat.o: ${topdir}/bashansi.h @@ -473,6 +505,40 @@ wcsdup.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h wcsdup.o: ${BASHINCDIR}/stdc.h wcsdup.o: ${topdir}/xmalloc.h -xstrchr.o: ${topdir}/bashansi.h -xstrchr.o: ${BASHINCDIR}/ansi_stdlib.h -xstrchr.o: ${BASHINCDIR}/shmbutil.h +mbschr.o: ${topdir}/bashansi.h +mbschr.o: ${BASHINCDIR}/ansi_stdlib.h +mbschr.o: ${BASHINCDIR}/shmbutil.h + +zgetline.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +zgetline.o: ${BASHINCDIR}/stdc.h +zgetline.o: ${topdir}/xmalloc.h +zgetline.o: ${topdir}/bashtypes.h + +mbscasecmp.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +mbscasecmp.o: ${BASHINCDIR}/stdc.h +mbscasecmp.o: ${topdir}/xmalloc.h + +mbscmp.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +mbscmp.o: ${BASHINCDIR}/stdc.h +mbscmp.o: ${topdir}/xmalloc.h + +casemod.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +casemod.o: ${BASHINCDIR}/stdc.h +casemod.o: ${topdir}/xmalloc.h +casemod.o: ${topdir}/bashtypes.h +casemod.o: ${BASHINCDIR}/shmbutil.h +casemod.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h + +fdprintf.o: ${BASHINCDIR}/stdc.h + +input_avail.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +input_avail.o: ${BASHINCDIR}/stdc.h +input_avail.o: ${topdir}/xmalloc.h ${BASHINCDIR}/posixselect.h + +mktime.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +mktime.o: ${BASHINCDIR}/stdc.h + +fnxform.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +fnxform.o: ${BASHINCDIR}/stdc.h +fnxform.o: ${topdir}/bashtypes.h +fnxform.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h diff --git a/lib/sh/casemod.c b/lib/sh/casemod.c new file mode 100644 index 0000000..d85549a --- /dev/null +++ b/lib/sh/casemod.c @@ -0,0 +1,244 @@ +/* casemod.c -- functions to change case of strings */ + +/* Copyright (C) 2008,2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#if defined (HAVE_CONFIG_H) +# include <config.h> +#endif + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif /* HAVE_UNISTD_H */ + +#include <stdc.h> + +#include <bashansi.h> +#include <bashintl.h> +#include <bashtypes.h> + +#include <stdio.h> +#include <ctype.h> +#include <xmalloc.h> + +#include <shmbutil.h> +#include <chartypes.h> + +#include <glob/strmatch.h> + +#define _to_wupper(wc) (iswlower (wc) ? towupper (wc) : (wc)) +#define _to_wlower(wc) (iswupper (wc) ? towlower (wc) : (wc)) + +#if !defined (HANDLE_MULTIBYTE) +# define cval(s, i) ((s)[(i)]) +# define iswalnum(c) (isalnum(c)) +# define TOGGLE(x) (ISUPPER (x) ? tolower (x) : (TOUPPER (x))) +#else +# define TOGGLE(x) (iswupper (x) ? towlower (x) : (_to_wupper(x))) +#endif + +/* These must agree with the defines in externs.h */ +#define CASE_NOOP 0x0000 +#define CASE_LOWER 0x0001 +#define CASE_UPPER 0x0002 +#define CASE_CAPITALIZE 0x0004 +#define CASE_UNCAP 0x0008 +#define CASE_TOGGLE 0x0010 +#define CASE_TOGGLEALL 0x0020 +#define CASE_UPFIRST 0x0040 +#define CASE_LOWFIRST 0x0080 + +#define CASE_USEWORDS 0x1000 /* modify behavior to act on words in passed string */ + +extern char *substring __P((char *, int, int)); + +#if defined (HANDLE_MULTIBYTE) +static wchar_t +cval (s, i) + char *s; + int i; +{ + size_t tmp; + wchar_t wc; + int l; + mbstate_t mps; + + if (MB_CUR_MAX == 1) + return ((wchar_t)s[i]); + l = strlen (s); + if (i >= (l - 1)) + return ((wchar_t)s[i]); + memset (&mps, 0, sizeof (mbstate_t)); + tmp = mbrtowc (&wc, s + i, l - i, &mps); + if (MB_INVALIDCH (tmp) || MB_NULLWCH (tmp)) + return ((wchar_t)s[i]); + return wc; +} +#endif + +/* Modify the case of characters in STRING matching PAT based on the value of + FLAGS. If PAT is null, modify the case of each character */ +char * +sh_modcase (string, pat, flags) + const char *string; + char *pat; + int flags; +{ + int start, next, end; + int inword, c, nc, nop, match, usewords; + char *ret, *s; + wchar_t wc; +#if defined (HANDLE_MULTIBYTE) + wchar_t nwc; + char mb[MB_LEN_MAX+1]; + int mlen; + size_t m; + mbstate_t state; +#endif + +#if defined (HANDLE_MULTIBYTE) + memset (&state, 0, sizeof (mbstate_t)); +#endif + + start = 0; + end = strlen (string); + + ret = (char *)xmalloc (end + 1); + strcpy (ret, string); + + /* See if we are supposed to split on alphanumerics and operate on each word */ + usewords = (flags & CASE_USEWORDS); + flags &= ~CASE_USEWORDS; + + inword = 0; + while (start < end) + { + wc = cval (ret, start); + + if (iswalnum (wc) == 0) + { + inword = 0; + ADVANCE_CHAR (ret, end, start); + continue; + } + + if (pat) + { + next = start; + ADVANCE_CHAR (ret, end, next); + s = substring (ret, start, next); + match = strmatch (pat, s, FNM_EXTMATCH) != FNM_NOMATCH; + free (s); + if (match == 0) + { + start = next; + inword = 1; + continue; + } + } + + /* XXX - for now, the toggling operators work on the individual + words in the string, breaking on alphanumerics. Should I + leave the capitalization operators to do that also? */ + if (flags == CASE_CAPITALIZE) + { + if (usewords) + nop = inword ? CASE_LOWER : CASE_UPPER; + else + nop = (start > 0) ? CASE_LOWER : CASE_UPPER; + inword = 1; + } + else if (flags == CASE_UNCAP) + { + if (usewords) + nop = inword ? CASE_UPPER : CASE_LOWER; + else + nop = (start > 0) ? CASE_UPPER : CASE_LOWER; + inword = 1; + } + else if (flags == CASE_UPFIRST) + { + if (usewords) + nop = inword ? CASE_NOOP : CASE_UPPER; + else + nop = (start > 0) ? CASE_NOOP : CASE_UPPER; + inword = 1; + } + else if (flags == CASE_LOWFIRST) + { + if (usewords) + nop = inword ? CASE_NOOP : CASE_LOWER; + else + nop = (start > 0) ? CASE_NOOP : CASE_LOWER; + inword = 1; + } + else if (flags == CASE_TOGGLE) + { + nop = inword ? CASE_NOOP : CASE_TOGGLE; + inword = 1; + } + else + nop = flags; + + if (MB_CUR_MAX == 1 || isascii (wc)) + { + switch (nop) + { + default: + case CASE_NOOP: nc = wc; break; + case CASE_UPPER: nc = TOUPPER (wc); break; + case CASE_LOWER: nc = TOLOWER (wc); break; + case CASE_TOGGLEALL: + case CASE_TOGGLE: nc = TOGGLE (wc); break; + } + ret[start] = nc; + } +#if defined (HANDLE_MULTIBYTE) + else + { + m = mbrtowc (&wc, string + start, end - start, &state); + if (MB_INVALIDCH (m)) + wc = (wchar_t)string[start]; + else if (MB_NULLWCH (m)) + wc = L'\0'; + switch (nop) + { + default: + case CASE_NOOP: nwc = wc; break; + case CASE_UPPER: nwc = TOUPPER (wc); break; + case CASE_LOWER: nwc = TOLOWER (wc); break; + case CASE_TOGGLEALL: + case CASE_TOGGLE: nwc = TOGGLE (wc); break; + } + if (nwc != wc) /* just skip unchanged characters */ + { + mlen = wcrtomb (mb, nwc, &state); + if (mlen > 0) + mb[mlen] = '\0'; + /* Assume the same width */ + strncpy (ret + start, mb, mlen); + } + } +#endif + + /* This assumes that the upper and lower case versions are the same width. */ + ADVANCE_CHAR (ret, end, start); + } + + return ret; +} diff --git a/lib/sh/clktck.c b/lib/sh/clktck.c index 546b49c..096ce06 100644 --- a/lib/sh/clktck.c +++ b/lib/sh/clktck.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/clock.c b/lib/sh/clock.c index 1186a19..84cdbc5 100644 --- a/lib/sh/clock.c +++ b/lib/sh/clock.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/eaccess.c b/lib/sh/eaccess.c index 1cff692..989bc22 100644 --- a/lib/sh/eaccess.c +++ b/lib/sh/eaccess.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #if defined (HAVE_CONFIG_H) # include <config.h> diff --git a/lib/sh/fdprintf.c b/lib/sh/fdprintf.c new file mode 100644 index 0000000..27d3a4b --- /dev/null +++ b/lib/sh/fdprintf.c @@ -0,0 +1,70 @@ +/* fdprintf -- printf to a file descriptor */ + +/* Copyright (C) 2008,2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdc.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + +#if defined (PREFER_STDARG) +# include <stdarg.h> +#else +# include <varargs.h> +#endif + +#include <stdio.h> + +int +#if defined (PREFER_STDARG) +fdprintf(int fd, const char *format, ...) +#else +fdprintf(fd, format, va_alist) + int fd; + const char *format; + va_dcl +#endif +{ + FILE *fp; + int fd2, rc, r2; + va_list args; + + if ((fd2 = dup(fd)) < 0) + return -1; + fp = fdopen (fd2, "w"); + if (fp == 0) + { + close (fd2); + return -1; + } + + SH_VA_START (args, format); + rc = vfprintf (fp, format, args); + fflush (fp); + va_end (args); + + r2 = fclose (fp); /* check here */ + + return rc; +} diff --git a/lib/sh/fmtullong.c b/lib/sh/fmtullong.c index df27944..97a1dc1 100644 --- a/lib/sh/fmtullong.c +++ b/lib/sh/fmtullong.c @@ -2,19 +2,21 @@ /* Copyright (C) 2001-2002 Free Software Foundation, Inc. -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 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. */ + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/fmtulong.c b/lib/sh/fmtulong.c index 43fdffd..214b146 100644 --- a/lib/sh/fmtulong.c +++ b/lib/sh/fmtulong.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #ifdef HAVE_CONFIG_H # include <config.h> diff --git a/lib/sh/fmtumax.c b/lib/sh/fmtumax.c index 9bb4718..f2786b5 100644 --- a/lib/sh/fmtumax.c +++ b/lib/sh/fmtumax.c @@ -2,19 +2,21 @@ /* Copyright (C) 2002 Free Software Foundation, Inc. -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 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. */ + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/fnxform.c b/lib/sh/fnxform.c new file mode 100644 index 0000000..d95274f --- /dev/null +++ b/lib/sh/fnxform.c @@ -0,0 +1,199 @@ +/* fnxform - use iconv(3) to transform strings to and from "filename" format */ + +/* Copyright (C) 2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif +#include "bashansi.h" +#include <stdio.h> +#include "bashtypes.h" + +#include "stdc.h" +#include "bashintl.h" +#include <xmalloc.h> + +#if defined (HAVE_ICONV) +# include <iconv.h> +#endif + +#if defined (HAVE_LOCALE_CHARSET) +extern const char *locale_charset __P((void)); +#else +extern char *get_locale_var __P((char *)); +#endif + +#if defined (HAVE_ICONV) +static iconv_t conv_fromfs = (iconv_t)-1; +static iconv_t conv_tofs = (iconv_t)-1; + +#define OUTLEN_MAX 4096 + +static char *outbuf = 0; +static size_t outlen = 0; + +static char *curencoding __P((void)); +static void init_tofs __P((void)); +static void init_fromfs __P((void)); + +static char * +curencoding () +{ + char *loc; +#if defined (HAVE_LOCALE_CHARSET) + loc = (char *)locale_charset (); + return loc; +#else + char *dot, *mod; + + loc = get_locale_var ("LC_CTYPE"); + if (loc == 0 || *loc == 0) + return ""; + dot = strchr (loc, '.'); + if (dot == 0) + return loc; + mod = strchr (dot, '@'); + if (mod) + *mod = '\0'; + return dot; +#endif +} + +static void +init_tofs () +{ + char *cur; + + cur = curencoding (); + conv_tofs = iconv_open ("UTF-8-MAC", cur); +} + +static void +init_fromfs () +{ + char *cur; + + cur = curencoding (); + conv_fromfs = iconv_open (cur, "UTF-8-MAC"); +} + +char * +fnx_tofs (string, len) + char *string; + size_t len; +{ +#ifdef MACOSX + ICONV_CONST char *inbuf; + char *tempbuf; + size_t templen; + + if (conv_tofs == (iconv_t)-1) + init_tofs (); + if (conv_tofs == (iconv_t)-1) + return string; + + /* Free and reallocate outbuf if it's *too* big */ + if (outlen >= OUTLEN_MAX && len < OUTLEN_MAX - 8) + { + free (outbuf); + outbuf = 0; + outlen = 0; + } + + inbuf = string; + if (outbuf == 0 || outlen < len + 8) + { + outlen = len + 8; + outbuf = outbuf ? xrealloc (outbuf, outlen + 1) : xmalloc (outlen + 1); + } + tempbuf = outbuf; + templen = outlen; + + iconv (conv_tofs, NULL, NULL, NULL, NULL); + + if (iconv (conv_tofs, &inbuf, &len, &tempbuf, &templen) == (size_t)-1) + return string; + + *tempbuf = '\0'; + return outbuf; +#else + return string; +#endif +} + +char * +fnx_fromfs (string, len) + char *string; + size_t len; +{ +#ifdef MACOSX + ICONV_CONST char *inbuf; + char *tempbuf; + size_t templen; + + if (conv_fromfs == (iconv_t)-1) + init_fromfs (); + if (conv_fromfs == (iconv_t)-1) + return string; + + /* Free and reallocate outbuf if it's *too* big */ + if (outlen >= OUTLEN_MAX && len < OUTLEN_MAX - 8) + { + free (outbuf); + outbuf = 0; + outlen = 0; + } + + inbuf = string; + if (outbuf == 0 || outlen < (len + 8)) + { + outlen = len + 8; + outbuf = outbuf ? xrealloc (outbuf, outlen + 1) : xmalloc (outlen + 1); + } + tempbuf = outbuf; + templen = outlen; + + iconv (conv_fromfs, NULL, NULL, NULL, NULL); + + if (iconv (conv_fromfs, &inbuf, &len, &tempbuf, &templen) == (size_t)-1) + return string; + + *tempbuf = '\0'; + return outbuf; +#else + return string; +#endif +} + +#else +char * +fnx_tofs (string) + char *string; +{ + return string; +} + +char * +fnx_fromfs (string) + char *string; +{ + return string; +} +#endif diff --git a/lib/sh/fpurge.c b/lib/sh/fpurge.c new file mode 100644 index 0000000..f9e1b9d --- /dev/null +++ b/lib/sh/fpurge.c @@ -0,0 +1,148 @@ +/* fpurge - Flushing buffers of a FILE stream. */ + +/* Copyright (C) 2007 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#include "stdc.h" + +#include <stdio.h> + +/* Specification. Same as in ../../externs.h. */ +#define NEED_FPURGE_DECL +#if HAVE_FPURGE +# define fpurge _bash_fpurge +#endif +extern int fpurge __P((FILE *stream)); + +#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */ +# include <stdio_ext.h> +#endif +#include <stdlib.h> + +int +fpurge (FILE *fp) +{ +#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */ + + __fpurge (fp); + /* The __fpurge function does not have a return value. */ + return 0; + +#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X */ + + /* Call the system's fpurge function. */ +# undef fpurge +# if !HAVE_DECL_FPURGE + extern int fpurge (FILE *); +# endif + int result = fpurge (fp); +# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ + if (result == 0) + /* Correct the invariants that fpurge broke. + <stdio.h> on BSD systems says: + "The following always hold: if _flags & __SRD, _w is 0." + If this invariant is not fulfilled and the stream is read-write but + currently writing, subsequent putc or fputc calls will write directly + into the buffer, although they shouldn't be allowed to. */ + if ((fp->_flags & __SRD) != 0) + fp->_w = 0; +# endif + return result; + +#else + + /* Most systems provide FILE as a struct and the necessary bitmask in + <stdio.h>, because they need it for implementing getc() and putc() as + fast macros. */ +# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ + fp->_IO_read_end = fp->_IO_read_ptr; + fp->_IO_write_ptr = fp->_IO_write_base; + /* Avoid memory leak when there is an active ungetc buffer. */ + if (fp->_IO_save_base != NULL) + { + free (fp->_IO_save_base); + fp->_IO_save_base = NULL; + } + return 0; +# elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ + fp_->_p = fp_->_bf._base; + fp_->_r = 0; + fp_->_w = ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */ + ? fp_->_bf._size + : 0); + /* Avoid memory leak when there is an active ungetc buffer. */ + if (fp_ub._base != NULL) + { + if (fp_ub._base != fp_->_ubuf) + free (fp_ub._base); + fp_ub._base = NULL; + } + return 0; +# elif defined __EMX__ /* emx+gcc */ + fp->_ptr = fp->_buffer; + fp->_rcount = 0; + fp->_wcount = 0; + fp->_ungetc_count = 0; + return 0; +# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */ + fp->_ptr = fp->_base; + if (fp->_ptr != NULL) + fp->_cnt = 0; + return 0; +# elif defined __UCLIBC__ /* uClibc */ +# ifdef __STDIO_BUFFERS + if (fp->__modeflags & __FLAG_WRITING) + fp->__bufpos = fp->__bufstart; + else if (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) + fp->__bufpos = fp->__bufread; +# endif + return 0; +# elif defined __QNX__ /* QNX */ + fp->_Rback = fp->_Back + sizeof (fp->_Back); + fp->_Rsave = NULL; + if (fp->_Mode & 0x2000 /* _MWRITE */) + /* fp->_Buf <= fp->_Next <= fp->_Wend */ + fp->_Next = fp->_Buf; + else + /* fp->_Buf <= fp->_Next <= fp->_Rend */ + fp->_Rend = fp->_Next; + return 0; +# elif defined __MINT__ /* Atari FreeMiNT */ + if (fp->__pushed_back) + { + fp->__bufp = fp->__pushback_bufp; + fp->__pushed_back = 0; + } + /* Preserve the current file position. */ + if (fp->__target != -1) + fp->__target += fp->__bufp - fp->__buffer; + fp->__bufp = fp->__buffer; + /* Nothing in the buffer, next getc is nontrivial. */ + fp->__get_limit = fp->__bufp; + /* Nothing in the buffer, next putc is nontrivial. */ + fp->__put_limit = fp->__buffer; + return 0; +# else +# warning "Please port gnulib fpurge.c to your platform! Look at the definitions of fflush, setvbuf and ungetc on your system, then report this to bug-gnulib." + return 0; +# endif + +#endif +} diff --git a/lib/sh/getcwd.c b/lib/sh/getcwd.c index cd724f6..07eb817 100644 --- a/lib/sh/getcwd.c +++ b/lib/sh/getcwd.c @@ -1,22 +1,22 @@ -/* getcwd.c -- stolen from the GNU C library and modified to work with bash. */ +/* getcwd.c -- get pathname of current directory */ /* Copyright (C) 1991 Free Software Foundation, Inc. - This file is part of the GNU C Library. - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + This file is part of GNU Bash, the Bourne Again SHell. - The GNU C Library is distributed in the hope that it will be useful, + Bash 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. + + Bash 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 - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If - not, write to the Free Software Foundation, Inc., - 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> @@ -26,6 +26,10 @@ #pragma alloca #endif /* _AIX && RISC6000 && !__GNUC__ */ +#if defined (__QNX__) +# undef HAVE_LSTAT +#endif + #include <bashtypes.h> #include <errno.h> @@ -44,6 +48,12 @@ #include <bashansi.h> +#if defined (BROKEN_DIRENT_D_INO) +# include "command.h" +# include "general.h" +# include "externs.h" +#endif + #include <xmalloc.h> #if !defined (errno) @@ -58,6 +68,33 @@ extern int errno; # define NULL 0 #endif +/* If the d_fileno member of a struct dirent doesn't return anything useful, + we need to check inode number equivalence the hard way. Return 1 if + the inode corresponding to PATH/DIR is identical to THISINO. */ +#if defined (BROKEN_DIRENT_D_INO) +static int +_path_checkino (dotp, name, thisino) + char *dotp; + char *name; + ino_t thisino; +{ + char *fullpath; + int r, e; + struct stat st; + + e = errno; + fullpath = sh_makepath (dotp, name, MP_RMDOT); + if (stat (fullpath, &st) < 0) + { + errno = e; + return 0; + } + free (fullpath); + errno = e; + return (st.st_ino == thisino); +} +#endif + /* Get the pathname of the current working directory, and put it in SIZE bytes of BUF. Returns NULL if the directory couldn't be determined or SIZE was too small. @@ -169,7 +206,11 @@ getcwd (buf, size) (d->d_name[1] == '\0' || (d->d_name[1] == '.' && d->d_name[2] == '\0'))) continue; +#if !defined (BROKEN_DIRENT_D_INO) if (mount_point || d->d_fileno == thisino) +#else + if (mount_point || _path_checkino (dotp, d->d_name, thisino)) +#endif { char *name; @@ -251,19 +292,21 @@ getcwd (buf, size) { size_t len = pathbuf + pathsize - pathp; + if (buf == NULL && size <= 0) + size = len; + + if ((size_t) size < len) + { + errno = ERANGE; + goto lose2; + } if (buf == NULL) { - if (len < (size_t) size) - len = size; - buf = (char *) malloc (len); + buf = (char *) malloc (size); if (buf == NULL) goto lose2; } - else if ((size_t) size < len) - { - errno = ERANGE; - goto lose2; - } + (void) memcpy((PTR_T) buf, (PTR_T) pathp, len); } diff --git a/lib/sh/getenv.c b/lib/sh/getenv.c index c3fbf75..8b5e340 100644 --- a/lib/sh/getenv.c +++ b/lib/sh/getenv.c @@ -5,19 +5,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/inet_aton.c b/lib/sh/inet_aton.c index 2835d62..4b48456 100644 --- a/lib/sh/inet_aton.c +++ b/lib/sh/inet_aton.c @@ -1,3 +1,5 @@ +/* inet_aton - convert string to numeric IP address */ + /* Snagged from GNU C library, version 2.0.3. */ /* diff --git a/lib/sh/input_avail.c b/lib/sh/input_avail.c new file mode 100644 index 0000000..ac157a9 --- /dev/null +++ b/lib/sh/input_avail.c @@ -0,0 +1,98 @@ +/* input_avail.c -- check whether or not data is available for reading on a + specified file descriptor. */ + +/* Copyright (C) 2008,2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#if defined (__TANDEM) +# include <floss.h> +#endif + +#if defined (HAVE_CONFIG_H) +# include <config.h> +#endif + +#include <sys/types.h> +#include <fcntl.h> +#if defined (HAVE_SYS_FILE_H) +# include <sys/file.h> +#endif /* HAVE_SYS_FILE_H */ + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif /* HAVE_UNISTD_H */ + +#include "bashansi.h" + +#include "posixselect.h" + +#if defined (FIONREAD_IN_SYS_IOCTL) +# include <sys/ioctl.h> +#endif + +#include <stdio.h> +#include <errno.h> + +#if !defined (errno) +extern int errno; +#endif /* !errno */ + +#if !defined (O_NDELAY) && defined (O_NONBLOCK) +# define O_NDELAY O_NONBLOCK /* Posix style */ +#endif + +/* Return >= 1 if select/FIONREAD indicates data available for reading on + file descriptor FD; 0 if no data available. Return -1 on error. */ +int +input_avail (fd) + int fd; +{ + int result, chars_avail; +#if defined(HAVE_SELECT) + fd_set readfds, exceptfds; + struct timeval timeout; +#endif + + if (fd < 0) + return -1; + + chars_avail = 0; + +#if defined (HAVE_SELECT) + FD_ZERO (&readfds); + FD_ZERO (&exceptfds); + FD_SET (fd, &readfds); + FD_SET (fd, &exceptfds); + timeout.tv_sec = 0; + timeout.tv_usec = 0; + result = select (fd + 1, &readfds, (fd_set *)NULL, &exceptfds, &timeout); + return ((result <= 0) ? 0 : 1); + +#endif + + result = -1; +#if defined (FIONREAD) + errno = 0; + result = ioctl (fd, FIONREAD, &chars_avail); + if (result == -1 && errno == EIO) + return -1; + return (chars_avail); +#endif + + return 0; +} diff --git a/lib/sh/itos.c b/lib/sh/itos.c index e9a7942..12e9398 100644 --- a/lib/sh/itos.c +++ b/lib/sh/itos.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #ifdef HAVE_CONFIG_H # include <config.h> diff --git a/lib/sh/mailstat.c b/lib/sh/mailstat.c index 03782e7..2b2ac0e 100644 --- a/lib/sh/mailstat.c +++ b/lib/sh/mailstat.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/makepath.c b/lib/sh/makepath.c index c496154..43dbab2 100644 --- a/lib/sh/makepath.c +++ b/lib/sh/makepath.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> @@ -42,17 +42,21 @@ # define MP_DOTILDE 0x01 # define MP_DOCWD 0x02 # define MP_RMDOT 0x04 +# define MP_IGNDOT 0x08 #endif extern char *get_working_directory __P((char *)); +static char *nullpath = ""; + /* Take PATH, an element from, e.g., $CDPATH, and DIR, a directory name, and paste them together into PATH/DIR. Tilde expansion is performed on PATH if (flags & MP_DOTILDE) is non-zero. If PATH is NULL or the empty string, it is converted to the current directory. A full pathname is used if (flags & MP_DOCWD) is non-zero, otherwise `./' is used. If (flags & MP_RMDOT) is non-zero, any `./' is removed from the beginning - of DIR. */ + of DIR. If (flags & MP_IGNDOT) is non-zero, a PATH that is "." or "./" + is ignored. */ #define MAKEDOT() \ do { \ @@ -89,6 +93,12 @@ sh_makepath (path, dir, flags) else MAKEDOT(); } + else if ((flags & MP_IGNDOT) && path[0] == '.' && (path[1] == '\0' || + path[1] == '/' && path[2] == '\0')) + { + xpath = nullpath; + pathlen = 0; + } else { xpath = ((flags & MP_DOTILDE) && *path == '~') ? bash_tilde_expand (path, 0) : (char *)path; @@ -107,12 +117,12 @@ sh_makepath (path, dir, flags) s = xpath; while (*s) *r++ = *s++; - if (s[-1] != '/') + if (s > xpath && s[-1] != '/') *r++ = '/'; s = xdir; while (*r++ = *s++) ; - if (xpath != path) + if (xpath != path && xpath != nullpath) free (xpath); return (ret); } diff --git a/lib/sh/mbscasecmp.c b/lib/sh/mbscasecmp.c new file mode 100644 index 0000000..3828164 --- /dev/null +++ b/lib/sh/mbscasecmp.c @@ -0,0 +1,78 @@ +/* mbscasecmp - case-insensitive multibyte string comparison. */ + +/* Copyright (C) 2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#if !defined (HAVE_MBSCASECMP) && defined (HANDLE_MULTIBYTE) + +#include <stdlib.h> +#include <stddef.h> +#include <string.h> + +#include <wchar.h> +#include <wctype.h> + +/* Compare MBS1 and MBS2 without regard to case. */ +int +mbscasecmp (mbs1, mbs2) + const char *mbs1; + const char *mbs2; +{ + int len1, len2; + wchar_t c1, c2, l1, l2; + + len1 = len2 = 0; + /* Reset multibyte characters to their initial state. */ + (void) mblen ((char *) NULL, 0); + + do + { + len1 = mbtowc (&c1, mbs1, MB_CUR_MAX); + len2 = mbtowc (&c2, mbs2, MB_CUR_MAX); + + if (len1 == 0) + return len2 == 0 ? 0 : -1; + else if (len2 == 0) + return 1; + else if (len1 > 0 && len2 < 0) + return -1; + else if (len1 < 0 && len2 > 0) + return 1; + else if (len1 < 0 && len2 < 0) + { + len1 = strlen (mbs1); + len2 = strlen (mbs2); + return (len1 == len2 ? memcmp (mbs1, mbs2, len1) + : ((len1 < len2) ? (memcmp (mbs1, mbs2, len1) > 0 ? 1 : -1) + : (memcmp (mbs1, mbs2, len2) >= 0 ? 1 : -1))); + } + + l1 = towlower (c1); + l2 = towlower (c2); + + mbs1 += len1; + mbs2 += len2; + } + while (l1 == l2); + + return l1 - l2; +} + +#endif diff --git a/lib/sh/xstrchr.c b/lib/sh/mbschr.c index 3272837..5143d64 100644 --- a/lib/sh/xstrchr.c +++ b/lib/sh/mbschr.c @@ -1,22 +1,22 @@ -/* xstrchr.c - strchr(3) that handles multibyte characters. */ +/* mbschr.c - strchr(3) that handles multibyte characters. */ /* Copyright (C) 2002 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> @@ -27,7 +27,7 @@ #include "bashansi.h" #include "shmbutil.h" -#undef xstrchr +#undef mbschr /* In some locales, the non-first byte of some multibyte characters have the same value as some ascii character. Faced with these strings, a @@ -35,9 +35,9 @@ char * #if defined (PROTOTYPES) -xstrchr (const char *s, int c) +mbschr (const char *s, int c) #else -xstrchr (s, c) +mbschr (s, c) const char *s; int c; #endif @@ -63,7 +63,7 @@ xstrchr (s, c) if (mblength == (size_t)-2 || mblength == (size_t)-1 || mblength == (size_t)0) mblength = 1; - if (c == (unsigned char)*pos) + if (mblength == 1 && c == (unsigned char)*pos) return pos; strlength -= mblength; diff --git a/lib/sh/mbscmp.c b/lib/sh/mbscmp.c new file mode 100644 index 0000000..e0eae5d --- /dev/null +++ b/lib/sh/mbscmp.c @@ -0,0 +1,72 @@ +/* mbscmp - multibyte string comparison. */ + +/* Copyright (C) 1995 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#if !defined (HAVE_MBSCMP) && defined (HANDLE_MULTIBYTE) + +#include <stdlib.h> +#include <stddef.h> +#include <string.h> + +/* Compare MBS1 and MBS2. */ +int +mbscmp (mbs1, mbs2) + const char *mbs1; + const char *mbs2; +{ + int len1, len2; + wchar_t c1, c2; + + len1 = len2 = 0; + /* Reset multibyte characters to their initial state. */ + (void) mblen ((char *) NULL, 0); + + do + { + len1 = mbtowc (&c1, mbs1, MB_CUR_MAX); + len2 = mbtowc (&c2, mbs2, MB_CUR_MAX); + + if (len1 == 0) + return len2 == 0 ? 0 : -1; + else if (len2 == 0) + return 1; + else if (len1 > 0 && len2 < 0) + return -1; + else if (len1 < 0 && len2 > 0) + return 1; + else if (len1 < 0 && len2 < 0) + { + len1 = strlen (mbs1); + len2 = strlen (mbs2); + return (len1 == len2 ? memcmp (mbs1, mbs2, len1) + : ((len1 < len2) ? (memcmp (mbs1, mbs2, len1) > 0 ? 1 : -1) + : (memcmp (mbs1, mbs2, len2) >= 0 ? 1 : -1))); + } + + mbs1 += len1; + mbs2 += len2; + } + while (c1 == c2); + + return c1 - c2; +} + +#endif diff --git a/lib/sh/memset.c b/lib/sh/memset.c index ddc36b6..4ebc418 100644 --- a/lib/sh/memset.c +++ b/lib/sh/memset.c @@ -1,19 +1,22 @@ -/* memset.c -- set an area of memory to a given value - Copyright (C) 1991-2002 Free Software Foundation, Inc. +/* memset.c -- set an area of memory to a given value */ - This program is free software; you can redistribute it and/or modify +/* Copyright (C) 1991-2002 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, + Bash 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. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ char * memset (char *str, int c, unsigned int len) diff --git a/lib/sh/mktime.c b/lib/sh/mktime.c index 81aeb22..7257400 100644 --- a/lib/sh/mktime.c +++ b/lib/sh/mktime.c @@ -1,22 +1,23 @@ +/* mktime - convert struct tm to a time_t value */ + /* Copyright (C) 1993-2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. + + This file is part of GNU Bash, the Bourne Again SHell. Contributed by Paul Eggert (eggert@twinsun.com). - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + Bash 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 GNU C Library is distributed in the hope that it will be useful, + Bash 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ /* Define this to have a standalone program to test this implementation of mktime. */ /* #define DEBUG 1 */ @@ -49,11 +50,10 @@ #include <limits.h> #endif +#include "bashansi.h" + #if DEBUG #include <stdio.h> -#if STDC_HEADERS -#include <stdlib.h> -#endif /* Make it work even if the system's libc has its own mktime routine. */ #define mktime my_mktime #endif /* DEBUG */ diff --git a/lib/sh/netconn.c b/lib/sh/netconn.c index ae7c249..36e5bf5 100644 --- a/lib/sh/netconn.c +++ b/lib/sh/netconn.c @@ -4,19 +4,18 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free - Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. + along with Bash. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> diff --git a/lib/sh/netopen.c b/lib/sh/netopen.c index d8eec75..736d413 100644 --- a/lib/sh/netopen.c +++ b/lib/sh/netopen.c @@ -9,19 +9,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free - Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/oslib.c b/lib/sh/oslib.c index 90d7be9..d47f9dc 100644 --- a/lib/sh/oslib.c +++ b/lib/sh/oslib.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/pathcanon.c b/lib/sh/pathcanon.c index 3b427a8..98e41ce 100644 --- a/lib/sh/pathcanon.c +++ b/lib/sh/pathcanon.c @@ -1,22 +1,22 @@ -/* pathcanon.c -- Canonicalize and manipulate pathnames. */ +/* pathcanon.c -- canonicalize and manipulate pathnames. */ /* Copyright (C) 2000 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/pathphys.c b/lib/sh/pathphys.c index 1f73944..15fcd25 100644 --- a/lib/sh/pathphys.c +++ b/lib/sh/pathphys.c @@ -1,22 +1,22 @@ -/* pathphys.c -- Return pathname with all symlinks expanded. */ +/* pathphys.c -- return pathname with all symlinks expanded. */ /* Copyright (C) 2000 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/rename.c b/lib/sh/rename.c index d5c2778..e410b5e 100644 --- a/lib/sh/rename.c +++ b/lib/sh/rename.c @@ -6,19 +6,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free - Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/setlinebuf.c b/lib/sh/setlinebuf.c index 3c5d056..6473ddf 100644 --- a/lib/sh/setlinebuf.c +++ b/lib/sh/setlinebuf.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/shmatch.c b/lib/sh/shmatch.c index f03a2ee..6de1dc1 100644 --- a/lib/sh/shmatch.c +++ b/lib/sh/shmatch.c @@ -1,24 +1,24 @@ +/* + * shmatch.c -- shell interface to posix regular expression matching. + */ + /* Copyright (C) 2003 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ - -/* - * shmatch.c -- shell interface to posix regular expression matching. - */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #ifdef HAVE_CONFIG_H # include <config.h> diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c index e992a66..a267d38 100644 --- a/lib/sh/shquote.c +++ b/lib/sh/shquote.c @@ -1,20 +1,22 @@ +/* shquote - functions to quote and dequote strings */ + /* Copyright (C) 1999 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/shtty.c b/lib/sh/shtty.c index 15cc82f..0433f5e 100644 --- a/lib/sh/shtty.c +++ b/lib/sh/shtty.c @@ -1,24 +1,24 @@ +/* + * shtty.c -- abstract interface to the terminal, focusing on capabilities. + */ + /* Copyright (C) 1999 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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. + Bash 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. - You should have received a copy of the GNU General Public License along - with Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. -/* - * shtty.c -- abstract interface to the terminal, focusing on capabilities. - */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #ifdef HAVE_CONFIG_H # include <config.h> @@ -85,7 +85,7 @@ ttrestore() ttsaved = 0; } -/* Retrieve the attributes associated with tty fd FD. */ +/* Retrieve the internally-saved attributes associated with tty fd FD. */ TTYSTRUCT * ttattr (fd) int fd; @@ -149,6 +149,17 @@ tt_setonechar(ttp) return 0; } +/* Set the tty associated with FD and TTP into one-character-at-a-time mode */ +int +ttfd_onechar (fd, ttp) + int fd; + TTYSTRUCT *ttp; +{ + if (tt_setonechar(ttp) < 0) + return -1; + return (ttsetattr (fd, ttp)); +} + /* Set the terminal into one-character-at-a-time mode */ int ttonechar () @@ -158,9 +169,7 @@ ttonechar () if (ttsaved == 0) return -1; tt = ttin; - if (tt_setonechar(&tt) < 0) - return -1; - return (ttsetattr (0, &tt)); + return (ttfd_onechar (0, &tt)); } /* @@ -180,6 +189,17 @@ tt_setnoecho(ttp) return 0; } +/* Set the tty associated with FD and TTP into no-echo mode */ +int +ttfd_noecho (fd, ttp) + int fd; + TTYSTRUCT *ttp; +{ + if (tt_setnoecho (ttp) < 0) + return -1; + return (ttsetattr (fd, ttp)); +} + /* Set the terminal into no-echo mode */ int ttnoecho () @@ -189,9 +209,7 @@ ttnoecho () if (ttsaved == 0) return -1; tt = ttin; - if (tt_setnoecho (&tt) < 0) - return -1; - return (ttsetattr (0, &tt)); + return (ttfd_noecho (0, &tt)); } /* @@ -213,6 +231,17 @@ tt_seteightbit (ttp) return 0; } +/* Set the tty associated with FD and TTP into eight-bit mode */ +int +ttfd_eightbit (fd, ttp) + int fd; + TTYSTRUCT *ttp; +{ + if (tt_seteightbit (ttp) < 0) + return -1; + return (ttsetattr (fd, ttp)); +} + /* Set the terminal into eight-bit mode */ int tteightbit () @@ -222,9 +251,7 @@ tteightbit () if (ttsaved == 0) return -1; tt = ttin; - if (tt_seteightbit (&tt) < 0) - return -1; - return (ttsetattr (0, &tt)); + return (ttfd_eightbit (0, &tt)); } /* @@ -242,6 +269,17 @@ tt_setnocanon (ttp) return 0; } +/* Set the tty associated with FD and TTP into non-canonical mode */ +int +ttfd_nocanon (fd, ttp) + int fd; + TTYSTRUCT *ttp; +{ + if (tt_setnocanon (ttp) < 0) + return -1; + return (ttsetattr (fd, ttp)); +} + /* Set the terminal into non-canonical mode */ int ttnocanon () @@ -251,9 +289,7 @@ ttnocanon () if (ttsaved == 0) return -1; tt = ttin; - if (tt_setnocanon (&tt) < 0) - return -1; - return (ttsetattr (0, &tt)); + return (ttfd_nocanon (0, &tt)); } /* @@ -269,6 +305,18 @@ tt_setcbreak(ttp) return (tt_setnoecho (ttp)); } +/* Set the tty associated with FD and TTP into cbreak (no-echo, + one-character-at-a-time) mode */ +int +ttfd_cbreak (fd, ttp) + int fd; + TTYSTRUCT *ttp; +{ + if (tt_setcbreak (ttp) < 0) + return -1; + return (ttsetattr (fd, ttp)); +} + /* Set the terminal into cbreak (no-echo, one-character-at-a-time) mode */ int ttcbreak () @@ -278,7 +326,5 @@ ttcbreak () if (ttsaved == 0) return -1; tt = ttin; - if (tt_setcbreak (&tt) < 0) - return -1; - return (ttsetattr (0, &tt)); + return (ttfd_cbreak (0, &tt)); } diff --git a/lib/sh/snprintf.c b/lib/sh/snprintf.c index 4a96474..d681b16 100644 --- a/lib/sh/snprintf.c +++ b/lib/sh/snprintf.c @@ -1,3 +1,5 @@ +/* snprintf - formatted output to strings, with bounds checking and allocation */ + /* build a test version with gcc -g -DDRIVER -I../.. -I../../include -o test-snprintf snprintf.c fmtu*long.o @@ -7,21 +9,22 @@ Unix snprintf implementation. derived from inetutils/libinetutils/snprintf.c Version 1.1 - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001,2006 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General License as published by - the Free Software Foundation; either version 2 of the License, or + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, + + Bash 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 License for more details. - - You should have received a copy of the GNU General License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. Revision History: @@ -58,6 +61,15 @@ # include <config.h> #endif +/* GCC 4.2 on Snow Leopard doesn't like the snprintf prototype */ +#if defined(DEBUG) && !defined (MACOSX) +# undef HAVE_SNPRINTF +# undef HAVE_ASPRINTF + +# define HAVE_SNPRINTF 0 +# define HAVE_ASPRINTF 0 +#endif + #if defined(DRIVER) && !defined(HAVE_CONFIG_H) #define HAVE_LONG_LONG #define HAVE_LONG_DOUBLE @@ -74,7 +86,7 @@ #define intmax_t long #endif -#if !defined (HAVE_SNPRINTF) || !defined (HAVE_ASPRINTF) +#if !HAVE_SNPRINTF || !HAVE_ASPRINTF #include <bashtypes.h> @@ -291,6 +303,13 @@ static void dfallback __P((struct DATA *, const char *, const char *, double)); static char *groupnum __P((char *)); +#ifndef HAVE_ISINF_IN_LIBC +static int isinf __P((double)); +#endif +#ifndef HAVE_ISNAN_IN_LIBC +static int isnan __P((double)); +#endif + #ifdef DRIVER static void memory_error_and_abort (); static void *xmalloc __P((size_t)); @@ -401,7 +420,7 @@ static void xfree __P((void *)); } \ } while (0) -#if defined (HAVE_LOCALE_H) +#if defined (HAVE_LOCALE_H) && defined (HAVE_LOCALECONV) # define GETLOCALEDATA(d, t, g) \ do \ { \ @@ -471,6 +490,8 @@ pow_10(n) 10^x ~= r * log_10(200) = 2; * log_10(250) = 2; + * + * NOTE: do not call this with r == 0 -- an infinite loop results. */ static int log_10(r) @@ -576,8 +597,11 @@ numtoa(number, base, precision, fract) { integral_part[0] = '0'; integral_part[1] = '\0'; - fraction_part[0] = '0'; - fraction_part[1] = '\0'; + /* The fractional part has to take the precision into account */ + for (ch = 0; ch < precision-1; ch++) + fraction_part[ch] = '0'; + fraction_part[ch] = '0'; + fraction_part[ch+1] = '\0'; if (fract) *fract = fraction_part; return integral_part; @@ -663,7 +687,8 @@ number(p, d, base) p->flags &= ~PF_ZEROPAD; sd = d; /* signed for ' ' padding in base 10 */ - flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0; + flags = 0; + flags = (*p->pf == 'x' || *p->pf == 'X' || *p->pf == 'o' || *p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0; if (*p->pf == 'X') flags |= FL_HEXUPPER; @@ -733,7 +758,7 @@ lnumber(p, d, base) p->flags &= ~PF_ZEROPAD; sd = d; /* signed for ' ' padding in base 10 */ - flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0; + flags = (*p->pf == 'x' || *p->pf == 'X' || *p->pf == 'o' || *p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0; if (*p->pf == 'X') flags |= FL_HEXUPPER; @@ -805,6 +830,7 @@ pointer(p, d) PUT_CHAR(*tmp, p); tmp++; } + PAD_LEFT(p); } @@ -972,11 +998,21 @@ floating(p, d) if ((p->flags & PF_THOUSANDS) && grouping && (t = groupnum (tmp))) tmp = t; + if ((*p->pf == 'g' || *p->pf == 'G') && (p->flags & PF_ALTFORM) == 0) + { + /* smash the trailing zeros unless altform */ + for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--) + tmp2[i] = '\0'; + if (tmp2[0] == '\0') + p->precision = 0; + } + /* calculate the padding. 1 for the dot */ p->width = p->width - ((d > 0. && p->justify == RIGHT) ? 1:0) - ((p->flags & PF_SPACE) ? 1:0) - - strlen(tmp) - p->precision - 1; + strlen(tmp) - p->precision - + ((p->precision != 0 || (p->flags & PF_ALTFORM)) ? 1 : 0); /* radix char */ PAD_RIGHT(p); PUT_PLUS(d, p, 0.); PUT_SPACE(d, p, 0.); @@ -991,11 +1027,6 @@ floating(p, d) if (p->precision != 0 || (p->flags & PF_ALTFORM)) PUT_CHAR(decpoint, p); /* put the '.' */ - if ((*p->pf == 'g' || *p->pf == 'G') && (p->flags & PF_ALTFORM) == 0) - /* smash the trailing zeros unless altform */ - for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--) - tmp2[i] = '\0'; - for (; *tmp2; tmp2++) PUT_CHAR(*tmp2, p); /* the fraction */ @@ -1011,14 +1042,19 @@ exponent(p, d) char *tmp, *tmp2; int j, i; - if (chkinfnan(p, d, 1) || chkinfnan(p, d, 2)) + if (d != 0 && (chkinfnan(p, d, 1) || chkinfnan(p, d, 2))) return; /* already printed nan or inf */ GETLOCALEDATA(decpoint, thoussep, grouping); DEF_PREC(p); - j = log_10(d); - d = d / pow_10(j); /* get the Mantissa */ - d = ROUND(d, p); + if (d == 0.) + j = 0; + else + { + j = log_10(d); + d = d / pow_10(j); /* get the Mantissa */ + d = ROUND(d, p); + } tmp = dtoa(d, p->precision, &tmp2); /* 1 for unit, 1 for the '.', 1 for 'e|E', @@ -1076,6 +1112,7 @@ exponent(p, d) PUT_CHAR(*tmp, p); tmp++; } + PAD_LEFT(p); } #endif @@ -1358,7 +1395,7 @@ conv_break: STAR_ARGS(data); DEF_PREC(data); d = GETDOUBLE(data); - i = log_10(d); + i = (d != 0.) ? log_10(d) : -1; /* * for '%g|%G' ANSI: use f if exponent * is in the range or [-4,p] exclusively @@ -1614,7 +1651,7 @@ dfallback (data, fs, fe, d) } #endif /* FLOATING_POINT */ -#ifndef HAVE_SNPRINTF +#if !HAVE_SNPRINTF int #if defined (__STDC__) @@ -1664,7 +1701,7 @@ snprintf(string, length, format, va_alist) #endif /* HAVE_SNPRINTF */ -#ifndef HAVE_ASPRINTF +#if !HAVE_ASPRINTF int #if defined (__STDC__) @@ -1709,9 +1746,9 @@ asprintf(stringp, format, va_alist) return rval; } -#endif +#endif /* !HAVE_ASPRINTF */ -#endif +#endif /* !HAVE_SNPRINTF || !HAVE_ASPRINTF */ #ifdef DRIVER diff --git a/lib/sh/spell.c b/lib/sh/spell.c index cff20b2..d0394c2 100644 --- a/lib/sh/spell.c +++ b/lib/sh/spell.c @@ -2,21 +2,21 @@ /* Copyright (C) 2000 Free Software Foundation, Inc. -This file is part of GNU Bash, the Bourne Again SHell. + This file is part of GNU Bash, the Bourne Again SHell. -Bash 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. + Bash 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. -Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software -Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> @@ -186,3 +186,27 @@ spdist(cur, new) return 3; } + +char * +dirspell (dirname) + char *dirname; +{ + int n; + char *guess; + + n = (strlen (dirname) * 3 + 1) / 2 + 1; + guess = (char *)malloc (n); + if (guess == 0) + return 0; + + switch (spname (dirname, guess)) + { + case -1: + default: + free (guess); + return (char *)NULL; + case 0: + case 1: + return guess; + } +} diff --git a/lib/sh/strcasecmp.c b/lib/sh/strcasecmp.c index 33d925b..5542f71 100644 --- a/lib/sh/strcasecmp.c +++ b/lib/sh/strcasecmp.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/strcasestr.c b/lib/sh/strcasestr.c new file mode 100644 index 0000000..c819b3e --- /dev/null +++ b/lib/sh/strcasestr.c @@ -0,0 +1,46 @@ +/* strcasestr.c - Find if one string appears as a substring of another string, + without regard to case. */ + +/* Copyright (C) 2000 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#include <bashansi.h> +#include <chartypes.h> + +#include <stdc.h> + +/* Determine if s2 occurs in s1. If so, return a pointer to the + match in s1. The compare is case insensitive. This is a + case-insensitive strstr(3). */ +char * +strcasestr (s1, s2) + const char *s1; + const char *s2; +{ + register int i, l, len, c; + + c = TOLOWER ((unsigned char)s2[0]); + len = strlen (s1); + l = strlen (s2); + for (i = 0; (len - i) >= l; i++) + if ((TOLOWER ((unsigned char)s1[i]) == c) && (strncasecmp (s1 + i, s2, l) == 0)) + return ((char *)s1 + i); + return ((char *)0); +} diff --git a/lib/sh/strerror.c b/lib/sh/strerror.c index 4990aa7..4081e9c 100644 --- a/lib/sh/strerror.c +++ b/lib/sh/strerror.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/strftime.c b/lib/sh/strftime.c index 0783d28..572baae 100644 --- a/lib/sh/strftime.c +++ b/lib/sh/strftime.c @@ -1,7 +1,7 @@ +/* strftime - formatted time and date to a string */ /* * Modified slightly by Chet Ramey for inclusion in Bash */ - /* * strftime.c * @@ -471,6 +471,8 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) * us that muck around with various message processors. */ case 'z': /* time zone offset east of GMT e.g. -0600 */ + if (timeptr->tm_isdst < 0) + break; #ifdef HAVE_TM_NAME /* * Systems with tm_name probably have tm_tzadj as @@ -493,7 +495,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) # ifdef HPUX off = -timezone / 60; # else - off = -(daylight ? timezone : altzone) / 60; + off = -(daylight ? altzone : timezone) / 60; # endif /* !HPUX */ #else /* !HAVE_TZNAME */ gettimeofday(& tv, & zone); diff --git a/lib/sh/strindex.c b/lib/sh/strindex.c deleted file mode 100644 index 9172862..0000000 --- a/lib/sh/strindex.c +++ /dev/null @@ -1,47 +0,0 @@ -/* strindex.c - Find if one string appears as a substring of another string, - without regard to case. */ - -/* Copyright (C) 2000 - Free Software Foundation, Inc. - - This file is part of GNU Bash, the Bourne Again SHell. - - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ - -#include <config.h> - -#include <bashansi.h> -#include <chartypes.h> - -#include <stdc.h> - -/* Determine if s2 occurs in s1. If so, return a pointer to the - match in s1. The compare is case insensitive. This is a - case-insensitive strstr(3). */ -char * -strindex (s1, s2) - const char *s1; - const char *s2; -{ - register int i, l, len, c; - - c = TOLOWER ((unsigned char)s2[0]); - len = strlen (s1); - l = strlen (s2); - for (i = 0; (len - i) >= l; i++) - if ((TOLOWER ((unsigned char)s1[i]) == c) && (strncasecmp (s1 + i, s2, l) == 0)) - return ((char *)s1 + i); - return ((char *)0); -} diff --git a/lib/sh/stringlist.c b/lib/sh/stringlist.c index efc6fa5..b0c272a 100644 --- a/lib/sh/stringlist.c +++ b/lib/sh/stringlist.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/stringvec.c b/lib/sh/stringvec.c index 222fcd6..b0ed416 100644 --- a/lib/sh/stringvec.c +++ b/lib/sh/stringvec.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/strnlen.c b/lib/sh/strnlen.c index da8feec..10414d3 100644 --- a/lib/sh/strnlen.c +++ b/lib/sh/strnlen.c @@ -1,18 +1,22 @@ +/* strnlen - return length of passed string, with length limit */ + /* Copyright (C) 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 file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, + Bash 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. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #ifdef HAVE_CONFIG_H # include <config.h> diff --git a/lib/sh/strpbrk.c b/lib/sh/strpbrk.c index 3c493a8..4439986 100644 --- a/lib/sh/strpbrk.c +++ b/lib/sh/strpbrk.c @@ -1,20 +1,25 @@ +/* strpbrk.c - locate multiple characters in a string */ + /* Copyright (C) 1991, 1994 Free Software Foundation, Inc. + NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, + Bash 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. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #ifdef HAVE_CONFIG_H # include <config.h> diff --git a/lib/sh/strstr.c b/lib/sh/strstr.c index c41e903..c43b05e 100644 --- a/lib/sh/strstr.c +++ b/lib/sh/strstr.c @@ -1,19 +1,22 @@ +/* strstr - find a substring within a string */ + /* Copyright (C) 1994, 1999 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 file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + Bash 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. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ /* * My personal strstr() implementation that beats most other algorithms. diff --git a/lib/sh/strtod.c b/lib/sh/strtod.c index cc3bec9..851d99b 100644 --- a/lib/sh/strtod.c +++ b/lib/sh/strtod.c @@ -1,18 +1,22 @@ +/* strtod.c - convert string to double-precision floating-point value. */ + /* Copyright (C) 1991, 1992 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, + Bash 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. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #if HAVE_CONFIG_H # include <config.h> diff --git a/lib/sh/strtoimax.c b/lib/sh/strtoimax.c index e20c4cc..a4170f0 100644 --- a/lib/sh/strtoimax.c +++ b/lib/sh/strtoimax.c @@ -1,19 +1,22 @@ -/* Convert string representation of a number into an intmax_t value. - Copyright 1999-2005 Free Software Foundation, Inc. +/* strtoimax - convert string representation of a number into an intmax_t value. */ - This program is free software; you can redistribute it and/or modify +/* Copyright 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, + Bash 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. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ /* Written by Paul Eggert. Modified by Chet Ramey for Bash. */ @@ -25,6 +28,10 @@ # include <inttypes.h> #endif +#if HAVE_STDINT_H +# include <stdint.h> +#endif + #if HAVE_STDLIB_H # include <stdlib.h> #endif diff --git a/lib/sh/strtol.c b/lib/sh/strtol.c index 2adbb89..8aa7478 100644 --- a/lib/sh/strtol.c +++ b/lib/sh/strtol.c @@ -1,21 +1,22 @@ -/* Convert string representation of a number into an integer value. - Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. +/* strtol - convert string representation of a number into a long integer value. */ - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. +/* Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001 Free Software Foundation, Inc. - The GNU C Library is distributed in the hope that it will be useful, + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 - Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/strtoll.c b/lib/sh/strtoll.c index 2000497..f6060ee 100644 --- a/lib/sh/strtoll.c +++ b/lib/sh/strtoll.c @@ -1,18 +1,22 @@ +/* strtoll - convert string representation of a number into a long long value. */ + /* Copyright (C) 1997 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 file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + Bash 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. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/strtoul.c b/lib/sh/strtoul.c index 4a75d76..cbaa484 100644 --- a/lib/sh/strtoul.c +++ b/lib/sh/strtoul.c @@ -1,18 +1,22 @@ +/* strtoul - convert string representation of a number into an unsigned long value. */ + /* Copyright (C) 1997 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 file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + Bash 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. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/strtoull.c b/lib/sh/strtoull.c index 09a2fac..02ddebb 100644 --- a/lib/sh/strtoull.c +++ b/lib/sh/strtoull.c @@ -1,18 +1,22 @@ +/* strtoull - convert string representation of a number into an unsigned long long value. */ + /* Copyright (C) 1997 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 file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + Bash 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. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/strtoumax.c b/lib/sh/strtoumax.c index e723d49..09423ad 100644 --- a/lib/sh/strtoumax.c +++ b/lib/sh/strtoumax.c @@ -1,19 +1,22 @@ -/* Convert string representation of a number into an uintmax_t value. - Copyright 1999-2005 Free Software Foundation, Inc. +/* strtoumax - convert string representation of a number into an uintmax_t value. */ - This program is free software; you can redistribute it and/or modify +/* Copyright 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, + Bash 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. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ /* Written by Paul Eggert. Modified by Chet Ramey for Bash. */ @@ -25,6 +28,10 @@ # include <inttypes.h> #endif +#if HAVE_STDINT_H +# include <stdint.h> +#endif + #if HAVE_STDLIB_H # include <stdlib.h> #endif diff --git a/lib/sh/strtrans.c b/lib/sh/strtrans.c index 1f0290e..355a306 100644 --- a/lib/sh/strtrans.c +++ b/lib/sh/strtrans.c @@ -1,24 +1,22 @@ -/* strtrans.c - Translate and untranslate strings with ANSI-C escape - sequences. */ +/* strtrans.c - Translate and untranslate strings with ANSI-C escape sequences. */ -/* Copyright (C) 2000 - Free Software Foundation, Inc. +/* Copyright (C) 2000 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/times.c b/lib/sh/times.c index 7136cf2..47ddf57 100644 --- a/lib/sh/times.c +++ b/lib/sh/times.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/timeval.c b/lib/sh/timeval.c index f7f624e..7bd9df8 100644 --- a/lib/sh/timeval.c +++ b/lib/sh/timeval.c @@ -4,19 +4,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c index 5f2279d..a87c254 100644 --- a/lib/sh/tmpfile.c +++ b/lib/sh/tmpfile.c @@ -6,19 +6,19 @@ This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free - Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> @@ -91,6 +91,9 @@ get_tmpdir (flags) char *tdir; tdir = (flags & MT_USETMPDIR) ? get_string_value ("TMPDIR") : (char *)NULL; + if (tdir && (file_iswdir (tdir) == 0 || strlen (tdir) > PATH_MAX)) + tdir = 0; + if (tdir == 0) tdir = get_sys_tmpdir (); diff --git a/lib/sh/uconvert.c b/lib/sh/uconvert.c new file mode 100644 index 0000000..3d656df --- /dev/null +++ b/lib/sh/uconvert.c @@ -0,0 +1,116 @@ +/* uconvert - convert string representations of decimal numbers into whole + number/fractional value pairs. */ + +/* Copyright (C) 2008,2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "config.h" + +#include "bashtypes.h" + +#if defined (TIME_WITH_SYS_TIME) +# include <sys/time.h> +# include <time.h> +#else +# if defined (HAVE_SYS_TIME_H) +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif + +#if defined (HAVE_UNISTD_H) +#include <unistd.h> +#endif + +#include <stdio.h> +#include "chartypes.h" + +#include "shell.h" +#include "builtins.h" + +#define DECIMAL '.' /* XXX - should use locale */ + +#define RETURN(x) \ +do { \ + if (ip) *ip = ipart * mult; \ + if (up) *up = upart; \ + return (x); \ +} while (0) + +/* + * An incredibly simplistic floating point converter. + */ +static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 }; + +/* Take a decimal number int-part[.[micro-part]] and convert it to the whole + and fractional portions. The fractional portion is returned in + millionths (micro); callers are responsible for multiplying appropriately. + Return 1 if value converted; 0 if invalid integer for either whole or + fractional parts. */ +int +uconvert(s, ip, up) + char *s; + long *ip, *up; +{ + int n, mult; + long ipart, upart; + char *p; + + ipart = upart = 0; + mult = 1; + + if (s && (*s == '-' || *s == '+')) + { + mult = (*s == '-') ? -1 : 1; + p = s + 1; + } + else + p = s; + + for ( ; p && *p; p++) + { + if (*p == DECIMAL) /* decimal point */ + break; + if (DIGIT(*p) == 0) + RETURN(0); + ipart = (ipart * 10) + (*p - '0'); + } + + if (p == 0 || *p == 0) /* callers ensure p can never be 0; this is to shut up clang */ + RETURN(1); + + if (*p == DECIMAL) + p++; + + /* Look for up to six digits past a decimal point. */ + for (n = 0; n < 6 && p[n]; n++) + { + if (DIGIT(p[n]) == 0) + RETURN(0); + upart = (upart * 10) + (p[n] - '0'); + } + + /* Now convert to millionths */ + upart *= multiplier[n]; + + if (n == 6 && p[6] >= '5' && p[6] <= '9') + upart++; /* round up 1 */ + + RETURN(1); +} diff --git a/lib/sh/ufuncs.c b/lib/sh/ufuncs.c new file mode 100644 index 0000000..ed526fe --- /dev/null +++ b/lib/sh/ufuncs.c @@ -0,0 +1,104 @@ +/* ufuncs - sleep and alarm functions that understand fractional values */ + +/* Copyright (C) 2008,2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "config.h" + +#include "bashtypes.h" + +#if defined (TIME_WITH_SYS_TIME) +# include <sys/time.h> +# include <time.h> +#else +# if defined (HAVE_SYS_TIME_H) +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif + +#if defined (HAVE_UNISTD_H) +#include <unistd.h> +#endif + +/* A version of `alarm' using setitimer if it's available. */ + +#if defined (HAVE_SETITIMER) +unsigned int +falarm(secs, usecs) + unsigned int secs, usecs; +{ + struct itimerval it, oit; + + it.it_interval.tv_sec = 0; + it.it_interval.tv_usec = 0; + + it.it_value.tv_sec = secs; + it.it_value.tv_usec = usecs; + + if (setitimer(ITIMER_REAL, &it, &oit) < 0) + return (-1); /* XXX will be converted to unsigned */ + + /* Backwards compatibility with alarm(3) */ + if (oit.it_value.tv_usec) + oit.it_value.tv_sec++; + return (oit.it_value.tv_sec); +} +#else +int +falarm (secs, usecs) + unsigned int secs, usecs; +{ + if (secs == 0 && usecs == 0) + return (alarm (0)); + + if (secs == 0 || usecs >= 500000) + { + secs++; + usecs = 0; + } + return (alarm (secs)); +} +#endif /* !HAVE_SETITIMER */ + +/* A version of sleep using fractional seconds and select. I'd like to use + `usleep', but it's already taken */ + +#if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) +int +fsleep(sec, usec) + unsigned int sec, usec; +{ + struct timeval tv; + + tv.tv_sec = sec; + tv.tv_usec = usec; + + return select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv); +} +#else /* !HAVE_TIMEVAL || !HAVE_SELECT */ +int +fsleep(sec, usec) + long sec, usec; +{ + if (usec >= 500000) /* round */ + sec++; + return (sleep(sec)); +} +#endif /* !HAVE_TIMEVAL || !HAVE_SELECT */ diff --git a/lib/sh/vprint.c b/lib/sh/vprint.c index 929bdbc..567fba3 100644 --- a/lib/sh/vprint.c +++ b/lib/sh/vprint.c @@ -2,21 +2,21 @@ /* Copyright (C) 1987,1989 Free Software Foundation, Inc. -This file is part of GNU Bash, the Bourne Again SHell. + This file is part of GNU Bash, the Bourne Again SHell. -Bash 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. + Bash 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. -Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software -Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/wcsdup.c b/lib/sh/wcsdup.c index e045307..62a3c86 100644 --- a/lib/sh/wcsdup.c +++ b/lib/sh/wcsdup.c @@ -1,22 +1,22 @@ -/* wcsdup.c - wcsdup(3) library function */ +/* wcsdup.c - duplicate wide character string */ /* Copyright (C) 2006 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/winsize.c b/lib/sh/winsize.c index f4696de..64a9858 100644 --- a/lib/sh/winsize.c +++ b/lib/sh/winsize.c @@ -1,22 +1,22 @@ -/* Handle window size changes and information. */ +/* winsize.c - handle window size changes and information. */ /* Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include "config.h" @@ -30,16 +30,29 @@ #include <sys/ioctl.h> -#if !defined (STRUCT_WINSIZE_IN_SYS_IOCTL) -/* For struct winsize on SCO */ -/* sys/ptem.h has winsize but needs mblk_t from sys/stream.h */ -# if defined (HAVE_SYS_PTEM_H) && defined (TIOCGWINSZ) && defined (SIGWINCH) -# if defined (HAVE_SYS_STREAM_H) -# include <sys/stream.h> -# endif +/* Try to find the definitions of `struct winsize' and TIOGCWINSZ */ + +#if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ) +# include <sys/ioctl.h> +#endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */ + +#if defined (STRUCT_WINSIZE_IN_TERMIOS) && !defined (STRUCT_WINSIZE_IN_SYS_IOCTL) +# include <termios.h> +#endif /* STRUCT_WINSIZE_IN_TERMIOS && !STRUCT_WINSIZE_IN_SYS_IOCTL */ + +/* Not in either of the standard places, look around. */ +#if !defined (STRUCT_WINSIZE_IN_TERMIOS) && !defined (STRUCT_WINSIZE_IN_SYS_IOCTL) +# if defined (HAVE_SYS_STREAM_H) +# include <sys/stream.h> +# endif /* HAVE_SYS_STREAM_H */ +# if defined (HAVE_SYS_PTEM_H) /* SVR4.2, at least, has it here */ # include <sys/ptem.h> -# endif /* HAVE_SYS_PTEM_H && TIOCGWINSZ && SIGWINCH */ -#endif /* !STRUCT_WINSIZE_IN_SYS_IOCTL */ +# define _IO_PTEM_H /* work around SVR4.2 1.1.4 bug */ +# endif /* HAVE_SYS_PTEM_H */ +# if defined (HAVE_SYS_PTE_H) /* ??? */ +# include <sys/pte.h> +# endif /* HAVE_SYS_PTE_H */ +#endif /* !STRUCT_WINSIZE_IN_TERMIOS && !STRUCT_WINSIZE_IN_SYS_IOCTL */ #include <stdio.h> diff --git a/lib/sh/zcatfd.c b/lib/sh/zcatfd.c index 24020eb..bdbcd91 100644 --- a/lib/sh/zcatfd.c +++ b/lib/sh/zcatfd.c @@ -1,20 +1,22 @@ +/* zcatfd - copy contents of file descriptor to another */ + /* Copyright (C) 2002 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. + + Bash 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. - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> diff --git a/lib/sh/zgetline.c b/lib/sh/zgetline.c new file mode 100644 index 0000000..33ac830 --- /dev/null +++ b/lib/sh/zgetline.c @@ -0,0 +1,121 @@ +/* zgetline - read a line of input from a specified file descriptor and return + a pointer to a newly-allocated buffer containing the data. */ + +/* Copyright (C) 2008,2009 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#include <sys/types.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + +#include <errno.h> +#include "xmalloc.h" + +#if !defined (errno) +extern int errno; +#endif + +extern ssize_t zread __P((int, char *, size_t)); +extern ssize_t zreadc __P((int, char *)); +extern ssize_t zreadintr __P((int, char *, size_t)); +extern ssize_t zreadcintr __P((int, char *)); + +typedef ssize_t breadfunc_t __P((int, char *, size_t)); +typedef ssize_t creadfunc_t __P((int, char *)); + +/* Initial memory allocation for automatic growing buffer in zreadlinec */ +#define GET_LINE_INITIAL_ALLOCATION 16 + +/* Derived from GNU libc's getline. + The behavior is almost the same as getline. See man getline. + The differences are + (1) using file descriptor instead of FILE *, + (2) the order of arguments; the file descriptor comes the first, and + (3) the addtion of thired argument, UNBUFFERED_READ; this argument + controls whether get_line uses buffering or not to get a byte data + from FD. get_line uses zreadc if UNBUFFERED_READ is zero; and + uses zread if UNBUFFERED_READ is non-zero. + + Returns number of bytes read or -1 on error. */ + +ssize_t +zgetline (fd, lineptr, n, unbuffered_read) + int fd; + char **lineptr; + size_t *n; + int unbuffered_read; +{ + int nr, retval; + char *line, c; + + if (lineptr == 0 || n == 0 || (*lineptr == 0 && *n != 0)) + return -1; + + nr = 0; + line = *lineptr; + + while (1) + { + retval = unbuffered_read ? zread (fd, &c, 1) : zreadc(fd, &c); + + if (retval <= 0) + { + if (line && nr > 0) + line[nr] = '\0'; + break; + } + + if (nr + 2 >= *n) + { + size_t new_size; + + new_size = (*n == 0) ? GET_LINE_INITIAL_ALLOCATION : *n * 2; + line = (*n >= new_size) ? NULL : xrealloc (*lineptr, new_size); + + if (line) + { + *lineptr = line; + *n = new_size; + } + else + { + if (*n > 0) + { + (*lineptr)[*n - 1] = '\0'; + nr = *n - 2; + } + break; + } + } + + line[nr] = c; + nr++; + + if (c == '\n') + { + line[nr] = '\0'; + break; + } + } + + return nr - 1; +} diff --git a/lib/sh/zmapfd.c b/lib/sh/zmapfd.c new file mode 100644 index 0000000..4000c4a --- /dev/null +++ b/lib/sh/zmapfd.c @@ -0,0 +1,90 @@ +/* zmapfd - read contents of file descriptor into a newly-allocated buffer */ + +/* Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#include <sys/types.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + +#include <errno.h> + +#include "bashansi.h" +#include "command.h" +#include "general.h" + +#if !defined (errno) +extern int errno; +#endif + +extern ssize_t zread __P((int, char *, size_t)); + +/* Dump contents of file descriptor FD to *OSTR. FN is the filename for + error messages (not used right now). */ +int +zmapfd (fd, ostr, fn) + int fd; + char **ostr; + char *fn; +{ + ssize_t nr; + int rval; + char lbuf[128]; + char *result; + int rsize, rind; + + rval = 0; + result = (char *)xmalloc (rsize = 64); + rind = 0; + + while (1) + { + nr = zread (fd, lbuf, sizeof (lbuf)); + if (nr == 0) + { + rval = rind; + break; + } + else if (nr < 0) + { + rval = -1; + free (result); + if (ostr) + *ostr = (char *)NULL; + break; + } + + RESIZE_MALLOCED_BUFFER (result, rind, nr, rsize, 128); + memcpy (result+rind, lbuf, nr); + rind += nr; + } + + RESIZE_MALLOCED_BUFFER (result, rind, 1, rsize, 128); + result[rind] = '\0'; + + if (ostr) + *ostr = result; + else + free (result); + + return rval; +} diff --git a/lib/sh/zread.c b/lib/sh/zread.c index 460234b..0fd1199 100644 --- a/lib/sh/zread.c +++ b/lib/sh/zread.c @@ -1,20 +1,22 @@ +/* zread - read data from file descriptor into buffer with retries */ + /* Copyright (C) 1999-2002 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. + Bash 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. + + Bash 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. - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> @@ -58,7 +60,7 @@ zread (fd, buf, len) #define NUM_INTR 3 ssize_t -zreadintr (fd, buf, len) +zreadretry (fd, buf, len) int fd; char *buf; size_t len; @@ -73,7 +75,7 @@ zreadintr (fd, buf, len) return r; if (r == -1 && errno == EINTR) { - if (++nintr > NUM_INTR) + if (++nintr >= NUM_INTR) return -1; continue; } @@ -81,6 +83,16 @@ zreadintr (fd, buf, len) } } +/* Call read(2) and allow it to be interrupted. Just a stub for now. */ +ssize_t +zreadintr (fd, buf, len) + int fd; + char *buf; + size_t len; +{ + return (read (fd, buf, len)); +} + /* Read one character from FD and return it in CP. Return values are as in read(2). This does some local buffering to avoid many one-character calls to read(2), like those the `read' builtin performs. */ @@ -111,6 +123,31 @@ zreadc (fd, cp) return 1; } +/* Don't mix calls to zreadc and zreadcintr in the same function, since they + use the same local buffer. */ +ssize_t +zreadcintr (fd, cp) + int fd; + char *cp; +{ + ssize_t nr; + + if (lind == lused || lused == 0) + { + nr = zreadintr (fd, lbuf, sizeof (lbuf)); + lind = 0; + if (nr <= 0) + { + lused = 0; + return nr; + } + lused = nr; + } + if (cp) + *cp = lbuf[lind++]; + return 1; +} + void zreset () { diff --git a/lib/sh/zwrite.c b/lib/sh/zwrite.c index cf1f9e6..3240f4f 100644 --- a/lib/sh/zwrite.c +++ b/lib/sh/zwrite.c @@ -1,20 +1,22 @@ +/* zwrite - write contents of buffer to file descriptor, retrying on error */ + /* Copyright (C) 1999-2002 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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. - - Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + Bash 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. + + Bash 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 Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include <config.h> |