aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sh')
-rw-r--r--lib/sh/Makefile.in80
-rw-r--r--lib/sh/casemod.c206
-rw-r--r--lib/sh/clktck.c26
-rw-r--r--lib/sh/clock.c26
-rw-r--r--lib/sh/eaccess.c26
-rw-r--r--lib/sh/fdprintf.c70
-rw-r--r--lib/sh/fmtullong.c28
-rw-r--r--lib/sh/fmtulong.c26
-rw-r--r--lib/sh/fmtumax.c28
-rw-r--r--lib/sh/fpurge.c123
-rw-r--r--lib/sh/getcwd.c61
-rw-r--r--lib/sh/getenv.c26
-rw-r--r--lib/sh/inet_aton.c2
-rw-r--r--lib/sh/input_avail.c105
-rw-r--r--lib/sh/itos.c22
-rw-r--r--lib/sh/mailstat.c26
-rw-r--r--lib/sh/makepath.c38
-rw-r--r--lib/sh/mbscmp.c62
-rw-r--r--lib/sh/memset.c19
-rw-r--r--lib/sh/mktime.c32
-rw-r--r--lib/sh/netconn.c19
-rw-r--r--lib/sh/netopen.c20
-rw-r--r--lib/sh/oslib.c26
-rw-r--r--lib/sh/pathcanon.c24
-rw-r--r--lib/sh/pathphys.c24
-rw-r--r--lib/sh/rename.c20
-rw-r--r--lib/sh/setlinebuf.c26
-rw-r--r--lib/sh/shmatch.c30
-rw-r--r--lib/sh/shquote.c28
-rw-r--r--lib/sh/shtty.c108
-rw-r--r--lib/sh/snprintf.c32
-rw-r--r--lib/sh/spell.c48
-rw-r--r--lib/sh/strcasecmp.c26
-rw-r--r--lib/sh/strerror.c26
-rw-r--r--lib/sh/strftime.c6
-rw-r--r--lib/sh/strindex.c25
-rw-r--r--lib/sh/stringlist.c26
-rw-r--r--lib/sh/stringvec.c26
-rw-r--r--lib/sh/strnlen.c18
-rw-r--r--lib/sh/strpbrk.c19
-rw-r--r--lib/sh/strstr.c27
-rw-r--r--lib/sh/strtod.c16
-rw-r--r--lib/sh/strtoimax.c19
-rw-r--r--lib/sh/strtol.c29
-rw-r--r--lib/sh/strtoll.c26
-rw-r--r--lib/sh/strtoul.c26
-rw-r--r--lib/sh/strtoull.c26
-rw-r--r--lib/sh/strtoumax.c20
-rw-r--r--lib/sh/strtrans.c28
-rw-r--r--lib/sh/times.c26
-rw-r--r--lib/sh/timeval.c26
-rw-r--r--lib/sh/tmpfile.c23
-rw-r--r--lib/sh/uconvert.c116
-rw-r--r--lib/sh/ufuncs.c104
-rw-r--r--lib/sh/vprint.c24
-rw-r--r--lib/sh/wcsdup.c24
-rw-r--r--lib/sh/winsize.c24
-rw-r--r--lib/sh/xstrchr.c26
-rw-r--r--lib/sh/zcatfd.c26
-rw-r--r--lib/sh/zgetline.c115
-rw-r--r--lib/sh/zmapfd.c90
-rw-r--r--lib/sh/zread.c28
-rw-r--r--lib/sh/zwrite.c28
63 files changed, 1860 insertions, 646 deletions
diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in
index bf95d19..c8db3a5 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@
@@ -88,8 +89,9 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
shquote.c strtrans.c strindex.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 xstrchr.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
# The header files for this library.
HSOURCES =
@@ -101,8 +103,9 @@ OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o strnlen.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}
+ fmtullong.o fmtumax.o xstrchr.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 ${LIBOBJS}
SUPPORT = Makefile
@@ -134,18 +137,23 @@ ${BUILD_DIR}/version.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile
-( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} version.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
+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
+mbscmp.o: mbscmp.c
memset.o: memset.c
mktime.o: mktime.c
netconn.o: netconn.c
@@ -178,10 +186,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
zcatfd.o: zcatfd.c
+zmapfd.o: zmapfd.c
+zgetline.o: zgetline.c
zread.o: zread.c
zwrite.o: zwrite.c
@@ -193,18 +205,23 @@ 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
+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
+mbscmp.o: ${BUILD_DIR}/config.h
memset.o: ${BUILD_DIR}/config.h
mktime.o: ${BUILD_DIR}/config.h
netconn.o: ${BUILD_DIR}/config.h
@@ -237,10 +254,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
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
@@ -439,6 +460,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
@@ -476,3 +501,26 @@ wcsdup.o: ${topdir}/xmalloc.h
xstrchr.o: ${topdir}/bashansi.h
xstrchr.o: ${BASHINCDIR}/ansi_stdlib.h
xstrchr.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
+
+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
+
diff --git a/lib/sh/casemod.c b/lib/sh/casemod.c
new file mode 100644
index 0000000..83b8ebe
--- /dev/null
+++ b/lib/sh/casemod.c
@@ -0,0 +1,206 @@
+/* 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 0x0
+#define CASE_LOWER 0x01
+#define CASE_UPPER 0x02
+#define CASE_CAPITALIZE 0x04
+#define CASE_UNCAP 0x08
+#define CASE_TOGGLE 0x10
+#define CASE_TOGGLEALL 0x20
+
+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;
+ char *ret, *s;
+ wchar_t wc;
+#if defined (HANDLE_MULTIBYTE)
+ wchar_t nwc;
+ char mb[MB_LEN_MAX+1];
+ int mlen;
+ 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);
+
+ 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;
+ }
+ }
+
+ if (flags == CASE_CAPITALIZE)
+ {
+ nop = inword ? CASE_LOWER : CASE_UPPER;
+ inword = 1;
+ }
+ else if (flags == CASE_UNCAP)
+ {
+ nop = inword ? CASE_UPPER : 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
+ {
+ mbrtowc (&wc, string + start, end - start, &state);
+ 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/fpurge.c b/lib/sh/fpurge.c
new file mode 100644
index 0000000..fd093b8
--- /dev/null
+++ b/lib/sh/fpurge.c
@@ -0,0 +1,123 @@
+/* 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, Solaris >= 7 */
+# include <stdio_ext.h>
+#endif
+#include <stdlib.h>
+
+int
+fpurge (FILE *fp)
+{
+#if HAVE___FPURGE /* glibc >= 2.2, Solaris >= 7 */
+
+ __fpurge (fp);
+ /* The __fpurge function does not have a return value. */
+ return 0;
+
+#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, 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 /* FreeBSD, NetBSD, OpenBSD, 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_ferror_unlocked /* GNU libc, BeOS */
+ 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 /* FreeBSD, NetBSD, OpenBSD, 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 defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
+ /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
+ and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
+# define fp_ub ((struct { struct __sbuf _ub; } *) fp->_ext._base)->_ub
+# else /* FreeBSD, MacOS X, Cygwin */
+# define fp_ub fp->_ub
+# endif
+ if (fp_ub._base != NULL)
+ {
+ if (fp_ub._base != fp->_ubuf)
+ free (fp_ub._base);
+ fp_ub._base = NULL;
+ }
+ return 0;
+# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, 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;
+# else
+ #error "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."
+# endif
+
+#endif
+}
diff --git a/lib/sh/getcwd.c b/lib/sh/getcwd.c
index 1a02794..84799bb 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>
@@ -58,6 +62,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 +200,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;
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..5e01f8f
--- /dev/null
+++ b/lib/sh/input_avail.c
@@ -0,0 +1,105 @@
+/* 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"
+
+#if defined (HAVE_SELECT)
+# if !defined (HAVE_SYS_SELECT_H) || !defined (M_UNIX)
+# include <sys/time.h>
+# endif
+#endif /* HAVE_SELECT */
+#if defined (HAVE_SYS_SELECT_H)
+# include <sys/select.h>
+#endif
+
+#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/mbscmp.c b/lib/sh/mbscmp.c
new file mode 100644
index 0000000..ea01c27
--- /dev/null
+++ b/lib/sh/mbscmp.c
@@ -0,0 +1,62 @@
+/* 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>
+
+/* 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 ((wchar_t *) &c1, mbs1, MB_CUR_MAX);
+ len2 = mbtowc ((wchar_t *) &c2, mbs2, MB_CUR_MAX);
+
+ if (len1 == 0)
+ return len2 == 0 ? 0 : -1;
+ if (len2 == 0)
+ return 1;
+ if (len1 < 0 || len2 < 0)
+ /* FIXME: an illegal character appears. What to do? */
+ return c1 - c2;
+
+ 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 246a01a..c406d4a 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,11 @@
# include <config.h>
#endif
+#if defined(DEBUG)
+# undef HAVE_SNPRINTF
+# undef HAVE_ASPRINTF
+#endif
+
#if defined(DRIVER) && !defined(HAVE_CONFIG_H)
#define HAVE_LONG_LONG
#define HAVE_LONG_DOUBLE
@@ -401,7 +409,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 \
{ \
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/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
index 9172862..5cb80ad 100644
--- a/lib/sh/strindex.c
+++ b/lib/sh/strindex.c
@@ -1,24 +1,23 @@
/* strindex.c - Find if one string appears as a substring of another string,
without regard to case. */
-/* 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/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..373f66a 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-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.
+ 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. */
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..3652b1e 100644
--- a/lib/sh/strtoumax.c
+++ b/lib/sh/strtoumax.c
@@ -1,20 +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-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.
+ 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. */
#if HAVE_CONFIG_H
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..1009565
--- /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)
+ 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..81ebb37 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"
diff --git a/lib/sh/xstrchr.c b/lib/sh/xstrchr.c
index 3272837..6dd4d8e 100644
--- a/lib/sh/xstrchr.c
+++ b/lib/sh/xstrchr.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/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..20069e9
--- /dev/null
+++ b/lib/sh/zgetline.c
@@ -0,0 +1,115 @@
+/* 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 *));
+
+/* 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)
+ {
+ line[nr] = '\0';
+ break;
+ }
+
+ if (nr + 2 >= *n)
+ {
+ size_t new_size;
+
+ new_size = (*n == 0) ? GET_LINE_INITIAL_ALLOCATION : *n * 2;
+ line = 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..94c426f 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 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/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>