Bash-5.3-alpha release

This commit is contained in:
Chet Ramey
2024-04-22 10:33:38 -04:00
parent f3b6bd1945
commit 622d318652
700 changed files with 136534 additions and 96420 deletions
+55 -5
View File
@@ -91,10 +91,11 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.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 mbschr.c zcatfd.c zmapfd.c winsize.c eaccess.c \
wcsdup.c fpurge.c zgetline.c mbscmp.c uconvert.c ufuncs.c \
casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \
wcsdup.c fpurge.c zgetline.c mbscmp.c mbsncmp.c uconvert.c \
ufuncs.c casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \
strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c strdup.c \
strvis.c utf8.c random.c gettimeofday.c timers.c
strvis.c strlcpy.c strscpy.c utf8.c random.c gettimeofday.c \
timers.c anonfile.c reallocarray.c compat.c
# The header files for this library.
HSOURCES =
@@ -107,8 +108,9 @@ OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o strnlen.o \
pathphys.o tmpfile.o stringlist.o stringvec.o spell.o shquote.o \
strtrans.o snprintf.o mailstat.o fmtulong.o \
fmtullong.o fmtumax.o zcatfd.o zmapfd.o winsize.o wcsdup.o \
fpurge.o zgetline.o mbscmp.o uconvert.o ufuncs.o casemod.o \
fpurge.o zgetline.o mbscmp.o mbsncmp.o uconvert.o ufuncs.o casemod.o \
input_avail.o mbscasecmp.o fnxform.o unicode.o shmbchar.o strvis.o \
strscpy.o anonfile.o compat.o \
utf8.o random.o gettimeofday.o timers.o wcsnwidth.o ${LIBOBJS}
SUPPORT = Makefile
@@ -144,9 +146,11 @@ ${BUILD_DIR}/pathnames.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile
-( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} pathnames.h )
# rules for losing makes, like SunOS
anonfile.o: anonfile.c
casemod.o: casemod.c
clktck.o: clktck.c
clock.o: clock.c
compat.o: compat.c
eaccess.o: eaccess.c
dprintf.o: dprintf.c
fmtullong.o: fmtullong.c
@@ -165,6 +169,7 @@ makepath.o: makepath.c
mbscasecmp.o: mbscasecmp.c
mbschr.o: mbschr.c
mbscmp.o: mbscmp.c
mbsncmp.o: mbsncmp.c
memset.o: memset.c
mktime.o: mktime.c
netconn.o: netconn.c
@@ -173,6 +178,7 @@ oslib.o: oslib.c
pathcanon.o: pathcanon.c
pathphys.o: pathphys.c
random.o: random.c
reallocarray.o: reallocarray.c
rename.o: rename.c
setlinebuf.o: setlinebuf.c
shmatch.o: shmatch.c
@@ -199,6 +205,8 @@ strtoull.o: strtoull.c
strtoumax.o: strtoumax.c
strtrans.o: strtrans.c
strvis.o: strvis.c
strlcpy.o: strlcpy.c
strscpy.o: strscpy.c
timers.o: timers.c
times.o: times.c
timeval.o: timeval.c
@@ -226,9 +234,11 @@ strtoul.o: strtol.c
strtoull.o: strtol.c
# all files in the library depend on config.h
anonfile.o: ${BUILD_DIR}/config.h
casemod.o: ${BUILD_DIR}/config.h
clktck.o: ${BUILD_DIR}/config.h
clock.o: ${BUILD_DIR}/config.h
compat.o: ${BUILD_DIR}/config.h
eaccess.o: ${BUILD_DIR}/config.h
dprintf.o: ${BUILD_DIR}/config.h
fmtullong.o: ${BUILD_DIR}/config.h
@@ -247,6 +257,7 @@ makepath.o: ${BUILD_DIR}/config.h
mbscasecmp.o: ${BUILD_DIR}/config.h
mbschr.o: ${BUILD_DIR}/config.h
mbscmp.o: ${BUILD_DIR}/config.h
mbsncmp.o: ${BUILD_DIR}/config.h
memset.o: ${BUILD_DIR}/config.h
mktime.o: ${BUILD_DIR}/config.h
netconn.o: ${BUILD_DIR}/config.h
@@ -255,6 +266,7 @@ oslib.o: ${BUILD_DIR}/config.h
pathcanon.o: ${BUILD_DIR}/config.h
pathphys.o: ${BUILD_DIR}/config.h
random.o: ${BUILD_DIR}/config.h
reallocarray.o: ${BUILD_DIR}/config.h
rename.o: ${BUILD_DIR}/config.h
setlinebuf.o: ${BUILD_DIR}/config.h
shmatch.o: ${BUILD_DIR}/config.h
@@ -281,6 +293,8 @@ strtoull.o: ${BUILD_DIR}/config.h
strtoumax.o: ${BUILD_DIR}/config.h
strtrans.o: ${BUILD_DIR}/config.h
strvis.o: ${BUILD_DIR}/config.h
strlcpy.o: ${BUILD_DIR}/config.h
strscpy.o: ${BUILD_DIR}/config.h
timers.o: ${BUILD_DIR}/config.h
times.o: ${BUILD_DIR}/config.h
timeval.o: ${BUILD_DIR}/config.h
@@ -519,6 +533,14 @@ strvis.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h
strvis.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
strvis.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
strlcpy.o: ${topdir}/bashansi.h
strlcpy.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h
strlcpy.o: ${BASHINCDIR}/typemax.h
strscpy.o: ${topdir}/bashansi.h
strscpy.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h
strscpy.o: ${BASHINCDIR}/typemax.h
times.o: ${BASHINCDIR}/systimes.h
times.o: ${BASHINCDIR}/posixtime.h
@@ -537,7 +559,6 @@ tmpfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
tmpfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
tmpfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
uconvert.o: ${topdir}/bashtypes.h
uconvert.o: ${BASHINCDIR}/chartypes.h
uconvert.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
uconvert.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
@@ -548,6 +569,7 @@ uconvert.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
uconvert.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
ufuncs.o: ${topdir}/bashtypes.h
ufuncs.o: ${BASHINCDIR}/posixtime.h ${BASHINCDIR}/posixselect.h
clock.o: ${BASHINCDIR}/posixtime.h
@@ -606,6 +628,10 @@ mbscmp.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
mbscmp.o: ${BASHINCDIR}/stdc.h
mbscmp.o: ${topdir}/xmalloc.h
mbsncmp.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
mbsncmp.o: ${BASHINCDIR}/stdc.h
mbsncmp.o: ${topdir}/xmalloc.h
casemod.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
casemod.o: ${BASHINCDIR}/stdc.h
casemod.o: ${topdir}/xmalloc.h
@@ -655,3 +681,27 @@ zmapfd.o: ${BASHINCDIR}/stdc.h
zmapfd.o: ${topdir}/command.h
zmapfd.o: ${topdir}/general.h
zmapfd.o: ${topdir}/bashtypes.h ${BASHINCDIR}/chartypes.h ${topdir}/xmalloc.h
anonfile.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
anonfile.o: ${topdir}/bashtypes.h
anonfile.o: ${BASHINCDIR}/filecntl.h
anonfile.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
anonfile.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
anonfile.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${topdir}/conftypes.h
anonfile.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
anonfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
anonfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
anonfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
reallocarray.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
compat.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
compat.o: ${topdir}/bashtypes.h
compat.o: ${BASHINCDIR}/filecntl.h
compat.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
compat.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
compat.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${topdir}/conftypes.h
compat.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
compat.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
compat.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
compat.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
+4 -9
View File
@@ -1,6 +1,6 @@
/* casemod.c -- functions to change case of strings */
/* Copyright (C) 2008-2020 Free Software Foundation, Inc.
/* Copyright (C) 2008-2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -67,7 +67,7 @@
#define CASE_USEWORDS 0x1000 /* modify behavior to act on words in passed string */
extern char *substring PARAMS((char *, int, int));
extern char *substring (char *, int, int);
#ifndef UCHAR_MAX
# define UCHAR_MAX TYPE_MAXIMUM(unsigned char)
@@ -75,9 +75,7 @@ extern char *substring PARAMS((char *, int, int));
#if defined (HANDLE_MULTIBYTE)
static wchar_t
cval (s, i, l)
char *s;
int i, l;
cval (char *s, int i, int l)
{
size_t tmp;
wchar_t wc;
@@ -98,10 +96,7 @@ cval (s, i, l)
/* 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;
sh_modcase (const char *string, char *pat, int flags)
{
int start, next, end, retind;
int inword, c, nc, nop, match, usewords;
+2 -2
View File
@@ -1,6 +1,6 @@
/* clktck.c - get the value of CLK_TCK. */
/* Copyright (C) 1997 Free Software Foundation, Inc.
/* Copyright (C) 1997,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -44,7 +44,7 @@
#endif /* !HAVE_SYSCONF && !_SC_CLK_TCK */
long
get_clk_tck ()
get_clk_tck (void)
{
static long retval = 0;
+9 -16
View File
@@ -1,6 +1,6 @@
/* clock.c - operations on struct tms and clock_t's */
/* Copyright (C) 1999 Free Software Foundation, Inc.
/* Copyright (C) 1999,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -24,10 +24,7 @@
#include <sys/types.h>
#include <posixtime.h>
#if defined (HAVE_SYS_TIMES_H)
# include <sys/times.h>
#endif
#include <systimes.h>
#include <stdio.h>
#include <stdc.h>
@@ -35,16 +32,13 @@
#include <bashintl.h>
#ifndef locale_decpoint
extern int locale_decpoint PARAMS((void));
extern int locale_decpoint (void);
#endif
extern long get_clk_tck PARAMS((void));
extern long get_clk_tck (void);
void
clock_t_to_secs (t, sp, sfp)
clock_t t;
time_t *sp;
int *sfp;
clock_t_to_secs (clock_t t, time_t *sp, long *sfp)
{
static long clk_tck = -1;
@@ -69,19 +63,18 @@ clock_t_to_secs (t, sp, sfp)
terms of the value of CLK_TCK, which is what is returned by the
`times' call. */
void
print_clock_t (fp, t)
FILE *fp;
clock_t t;
print_clock_t (FILE *fp, clock_t t)
{
time_t timestamp;
long minutes;
int seconds, seconds_fraction;
int seconds;
long seconds_fraction;
clock_t_to_secs (t, &timestamp, &seconds_fraction);
minutes = timestamp / 60;
seconds = timestamp % 60;
fprintf (fp, "%ldm%d%c%03ds", minutes, seconds, locale_decpoint(), seconds_fraction);
fprintf (fp, "%ldm%d%c%03lds", minutes, seconds, locale_decpoint(), seconds_fraction);
}
#endif /* HAVE_TIMES */
+3 -15
View File
@@ -1,6 +1,6 @@
/* dprintf -- printf to a file descriptor */
/* Copyright (C) 2008-2010 Free Software Foundation, Inc.
/* Copyright (C) 2008-2010,2022,2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -28,23 +28,11 @@
# include <unistd.h>
#endif
#if defined (PREFER_STDARG)
# include <stdarg.h>
#else
# include <varargs.h>
#endif
#include <stdarg.h>
#include <stdio.h>
int
#if defined (PREFER_STDARG)
dprintf(int fd, const char *format, ...)
#else
dprintf(fd, format, va_alist)
int fd;
const char *format;
va_dcl
#endif
{
FILE *fp;
int fd2, rc, r2;
@@ -59,7 +47,7 @@ dprintf(fd, format, va_alist)
return -1;
}
SH_VA_START (args, format);
va_start (args, format);
rc = vfprintf (fp, format, args);
fflush (fp);
va_end (args);
+11 -20
View File
@@ -1,6 +1,6 @@
/* eaccess.c - eaccess replacement for the shell, plus other access functions. */
/* Copyright (C) 2006-2020 Free Software Foundation, Inc.
/* Copyright (C) 2006-2020,2022-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -52,15 +52,14 @@ extern int errno;
#define F_OK 0
#endif /* R_OK */
static int path_is_devfd PARAMS((const char *));
static int sh_stataccess PARAMS((const char *, int));
static int path_is_devfd (const char *);
static int sh_stataccess (const char *, int);
#if HAVE_DECL_SETREGID
static int sh_euidaccess PARAMS((const char *, int));
static int sh_euidaccess (const char *, int);
#endif
static int
path_is_devfd (path)
const char *path;
path_is_devfd (const char *path)
{
if (path[0] == '/' && path[1] == 'd' && strncmp (path, "/dev/fd/", 8) == 0)
return 1;
@@ -78,9 +77,7 @@ path_is_devfd (path)
/* A wrapper for stat () which disallows pathnames that are empty strings
and handles /dev/fd emulation on systems that don't have it. */
int
sh_stat (path, finfo)
const char *path;
struct stat *finfo;
sh_stat (const char *path, struct stat *finfo)
{
static char *pbuf = 0;
@@ -97,7 +94,7 @@ sh_stat (path, finfo)
intmax_t fd;
int r;
if (legal_number (path + 8, &fd) && fd == (int)fd)
if (valid_number (path + 8, &fd) && fd == (int)fd)
{
r = fstat ((int)fd, finfo);
if (r == 0 || errno != EBADF)
@@ -112,7 +109,7 @@ sh_stat (path, finfo)
effectively a no-op. */
pbuf = xrealloc (pbuf, sizeof (DEV_FD_PREFIX) + strlen (path + 8));
strcpy (pbuf, DEV_FD_PREFIX);
strcat (pbuf, path + 8);
strcpy (pbuf + sizeof (DEV_FD_PREFIX) - 1, path + 8);
return (stat (pbuf, finfo));
#endif /* !HAVE_DEV_FD */
}
@@ -136,9 +133,7 @@ sh_stat (path, finfo)
and don't make the mistake of telling root that any file is
executable. This version uses stat(2). */
static int
sh_stataccess (path, mode)
const char *path;
int mode;
sh_stataccess (const char *path, int mode)
{
struct stat st;
@@ -173,9 +168,7 @@ sh_stataccess (path, mode)
/* Version to call when uid != euid or gid != egid. We temporarily swap
the effective and real uid and gid as appropriate. */
static int
sh_euidaccess (path, mode)
const char *path;
int mode;
sh_euidaccess (const char *path, int mode)
{
int r, e;
@@ -198,9 +191,7 @@ sh_euidaccess (path, mode)
#endif
int
sh_eaccess (path, mode)
const char *path;
int mode;
sh_eaccess (const char *path, int mode)
{
int ret;
+7 -19
View File
@@ -1,6 +1,6 @@
/* fmtulong.c -- Convert unsigned long int to string. */
/* Copyright (C) 1998-2011 Free Software Foundation, Inc.
/* Copyright (C) 1998-2011,2023-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -31,9 +31,6 @@
#endif
#include <bashansi.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
@@ -54,16 +51,12 @@
extern int errno;
#endif
#define x_digs "0123456789abcdef"
#define X_digs "0123456789ABCDEF"
static char const x_digs[16] = "0123456789abcdef";
static char const X_digs[16] = "0123456789ABCDEF";
/* XXX -- assumes uppercase letters, lowercase letters, and digits are
contiguous */
#define FMTCHAR(x) \
((x) < 10) ? (x) + '0' \
: (((x) < 36) ? (x) - 10 + 'a' \
: (((x) < 62) ? (x) - 36 + 'A' \
: (((x) == 62) ? '@' : '_')))
static char * const all_digs = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@_";
#define FMTCHAR(x) all_digs[(x)]
#ifndef FL_PREFIX
# define FL_PREFIX 0x01 /* add 0x, 0X, or 0 prefix as appropriate */
@@ -81,12 +74,7 @@ extern int errno;
base. The caller passes the output buffer and the size. This should
check for buffer underflow, but currently does not. */
char *
fmtulong (ui, base, buf, len, flags)
UNSIGNED_LONG ui;
int base;
char *buf;
size_t len;
int flags;
fmtulong (UNSIGNED_LONG ui, int base, char *buf, size_t len, int flags)
{
char *p;
int sign;
+13 -19
View File
@@ -1,6 +1,6 @@
/* fnxform - use iconv(3) to transform strings to and from "filename" format */
/* Copyright (C) 2009-2020 Free Software Foundation, Inc.
/* Copyright (C) 2009-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -35,9 +35,9 @@
#endif
#if defined (HAVE_LOCALE_CHARSET)
extern const char *locale_charset PARAMS((void));
extern const char *locale_charset (void);
#else
extern char *get_locale_var PARAMS((char *));
extern char *get_locale_var (char *);
#endif
#if defined (HAVE_ICONV)
@@ -49,12 +49,12 @@ static iconv_t conv_tofs = (iconv_t)-1;
static char *outbuf = 0;
static size_t outlen = 0;
static char *curencoding PARAMS((void));
static void init_tofs PARAMS((void));
static void init_fromfs PARAMS((void));
static char *curencoding (void);
static void init_tofs (void);
static void init_fromfs (void);
static char *
curencoding ()
curencoding (void)
{
char *loc;
#if defined (HAVE_LOCALE_CHARSET)
@@ -77,7 +77,7 @@ curencoding ()
}
static void
init_tofs ()
init_tofs (void)
{
char *cur;
@@ -86,7 +86,7 @@ init_tofs ()
}
static void
init_fromfs ()
init_fromfs (void)
{
char *cur;
@@ -95,9 +95,7 @@ init_fromfs ()
}
char *
fnx_tofs (string, len)
char *string;
size_t len;
fnx_tofs (char *string, size_t len)
{
#ifdef MACOSX
ICONV_CONST char *inbuf;
@@ -139,9 +137,7 @@ fnx_tofs (string, len)
}
char *
fnx_fromfs (string, len)
char *string;
size_t len;
fnx_fromfs (char *string, size_t len)
{
#ifdef MACOSX
ICONV_CONST char *inbuf;
@@ -184,15 +180,13 @@ fnx_fromfs (string, len)
#else
char *
fnx_tofs (string)
char *string;
fnx_tofs (char *string, size_t len)
{
return string;
}
char *
fnx_fromfs (string)
char *string;
fnx_fromfs (char *string, size_t len)
{
return string;
}
+2 -2
View File
@@ -1,6 +1,6 @@
/* fpurge - Flushing buffers of a FILE stream. */
/* Copyright (C) 2007-2020 Free Software Foundation, Inc.
/* Copyright (C) 2007-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -29,7 +29,7 @@
#if HAVE_FPURGE
# define fpurge _bash_fpurge
#endif
extern int fpurge PARAMS((FILE *stream));
extern int fpurge (FILE *stream);
#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */
# include <stdio_ext.h>
+2 -16
View File
@@ -1,6 +1,6 @@
/* getcwd.c -- get pathname of current directory */
/* Copyright (C) 1991 Free Software Foundation, Inc.
/* Copyright (C) 1991, 2022, 2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -64,19 +64,12 @@ extern int errno;
# define lstat stat
#endif
#if !defined (NULL)
# 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 (D_FILENO_AVAILABLE)
static int
_path_checkino (dotp, name, thisino)
char *dotp;
char *name;
ino_t thisino;
_path_checkino (const char *dotp, const char *name, ino_t thisino)
{
char *fullpath;
int r, e;
@@ -102,15 +95,8 @@ _path_checkino (dotp, name, thisino)
an array is allocated with `malloc'; the array is SIZE
bytes long, unless SIZE <= 0, in which case it is as
big as necessary. */
#if defined (__STDC__)
char *
getcwd (char *buf, size_t size)
#else /* !__STDC__ */
char *
getcwd (buf, size)
char *buf;
size_t size;
#endif /* !__STDC__ */
{
static const char dots[]
= "../../../../../../../../../../../../../../../../../../../../../../../\
+15 -40
View File
@@ -1,7 +1,7 @@
/* getenv.c - get environment variable value from the shell's variable
list. */
/* Copyright (C) 1997-2002 Free Software Foundation, Inc.
/* Copyright (C) 1997-2002,2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -47,8 +47,7 @@ extern char **environ;
static char *last_tempenv_value = (char *)NULL;
char *
getenv (name)
const char *name;
getenv (const char *name)
{
SHELL_VAR *var;
@@ -71,7 +70,8 @@ getenv (name)
}
else if (environ)
{
register int i, len;
int i;
size_t len;
/* In some cases, s5r3 invokes getenv() before main(); BSD systems
using gprof also exhibit this behavior. This means that
@@ -90,20 +90,14 @@ getenv (name)
/* Some versions of Unix use _getenv instead. */
char *
_getenv (name)
const char *name;
_getenv (const char *name)
{
return (getenv (name));
}
/* SUSv3 says argument is a `char *'; BSD implementations disagree */
int
putenv (str)
#ifndef HAVE_STD_PUTENV
const char *str;
#else
char *str;
#endif
putenv (char *str)
{
SHELL_VAR *var;
char *name, *value;
@@ -142,22 +136,14 @@ putenv (str)
#if 0
int
_putenv (name)
#ifndef HAVE_STD_PUTENV
const char *name;
#else
char *name;
#endif
_putenv (char *name)
{
return putenv (name);
}
#endif
int
setenv (name, value, rewrite)
const char *name;
const char *value;
int rewrite;
setenv (const char *name, const char *value, int rewrite)
{
SHELL_VAR *var;
char *v;
@@ -188,33 +174,22 @@ setenv (name, value, rewrite)
#if 0
int
_setenv (name, value, rewrite)
const char *name;
const char *value;
int rewrite;
_setenv (const char *name, const char *value, int rewrite)
{
return setenv (name, value, rewrite);
}
#endif
/* SUSv3 says unsetenv returns int; existing implementations (BSD) disagree. */
/* SUSv3 says unsetenv returns int; existing implementations (BSD) disagree.
POSIX says int. */
#ifdef HAVE_STD_UNSETENV
#define UNSETENV_RETURN(N) return(N)
#define UNSETENV_RETTYPE int
#else
#define UNSETENV_RETURN(N) return
#define UNSETENV_RETTYPE void
#endif
UNSETENV_RETTYPE
unsetenv (name)
const char *name;
int
unsetenv (const char *name)
{
if (name == 0 || *name == '\0' || strchr (name, '=') != 0)
{
errno = EINVAL;
UNSETENV_RETURN(-1);
return (-1);
}
/* XXX - should we just remove the export attribute here? */
@@ -228,6 +203,6 @@ unsetenv (name)
VUNSETATTR (v, att_exported);
#endif
UNSETENV_RETURN(0);
return (0);
}
#endif /* CAN_REDEFINE_GETENV */
+27 -3
View File
@@ -1,6 +1,6 @@
/* gettimeofday.c - gettimeofday replacement using time() */
/* Copyright (C) 2020 Free Software Foundation, Inc.
/* Copyright (C) 2020, 2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -23,13 +23,37 @@
#if !defined (HAVE_GETTIMEOFDAY)
#include "posixtime.h"
#if HAVE_STDINT_H
#include <stdint.h>
#endif
/* A version of gettimeofday that just sets tv_sec from time(3) */
/* A version of gettimeofday that just sets tv_sec from time(3) on Unix-like
systems that don't have it, or a version for Win32 systems. */
int
gettimeofday (struct timeval *tv, void *tz)
gettimeofday (struct timeval *restrict tv, void *restrict tz)
{
#if !defined (_WIN32)
tv->tv_sec = (time_t) time ((time_t *)0);
tv->tv_usec = 0;
#else
/* EPOCH is the number of 100 nanosecond intervals from
January 1, 1601 (UTC) to January 1, 1970.
(the correct value has 9 trailing zeros) */
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t)file_time.dwLowDateTime);
time += ((uint64_t)file_time.dwHighDateTime) << 32;
tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
#endif
return 0;
}
#endif
+2 -5
View File
@@ -94,8 +94,7 @@ static char rcsid[] = "$Id: inet_addr.c,v 1.5 1996/08/14 03:48:37 drepper Exp $"
* The value returned is in network order.
*/
u_long
inet_addr(cp)
register const char *cp;
inet_addr(const char *cp)
{
struct in_addr val;
@@ -113,9 +112,7 @@ inet_addr(cp)
* cannot distinguish between failure and a local broadcast address.
*/
int
inet_aton(cp, addr)
register const char *cp;
struct in_addr *addr;
inet_aton(const char *cp, struct in_addr *addr)
{
register u_bits32_t val;
register int base, n;
+6 -13
View File
@@ -1,7 +1,7 @@
/* input_avail.c -- check whether or not data is available for reading on a
specified file descriptor. */
/* Copyright (C) 2008,2009-2019 Free Software Foundation, Inc.
/* Copyright (C) 2008,2009-2019,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -33,9 +33,7 @@
# include <sys/file.h>
#endif /* HAVE_SYS_FILE_H */
#if defined (HAVE_PSELECT)
# include <signal.h>
#endif
#include <signal.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
@@ -63,8 +61,7 @@ extern int errno;
/* 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;
input_avail (int fd)
{
int result, chars_avail;
#if defined(HAVE_SELECT)
@@ -102,15 +99,11 @@ input_avail (fd)
/* Wait until NCHARS are available for reading on file descriptor FD.
This can wait indefinitely. Return -1 on error. */
int
nchars_avail (fd, nchars)
int fd;
int nchars;
nchars_avail (int fd, int nchars)
{
int result, chars_avail;
#if defined(HAVE_SELECT)
fd_set readfds, exceptfds;
#endif
#if defined (HAVE_PSELECT) || defined (HAVE_SELECT)
fd_set readfds, exceptfds;
sigset_t set, oset;
#endif
@@ -121,7 +114,7 @@ nchars_avail (fd, nchars)
chars_avail = 0;
#if defined (HAVE_SELECT)
#if defined (HAVE_PSELECT) || defined (HAVE_SELECT)
FD_ZERO (&readfds);
FD_ZERO (&exceptfds);
FD_SET (fd, &readfds);
+5 -14
View File
@@ -30,10 +30,7 @@
#include "shell.h"
char *
inttostr (i, buf, len)
intmax_t i;
char *buf;
size_t len;
inttostr (intmax_t i, char *buf, size_t len)
{
return (fmtumax (i, 10, buf, len, 0));
}
@@ -41,8 +38,7 @@ inttostr (i, buf, len)
/* Integer to string conversion. This conses the string; the
caller should free it. */
char *
itos (i)
intmax_t i;
itos (intmax_t i)
{
char *p, lbuf[INT_STRLEN_BOUND(intmax_t) + 1];
@@ -53,8 +49,7 @@ itos (i)
/* Integer to string conversion. This conses the string using strdup;
caller should free it and be prepared to deal with NULL return. */
char *
mitos (i)
intmax_t i;
mitos (intmax_t i)
{
char *p, lbuf[INT_STRLEN_BOUND(intmax_t) + 1];
@@ -63,10 +58,7 @@ mitos (i)
}
char *
uinttostr (i, buf, len)
uintmax_t i;
char *buf;
size_t len;
uinttostr (uintmax_t i, char *buf, size_t len)
{
return (fmtumax (i, 10, buf, len, FL_UNSIGNED));
}
@@ -74,8 +66,7 @@ uinttostr (i, buf, len)
/* Integer to string conversion. This conses the string; the
caller should free it. */
char *
uitos (i)
uintmax_t i;
uitos (uintmax_t i)
{
char *p, lbuf[INT_STRLEN_BOUND(uintmax_t) + 1];
+2 -4
View File
@@ -1,6 +1,6 @@
/* mailstat.c -- stat a mailbox file, handling maildir-type mail directories */
/* Copyright (C) 2001 Free Software Foundation, Inc.
/* Copyright (C) 2001,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -52,9 +52,7 @@
*/
int
mailstat(path, st)
const char *path;
struct stat *st;
mailstat(const char *path, struct stat *st)
{
static struct stat st_new_last, st_ret_last;
struct stat st_ret, st_tmp;
+4 -10
View File
@@ -1,6 +1,6 @@
/* makepath.c - glue PATH and DIR together into a full pathname. */
/* Copyright (C) 1987-2020 Free Software Foundation, Inc.
/* Copyright (C) 1987-2020,2022-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -32,10 +32,6 @@
#include <tilde/tilde.h>
#ifndef NULL
# define NULL 0
#endif
/* MAKE SURE THESE AGREE WITH ../../externs.h. */
#ifndef MP_DOTILDE
@@ -45,7 +41,7 @@
# define MP_IGNDOT 0x08
#endif
extern char *get_working_directory PARAMS((char *));
extern char *get_working_directory (char *);
static char *nullpath = "";
@@ -67,11 +63,9 @@ static char *nullpath = "";
} while (0)
char *
sh_makepath (path, dir, flags)
const char *path, *dir;
int flags;
sh_makepath (const char *path, const char *dir, int flags)
{
int dirlen, pathlen;
size_t dirlen, pathlen;
char *ret, *xpath, *xdir, *r, *s;
if (path == 0 || *path == '\0')
+10 -11
View File
@@ -1,6 +1,6 @@
/* mbscasecmp - case-insensitive multibyte string comparison. */
/* Copyright (C) 2009-2015 Free Software Foundation, Inc.
/* Copyright (C) 2009-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -31,22 +31,21 @@
/* Compare MBS1 and MBS2 without regard to case. */
int
mbscasecmp (mbs1, mbs2)
const char *mbs1;
const char *mbs2;
mbscasecmp (const char *mbs1, const char *mbs2)
{
int len1, len2, mb_cur_max;
wchar_t c1, c2, l1, l2;
size_t len1, len2;
int mb_cur_max;
wchar_t c1, c2;
wint_t l1, l2;
mbstate_t state1 = { 0 }, state2 = { 0 };
len1 = len2 = 0;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
mb_cur_max = MB_CUR_MAX;
do
{
len1 = mbtowc (&c1, mbs1, mb_cur_max);
len2 = mbtowc (&c2, mbs2, mb_cur_max);
len1 = mbrtowc (&c1, mbs1, mb_cur_max, &state1);
len2 = mbrtowc (&c2, mbs2, mb_cur_max, &state2);
if (len1 == 0)
return len2 == 0 ? 0 : -1;
-6
View File
@@ -39,13 +39,7 @@ extern char *utf8_mbschr (const char *, int); /* XXX */
legacy strchr() might return the wrong value. */
char *
#if defined (PROTOTYPES)
mbschr (const char *s, int c)
#else
mbschr (s, c)
const char *s;
int c;
#endif
{
#if HANDLE_MULTIBYTE
char *pos;
+8 -9
View File
@@ -1,6 +1,6 @@
/* mbscmp - multibyte string comparison. */
/* Copyright (C) 1995-2018 Free Software Foundation, Inc.
/* Copyright (C) 1995-2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -26,28 +26,27 @@
#include <stddef.h>
#include <string.h>
#include <wchar.h>
extern int locale_utf8locale;
extern int utf8_mbscmp (const char *, const char *);
/* Compare MBS1 and MBS2. */
int
mbscmp (mbs1, mbs2)
const char *mbs1;
const char *mbs2;
mbscmp (const char *mbs1, const char *mbs2)
{
int len1, len2, mb_cur_max;
wchar_t c1, c2;
mbstate_t state1 = { 0 }, state2 = { 0 };
len1 = len2 = 0;
/* Reset multibyte characters to their initial state. */
(void) mblen ((char *) NULL, 0);
mb_cur_max = MB_CUR_MAX;
do
{
len1 = mbtowc (&c1, mbs1, mb_cur_max);
len2 = mbtowc (&c2, mbs2, mb_cur_max);
len1 = mbrtowc (&c1, mbs1, mb_cur_max, &state1);
len2 = mbrtowc (&c2, mbs2, mb_cur_max, &state2);
if (len1 == 0)
return len2 == 0 ? 0 : -1;
+11 -146
View File
@@ -1,6 +1,6 @@
/* mktime - convert struct tm to a time_t value */
/* Copyright (C) 1993-2020 Free Software Foundation, Inc.
/* Copyright (C) 1993-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Contributed by Paul Eggert (eggert@twinsun.com).
@@ -56,14 +56,6 @@
#define mktime my_mktime
#endif /* DEBUG_MKTIME */
#ifndef PARAMS
#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
#define PARAMS(args) args
#else
#define PARAMS(args) ()
#endif /* GCC. */
#endif /* Not PARAMS. */
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
@@ -117,17 +109,15 @@ const unsigned short int __mon_yday[2][13] =
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
};
static time_t ydhms_tm_diff PARAMS ((int, int, int, int, int, const struct tm *));
time_t __mktime_internal PARAMS ((struct tm *,
static time_t ydhms_tm_diff (int, int, int, int, int, const struct tm *);
time_t __mktime_internal (struct tm *,
struct tm *(*) (const time_t *, struct tm *),
time_t *));
time_t *);
static struct tm *my_localtime_r PARAMS ((const time_t *, struct tm *));
static struct tm *my_localtime_r (const time_t *, struct tm *);
static struct tm *
my_localtime_r (t, tp)
const time_t *t;
struct tm *tp;
my_localtime_r (const time_t *t, struct tm *tp)
{
struct tm *l = localtime (t);
if (! l)
@@ -136,16 +126,13 @@ my_localtime_r (t, tp)
return tp;
}
/* Yield the difference between (YEAR-YDAY HOUR:MIN:SEC) and (*TP),
measured in seconds, ignoring leap seconds.
YEAR uses the same numbering as TM->tm_year.
All values are in range, except possibly YEAR.
If overflow occurs, yield the low order bits of the correct answer. */
static time_t
ydhms_tm_diff (year, yday, hour, min, sec, tp)
int year, yday, hour, min, sec;
const struct tm *tp;
ydhms_tm_diff (int year, int yday, int hour, int min, int sec, const struct tm *tp)
{
/* Compute intervening leap days correctly even if year is negative.
Take care to avoid int overflow. time_t overflow is OK, since
@@ -167,13 +154,11 @@ ydhms_tm_diff (year, yday, hour, min, sec, tp)
+ (sec - tp->tm_sec));
}
static time_t localtime_offset;
/* Convert *TP to a time_t value. */
time_t
mktime (tp)
struct tm *tp;
mktime (struct tm *tp)
{
#ifdef _LIBC
/* POSIX.1 8.1.1 requires that whenever mktime() is called, the
@@ -191,10 +176,9 @@ mktime (tp)
compared to what the result would be for UTC without leap seconds.
If *OFFSET's guess is correct, only one CONVERT call is needed. */
time_t
__mktime_internal (tp, convert, offset)
struct tm *tp;
struct tm *(*convert) PARAMS ((const time_t *, struct tm *));
time_t *offset;
__mktime_internal (struct tm *tp,
struct tm *(*convert) (const time_t *, struct tm *),
time_t *offset)
{
time_t t, dt, t0;
struct tm tm;
@@ -317,122 +301,3 @@ __mktime_internal (tp, convert, offset)
#ifdef weak_alias
weak_alias (mktime, timelocal)
#endif
#if DEBUG_MKTIME
static int
not_equal_tm (a, b)
struct tm *a;
struct tm *b;
{
return ((a->tm_sec ^ b->tm_sec)
| (a->tm_min ^ b->tm_min)
| (a->tm_hour ^ b->tm_hour)
| (a->tm_mday ^ b->tm_mday)
| (a->tm_mon ^ b->tm_mon)
| (a->tm_year ^ b->tm_year)
| (a->tm_mday ^ b->tm_mday)
| (a->tm_yday ^ b->tm_yday)
| (a->tm_isdst ^ b->tm_isdst));
}
static void
print_tm (tp)
struct tm *tp;
{
printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d",
tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday,
tp->tm_hour, tp->tm_min, tp->tm_sec,
tp->tm_yday, tp->tm_wday, tp->tm_isdst);
}
static int
check_result (tk, tmk, tl, tml)
time_t tk;
struct tm tmk;
time_t tl;
struct tm tml;
{
if (tk != tl || not_equal_tm (&tmk, &tml))
{
printf ("mktime (");
print_tm (&tmk);
printf (")\nyields (");
print_tm (&tml);
printf (") == %ld, should be %ld\n", (long) tl, (long) tk);
return 1;
}
return 0;
}
int
main (argc, argv)
int argc;
char **argv;
{
int status = 0;
struct tm tm, tmk, tml;
time_t tk, tl;
char trailer;
if ((argc == 3 || argc == 4)
&& (sscanf (argv[1], "%d-%d-%d%c",
&tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer)
== 3)
&& (sscanf (argv[2], "%d:%d:%d%c",
&tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer)
== 3))
{
tm.tm_year -= TM_YEAR_BASE;
tm.tm_mon--;
tm.tm_isdst = argc == 3 ? -1 : atoi (argv[3]);
tmk = tm;
tl = mktime (&tmk);
tml = *localtime (&tl);
printf ("mktime returns %ld == ", (long) tl);
print_tm (&tmk);
printf ("\n");
status = check_result (tl, tmk, tl, tml);
}
else if (argc == 4 || (argc == 5 && strcmp (argv[4], "-") == 0))
{
time_t from = atol (argv[1]);
time_t by = atol (argv[2]);
time_t to = atol (argv[3]);
if (argc == 4)
for (tl = from; tl <= to; tl += by)
{
tml = *localtime (&tl);
tmk = tml;
tk = mktime (&tmk);
status |= check_result (tk, tmk, tl, tml);
}
else
for (tl = from; tl <= to; tl += by)
{
/* Null benchmark. */
tml = *localtime (&tl);
tmk = tml;
tk = tl;
status |= check_result (tk, tmk, tl, tml);
}
}
else
printf ("Usage:\
\t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\
\t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\
\t%s FROM BY TO - # Do not test those values (for benchmark).\n",
argv[0], argv[0], argv[0]);
return status;
}
#endif /* DEBUG_MKTIME */
/*
Local Variables:
compile-command: "gcc -DDEBUG=1 -Wall -O -g mktime.c -o mktime"
End:
*/
+2 -3
View File
@@ -1,6 +1,6 @@
/* netconn.c -- is a particular file descriptor a network connection?. */
/* Copyright (C) 2002-2005 Free Software Foundation, Inc.
/* Copyright (C) 2002-2005,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -41,8 +41,7 @@
/* Is FD a socket or network connection? */
int
isnetconn (fd)
int fd;
isnetconn (int fd)
{
#if defined (HAVE_SYS_SOCKET_H) && defined (HAVE_GETPEERNAME) && !defined (SVR4_2) && !defined (__BEOS__)
int rv;
+17 -32
View File
@@ -5,7 +5,7 @@
* chet@ins.CWRU.Edu
*/
/* Copyright (C) 1987-2020 Free Software Foundation, Inc.
/* Copyright (C) 1987-2020,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -63,27 +63,25 @@ extern int errno;
#endif
#if !defined (HAVE_INET_ATON)
extern int inet_aton PARAMS((const char *, struct in_addr *));
extern int inet_aton (const char *, struct in_addr *);
#endif
#ifndef HAVE_GETADDRINFO
static int _getaddr PARAMS((char *, struct in_addr *));
static int _getserv PARAMS((char *, int, unsigned short *));
static int _netopen4 PARAMS((char *, char *, int));
static int _getaddr (const char *, struct in_addr *);
static int _getserv (const char *, int, unsigned short *);
static int _netopen4 (const char *, const char *, int);
#else /* HAVE_GETADDRINFO */
static int _netopen6 PARAMS((char *, char *, int));
static int _netopen6 (const char *, const char *, int);
#endif
static int _netopen PARAMS((char *, char *, int));
static int _netopen (const char *, const char *, int);
#ifndef HAVE_GETADDRINFO
/* Stuff the internet address corresponding to HOST into AP, in network
byte order. Return 1 on success, 0 on failure. */
static int
_getaddr (host, ap)
char *host;
struct in_addr *ap;
_getaddr (const char *host, struct in_addr *ap)
{
struct hostent *h;
int r;
@@ -114,15 +112,12 @@ _getaddr (host, ap)
/* Return 1 if SERV is a valid port number and stuff the converted value into
PP in network byte order. */
static int
_getserv (serv, proto, pp)
char *serv;
int proto;
unsigned short *pp;
_getserv (const char *serv, int proto, unsigned short *pp)
{
intmax_t l;
unsigned short s;
if (legal_number (serv, &l))
if (valid_number (serv, &l))
{
s = (unsigned short)(l & 0xFFFF);
if (s != l)
@@ -154,9 +149,7 @@ _getserv (serv, proto, pp)
* traditional BSD mechanisms. Returns the connected socket or -1 on error.
*/
static int
_netopen4(host, serv, typ)
char *host, *serv;
int typ;
_netopen4(const char *host, const char *serv, int typ)
{
struct in_addr ina;
struct sockaddr_in sin;
@@ -209,9 +202,7 @@ _netopen4(host, serv, typ)
* on error.
*/
static int
_netopen6 (host, serv, typ)
char *host, *serv;
int typ;
_netopen6 (const char *host, const char *serv, int typ)
{
int s, e;
struct addrinfo hints, *res, *res0;
@@ -274,9 +265,7 @@ _netopen6 (host, serv, typ)
* Returns the connected socket or -1 on error.
*/
static int
_netopen(host, serv, typ)
char *host, *serv;
int typ;
_netopen(const char *host, const char *serv, int typ)
{
#ifdef HAVE_GETADDRINFO
return (_netopen6 (host, serv, typ));
@@ -290,8 +279,7 @@ _netopen(host, serv, typ)
* host `host' on port `port' and return the connected socket.
*/
int
netopen (path)
char *path;
netopen (char *path)
{
char *np, *s, *t;
int fd;
@@ -320,8 +308,7 @@ netopen (path)
* `serv' and return the connected socket.
*/
int
tcpopen (host, serv)
char *host, *serv;
tcpopen (char *host, char *serv)
{
return (_netopen (host, serv, 't'));
}
@@ -331,8 +318,7 @@ tcpopen (host, serv)
* `serv' and return the connected socket.
*/
int
udpopen (host, serv)
char *host, *serv;
udpopen (char *host, char *serv)
{
return _netopen (host, serv, 'u');
}
@@ -341,8 +327,7 @@ udpopen (host, serv)
#else /* !HAVE_NETWORK */
int
netopen (path)
char *path;
netopen (char *path)
{
internal_error (_("network operations not supported"));
return -1;
+20 -33
View File
@@ -1,6 +1,6 @@
/* oslib.c - functions present only in some unix versions. */
/* Copyright (C) 1995,2010 Free Software Foundation, Inc.
/* Copyright (C) 1995,2010,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -54,11 +54,9 @@ extern int errno;
/* Make the functions strchr and strrchr if they do not exist. */
#if !defined (HAVE_STRCHR)
char *
strchr (string, c)
char *string;
int c;
strchr (const char *string, int c)
{
register char *s;
char *s;
for (s = string; s && *s; s++)
if (*s == c)
@@ -68,13 +66,11 @@ strchr (string, c)
}
char *
strrchr (string, c)
char *string;
int c;
strrchr (const char *string, int c)
{
register char *s, *t;
char *s, *t;
for (s = string, t = (char *)NULL; s && *s; s++)
for (s = string, t = NULL; s && *s; s++)
if (*s == c)
t = s;
return (t);
@@ -85,8 +81,7 @@ strrchr (string, c)
/* Replacement for dup2 (), for those systems which either don't have it,
or supply one with broken behaviour. */
int
dup2 (fd1, fd2)
int fd1, fd2;
dup2 (int fd1, int fd2)
{
int saved_errno, r;
@@ -143,7 +138,7 @@ dup2 (fd1, fd2)
#if !defined (HAVE_GETDTABLESIZE)
int
getdtablesize ()
getdtablesize (void)
{
# if defined (_POSIX_VERSION) && defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
return (sysconf(_SC_OPEN_MAX)); /* Posix systems use sysconf */
@@ -166,9 +161,7 @@ getdtablesize ()
# undef bcopy
# endif
void
bcopy (s,d,n)
void *d, *s;
size_t n;
bcopy (void *s, void *d, size_t n)
{
FASTCOPY (s, d, n);
}
@@ -179,9 +172,7 @@ bcopy (s,d,n)
# undef bzero
# endif
void
bzero (s, n)
void *s;
size_t n;
bzero (void *s, size_t n)
{
register int i;
register char *r;
@@ -195,9 +186,7 @@ bzero (s, n)
# if defined (HAVE_UNAME)
# include <sys/utsname.h>
int
gethostname (name, namelen)
char *name;
size_t namelen;
gethostname (char *name, size_t namelen)
{
int i;
struct utsname ut;
@@ -212,9 +201,7 @@ gethostname (name, namelen)
}
# else /* !HAVE_UNAME */
int
gethostname (name, namelen)
char *name;
size_t namelen;
gethostname (char *name, size_t namelen)
{
strncpy (name, "unknown", namelen);
name[namelen] = '\0';
@@ -225,9 +212,7 @@ gethostname (name, namelen)
#if !defined (HAVE_KILLPG)
int
killpg (pgrp, sig)
pid_t pgrp;
int sig;
killpg (pid_t pgrp, int sig)
{
return (kill (-pgrp, sig));
}
@@ -235,9 +220,7 @@ killpg (pgrp, sig)
#if !defined (HAVE_MKFIFO) && defined (PROCESS_SUBSTITUTION)
int
mkfifo (path, mode)
char *path;
mode_t mode;
mkfifo (char *path, mode_t mode)
{
#if defined (S_IFIFO)
return (mknod (path, (mode | S_IFIFO), 0));
@@ -248,9 +231,10 @@ mkfifo (path, mode)
#endif /* !HAVE_MKFIFO && PROCESS_SUBSTITUTION */
#define DEFAULT_MAXGROUPS 64
#define MIN_MAXGROUPS 32 /* work around macOS issue */
int
getmaxgroups ()
getmaxgroups (void)
{
static int maxgroups = -1;
@@ -274,11 +258,14 @@ getmaxgroups ()
if (maxgroups <= 0)
maxgroups = DEFAULT_MAXGROUPS;
if (maxgroups < MIN_MAXGROUPS)
maxgroups = MIN_MAXGROUPS;
return maxgroups;
}
long
getmaxchild ()
getmaxchild (void)
{
static long maxchild = -1L;
+5 -9
View File
@@ -1,6 +1,6 @@
/* pathcanon.c -- canonicalize and manipulate pathnames. */
/* Copyright (C) 2000 Free Software Foundation, Inc.
/* Copyright (C) 2000,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -45,9 +45,8 @@ extern int errno;
#if defined (__CYGWIN__)
#include <sys/cygwin.h>
static int
_is_cygdrive (path)
char *path;
static inline int
_is_cygdrive (char *path)
{
static char user[MAXPATHLEN];
static char system[MAXPATHLEN];
@@ -72,8 +71,7 @@ _is_cygdrive (path)
/* Return 1 if PATH corresponds to a directory. A function for debugging. */
static int
_path_isdir (path)
char *path;
_path_isdir (char *path)
{
int l;
struct stat sb;
@@ -101,9 +99,7 @@ _path_isdir (path)
#define DOUBLE_SLASH(p) ((p[0] == '/') && (p[1] == '/') && p[2] != '/')
char *
sh_canonpath (path, flags)
char *path;
int flags;
sh_canonpath (char *path, int flags)
{
char stub_char;
char *result, *p, *q, *base, *dotdot;
+17 -26
View File
@@ -1,6 +1,6 @@
/* pathphys.c -- return pathname with all symlinks expanded. */
/* Copyright (C) 2000-2020 Free Software Foundation, Inc.
/* Copyright (C) 2000-2020,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -46,13 +46,10 @@
extern int errno;
#endif /* !errno */
extern char *get_working_directory PARAMS((char *));
extern char *get_working_directory (char *);
static int
_path_readlink (path, buf, bufsiz)
char *path;
char *buf;
int bufsiz;
static inline ssize_t
_path_readlink (char *path, char *buf, size_t bufsiz)
{
#ifdef HAVE_READLINK
return readlink (path, buf, bufsiz);
@@ -72,13 +69,17 @@ _path_readlink (path, buf, bufsiz)
*/
char *
sh_physpath (path, flags)
char *path;
int flags;
sh_physpath (char *path, int flags)
{
char tbuf[PATH_MAX+1], linkbuf[PATH_MAX+1];
char *result, *p, *q, *qsave, *qbase, *workpath;
int double_slash_path, linklen, nlink;
int double_slash_path, nlink;
ssize_t r;
size_t linklen;
#ifdef __CYGWIN__
return realpath (path, NULL);
#endif
linklen = strlen (path);
@@ -103,13 +104,8 @@ sh_physpath (path, flags)
/* This always gets an absolute pathname. */
/* POSIX.2 says to leave a leading `//' alone. On cygwin, we skip over any
leading `x:' (dos drive name). */
#if defined (__CYGWIN__)
qbase = (ISALPHA((unsigned char)workpath[0]) && workpath[1] == ':') ? workpath + 3 : workpath + 1;
#else
/* POSIX.2 says to leave a leading `//' alone. */
qbase = workpath + 1;
#endif
double_slash_path = DOUBLE_SLASH (workpath);
qbase += double_slash_path;
@@ -164,13 +160,14 @@ sh_physpath (path, flags)
*q = '\0';
linklen = _path_readlink (result, linkbuf, PATH_MAX);
if (linklen < 0) /* if errno == EINVAL, it's not a symlink */
r = _path_readlink (result, linkbuf, PATH_MAX);
if (r < 0) /* if errno == EINVAL, it's not a symlink */
{
if (errno != EINVAL)
goto error;
continue;
}
linklen = r;
/* It's a symlink, and the value is in LINKBUF. */
nlink++;
@@ -214,11 +211,7 @@ error:
{
q = result;
/* Duplicating some code here... */
#if defined (__CYGWIN__)
qbase = (ISALPHA((unsigned char)workpath[0]) && workpath[1] == ':') ? workpath + 3 : workpath + 1;
#else
qbase = workpath + 1;
#endif
double_slash_path = DOUBLE_SLASH (workpath);
qbase += double_slash_path;
@@ -252,9 +245,7 @@ error:
}
char *
sh_realpath (pathname, resolved)
const char *pathname;
char *resolved;
sh_realpath (const char *pathname, char *resolved)
{
char *tdir, *wd;
+24 -28
View File
@@ -1,6 +1,6 @@
/* random.c -- Functions for managing 16-bit and 32-bit random numbers. */
/* Copyright (C) 2020 Free Software Foundation, Inc.
/* Copyright (C) 2020,2022,2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -40,31 +40,32 @@ extern time_t shell_start_time;
extern int last_random_value;
static u_bits32_t intrand32 PARAMS((u_bits32_t));
static u_bits32_t genseed PARAMS((void));
static u_bits32_t intrand32 (u_bits32_t);
static u_bits32_t genseed (void);
static u_bits32_t brand32 PARAMS((void));
static void sbrand32 PARAMS((u_bits32_t));
static void perturb_rand32 PARAMS((void));
static u_bits32_t brand32 (void);
static void sbrand32 (u_bits32_t);
static void perturb_rand32 (void);
/* The random number seed. You can change this by setting RANDOM. */
static u_bits32_t rseed = 1;
/* Returns a 32-bit pseudo-random number. */
static u_bits32_t
intrand32 (last)
u_bits32_t last;
intrand32 (u_bits32_t last)
{
/* Minimal Standard generator from
"Random number generators: good ones are hard to find",
Park and Miller, Communications of the ACM, vol. 31, no. 10,
October 1988, p. 1195. Filtered through FreeBSD.
x(n+1) = 16807 * x(n) mod (m).
x(n+1) = 16807 * x(n) mod (m)
where 16807 == 7^5.
We split up the calculations to avoid overflow.
h = last / q; l = x - h * q; t = a * l - h * r
h = last / q; l = last % q; t = a * l - h * r
m = 2147483647, a = 16807, q = 127773, r = 2836
There are lots of other combinations of constants to use; look at
@@ -76,7 +77,7 @@ intrand32 (last)
/* Can't seed with 0. */
ret = (last == 0) ? 123459876 : last;
h = ret / 127773;
l = ret - (127773 * h);
l = ret % 127773;
t = 16807 * l - 2836 * h;
ret = (t < 0) ? t + 0x7fffffff : t;
@@ -84,13 +85,13 @@ intrand32 (last)
}
static u_bits32_t
genseed ()
genseed (void)
{
struct timeval tv;
u_bits32_t iv;
gettimeofday (&tv, NULL);
iv = (u_bits32_t)seedrand; /* let the compiler truncate */
iv = (uintptr_t)seedrand; /* let the compiler truncate */
iv = tv.tv_sec ^ tv.tv_usec ^ getpid () ^ getppid () ^ current_user.uid ^ iv;
return (iv);
}
@@ -99,7 +100,7 @@ genseed ()
/* Returns a pseudo-random number between 0 and 32767. */
int
brand ()
brand (void)
{
unsigned int ret;
@@ -113,15 +114,14 @@ brand ()
/* Set the random number generator seed to SEED. */
void
sbrand (seed)
unsigned long seed;
sbrand (unsigned long seed)
{
rseed = seed;
last_random_value = 0;
}
void
seedrand ()
seedrand (void)
{
u_bits32_t iv;
@@ -138,7 +138,7 @@ static int urandfd = -1;
/* Returns a 32-bit pseudo-random number between 0 and 4294967295. */
static u_bits32_t
brand32 ()
brand32 (void)
{
u_bits32_t ret;
@@ -147,14 +147,13 @@ brand32 ()
}
static void
sbrand32 (seed)
u_bits32_t seed;
sbrand32 (u_bits32_t seed)
{
last_rand32 = rseed32 = seed;
}
void
seedrand32 ()
seedrand32 (void)
{
u_bits32_t iv;
@@ -163,14 +162,14 @@ seedrand32 ()
}
static void
perturb_rand32 ()
perturb_rand32 (void)
{
rseed32 ^= genseed ();
}
/* Force another attempt to open /dev/urandom on the next call to get_urandom32 */
void
urandom_close ()
urandom_close (void)
{
if (urandfd >= 0)
close (urandfd);
@@ -185,10 +184,7 @@ urandom_close ()
#endif
static ssize_t
getrandom (buf, len, flags)
void *buf;
size_t len;
unsigned int flags;
getrandom (void *buf, size_t len, unsigned int flags)
{
int oflags;
ssize_t r;
@@ -220,7 +216,7 @@ getrandom (buf, len, flags)
#endif
u_bits32_t
get_urandom32 ()
get_urandom32 (void)
{
u_bits32_t ret;
+2 -3
View File
@@ -2,7 +2,7 @@
* rename - rename a file
*/
/* Copyright (C) 1999 Free Software Foundation, Inc.
/* Copyright (C) 1999, 2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -39,8 +39,7 @@ extern int errno;
#endif
int
rename (from, to)
const char *from, *to;
rename (const char *from, const char *to)
{
struct stat fb, tb;
+1 -2
View File
@@ -35,8 +35,7 @@ static char *stderrbuf = 0;
/* Cause STREAM to buffer lines as opposed to characters or blocks. */
int
sh_setlinebuf (stream)
FILE *stream;
sh_setlinebuf (FILE *stream)
{
#if !defined (HAVE_SETLINEBUF) && !defined (HAVE_SETVBUF)
return (0);
+26 -12
View File
@@ -39,27 +39,36 @@
#include "variables.h"
#include "externs.h"
extern int glob_ignore_case, match_ignore_case;
extern int match_ignore_case;
#if defined (ARRAY_VARS)
extern SHELL_VAR *builtin_find_indexed_array (char *, int);
#endif
static char *
strregerror (int err, const regex_t *regex_p)
{
char *str;
size_t size;
size = regerror (err, regex_p, (char *)0, 0);
str = xmalloc (size);
(void)regerror (err, regex_p, str, size);
return str;
}
int
sh_regmatch (string, pattern, flags)
const char *string;
const char *pattern;
int flags;
sh_regmatch (const char *string, const char *pattern, int flags, char **errbuf)
{
regex_t regex = { 0 };
regmatch_t *matches;
int rflags;
int rflags, reg_err;
#if defined (ARRAY_VARS)
SHELL_VAR *rematch;
ARRAY *amatch;
int subexp_ind;
size_t subexp_ind, subexp_len;
char *subexp_str;
int subexp_len;
#endif
int result;
@@ -74,8 +83,12 @@ sh_regmatch (string, pattern, flags)
rflags |= REG_NOSUB;
#endif
if (regcomp (&regex, pattern, rflags))
return 2; /* flag for printing a warning here. */
if (reg_err = regcomp (&regex, pattern, rflags))
{
if (errbuf)
*errbuf = strregerror (reg_err, &regex);
return 2; /* flag for printing a warning here. */
}
#if defined (ARRAY_VARS)
matches = (regmatch_t *)malloc (sizeof (regmatch_t) * (regex.re_nsub + 1));
@@ -85,6 +98,7 @@ sh_regmatch (string, pattern, flags)
/* man regexec: NULL PMATCH ignored if NMATCH == 0 */
if (regexec (&regex, string, matches ? regex.re_nsub + 1 : 0, matches, 0))
/* XXX - catch errors and fill in *errbuf here? */
result = EXECUTION_FAILURE;
else
result = EXECUTION_SUCCESS; /* match */
@@ -96,11 +110,11 @@ sh_regmatch (string, pattern, flags)
/* Store the parenthesized subexpressions in the array BASH_REMATCH.
Element 0 is the portion that matched the entire regexp. Element 1
is the part that matched the first subexpression, and so on. */
#if 1
#if 0
/* This was the pre-bash-5.3 code. */
unbind_global_variable_noref ("BASH_REMATCH");
rematch = make_new_array_variable ("BASH_REMATCH");
#else
/* TAG:bash-5.3 */
rematch = builtin_find_indexed_array ("BASH_REMATCH", 1);
#endif
amatch = rematch ? array_cell (rematch) : (ARRAY *)0;
+4 -9
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2001, 2006, 2009, 2010, 2012, 2015-2018 Free Software Foundation, Inc.
/* Copyright (C) 2001, 2006, 2009, 2010, 2012, 2015-2018, 2022 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
@@ -51,8 +51,7 @@ extern int utf8_mblen (const char *, size_t);
/* Count the number of characters in S, counting multi-byte characters as a
single character. */
size_t
mbstrlen (s)
const char *s;
mbstrlen (const char *s)
{
size_t clen, nc;
mbstate_t mbs = { 0 }, mbsbak = { 0 };
@@ -81,8 +80,7 @@ mbstrlen (s)
/* XXX - if we know that the locale is UTF-8, we can just check whether or
not any byte has the eighth bit turned on */
char *
mbsmbchar (s)
const char *s;
mbsmbchar (const char *s)
{
char *t;
size_t clen;
@@ -115,10 +113,7 @@ mbsmbchar (s)
}
int
sh_mbsnlen(src, srclen, maxlen)
const char *src;
size_t srclen;
int maxlen;
sh_mbsnlen(const char *src, size_t srclen, int maxlen)
{
int count;
int sind;
+21 -33
View File
@@ -1,6 +1,6 @@
/* shquote - functions to quote and dequote strings */
/* Copyright (C) 1999-2020 Free Software Foundation, Inc.
/* Copyright (C) 1999-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -36,8 +36,8 @@
#include "shmbchar.h"
#include "shmbutil.h"
extern char *ansic_quote PARAMS((char *, int, int *));
extern int ansic_shouldquote PARAMS((const char *));
extern char *ansic_quote (char *, int, int *);
extern int ansic_shouldquote (const char *);
/* Default set of characters that should be backslash-quoted in strings */
static const char bstab[256] =
@@ -92,10 +92,9 @@ static const char bstab[256] =
/* Return a new string which is the single-quoted version of STRING.
Used by alias and trap, among others. */
char *
sh_single_quote (string)
const char *string;
sh_single_quote (const char *string)
{
register int c;
int c;
char *result, *r;
const char *s;
@@ -132,10 +131,9 @@ sh_single_quote (string)
/* Quote STRING using double quotes. Return a new string. */
char *
sh_double_quote (string)
const char *string;
sh_double_quote (const char *string)
{
register unsigned char c;
unsigned char c;
int mb_cur_max;
char *result, *r;
size_t slen;
@@ -180,18 +178,17 @@ sh_double_quote (string)
/* Turn S into a simple double-quoted string. If FLAGS is non-zero, quote
double quote characters in S with backslashes. */
char *
sh_mkdoublequoted (s, slen, flags)
const char *s;
int slen, flags;
sh_mkdoublequoted (const char *s, size_t slen, int flags)
{
char *r, *ret;
const char *send;
int rlen, mb_cur_max;
int mb_cur_max;
size_t rlen;
DECLARE_MBSTATE;
send = s + slen;
mb_cur_max = flags ? MB_CUR_MAX : 1;
rlen = (flags == 0) ? slen + 3 : (2 * slen) + 1;
rlen = (flags == 0) ? slen + 3 : (2 * slen) + 3;
ret = r = (char *)xmalloc (rlen);
*r++ = '"';
@@ -220,10 +217,9 @@ sh_mkdoublequoted (s, slen, flags)
double quotes. Return a new string. XXX - should this handle CTLESC
and CTLNUL? */
char *
sh_un_double_quote (string)
char *string;
sh_un_double_quote (char *string)
{
register int c, pass_next;
int c, pass_next;
char *result, *r, *s;
r = result = (char *)xmalloc (strlen (string) + 1);
@@ -259,21 +255,19 @@ sh_un_double_quote (string)
other shell blank characters. */
char *
sh_backslash_quote (string, table, flags)
char *string;
char *table;
int flags;
sh_backslash_quote (char *string, const char *table, int flags)
{
int c, mb_cur_max;
size_t slen;
char *result, *r, *s, *backslash_table, *send;
char *result, *r, *s, *send;
const char *backslash_table;
DECLARE_MBSTATE;
slen = strlen (string);
send = string + slen;
result = (char *)xmalloc (2 * slen + 1);
backslash_table = table ? table : (char *)bstab;
backslash_table = table ? table : bstab;
mb_cur_max = MB_CUR_MAX;
for (r = result, s = string; s && (c = *s); s++)
@@ -315,9 +309,7 @@ sh_backslash_quote (string, table, flags)
/* Quote characters that get special treatment when in double quotes in STRING
using backslashes. FLAGS is reserved for future use. Return a new string. */
char *
sh_backslash_quote_for_double_quotes (string, flags)
char *string;
int flags;
sh_backslash_quote_for_double_quotes (char *string, int flags)
{
unsigned char c;
char *result, *r, *s, *send;
@@ -358,9 +350,7 @@ sh_backslash_quote_for_double_quotes (string, flags)
#endif /* PROMPT_STRING_DECODE */
char *
sh_quote_reusable (s, flags)
char *s;
int flags;
sh_quote_reusable (char *s, int flags)
{
char *ret;
@@ -383,8 +373,7 @@ sh_quote_reusable (s, flags)
}
int
sh_contains_shell_metas (string)
const char *string;
sh_contains_shell_metas (const char *string)
{
const char *s;
@@ -418,8 +407,7 @@ sh_contains_shell_metas (string)
}
int
sh_contains_quotes (string)
const char *string;
sh_contains_quotes (const char *string)
{
const char *s;
+21 -41
View File
@@ -2,7 +2,7 @@
* shtty.c -- abstract interface to the terminal, focusing on capabilities.
*/
/* Copyright (C) 1999 Free Software Foundation, Inc.
/* Copyright (C) 1999, 2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -34,9 +34,7 @@ static TTYSTRUCT ttin, ttout;
static int ttsaved = 0;
int
ttgetattr(fd, ttp)
int fd;
TTYSTRUCT *ttp;
ttgetattr(int fd, TTYSTRUCT *ttp)
{
#ifdef TERMIOS_TTY_DRIVER
return tcgetattr(fd, ttp);
@@ -50,9 +48,7 @@ TTYSTRUCT *ttp;
}
int
ttsetattr(fd, ttp)
int fd;
TTYSTRUCT *ttp;
ttsetattr(int fd, TTYSTRUCT *ttp)
{
#ifdef TERMIOS_TTY_DRIVER
return tcsetattr(fd, TCSADRAIN, ttp);
@@ -66,7 +62,7 @@ TTYSTRUCT *ttp;
}
void
ttsave()
ttsave(void)
{
if (ttsaved)
return;
@@ -76,7 +72,7 @@ ttsave()
}
void
ttrestore()
ttrestore(void)
{
if (ttsaved == 0)
return;
@@ -87,8 +83,7 @@ ttrestore()
/* Retrieve the internally-saved attributes associated with tty fd FD. */
TTYSTRUCT *
ttattr (fd)
int fd;
ttattr (int fd)
{
if (ttsaved == 0)
return ((TTYSTRUCT *)0);
@@ -105,8 +100,7 @@ ttattr (fd)
* ttsetattr, the terminal will be in one-char-at-a-time mode.
*/
int
tt_setonechar(ttp)
TTYSTRUCT *ttp;
tt_setonechar(TTYSTRUCT *ttp)
{
#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
@@ -151,9 +145,7 @@ tt_setonechar(ttp)
/* Set the tty associated with FD and TTP into one-character-at-a-time mode */
int
ttfd_onechar (fd, ttp)
int fd;
TTYSTRUCT *ttp;
ttfd_onechar (int fd, TTYSTRUCT *ttp)
{
if (tt_setonechar(ttp) < 0)
return -1;
@@ -162,7 +154,7 @@ ttfd_onechar (fd, ttp)
/* Set the terminal into one-character-at-a-time mode */
int
ttonechar ()
ttonechar (void)
{
TTYSTRUCT tt;
@@ -177,8 +169,7 @@ ttonechar ()
* ttsetattr, the terminal will be in no-echo mode.
*/
int
tt_setnoecho(ttp)
TTYSTRUCT *ttp;
tt_setnoecho(TTYSTRUCT *ttp)
{
#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
ttp->c_lflag &= ~(ECHO|ECHOK|ECHONL);
@@ -191,9 +182,7 @@ tt_setnoecho(ttp)
/* Set the tty associated with FD and TTP into no-echo mode */
int
ttfd_noecho (fd, ttp)
int fd;
TTYSTRUCT *ttp;
ttfd_noecho (int fd, TTYSTRUCT *ttp)
{
if (tt_setnoecho (ttp) < 0)
return -1;
@@ -202,7 +191,7 @@ ttfd_noecho (fd, ttp)
/* Set the terminal into no-echo mode */
int
ttnoecho ()
ttnoecho (void)
{
TTYSTRUCT tt;
@@ -217,8 +206,7 @@ ttnoecho ()
* ttsetattr, the terminal will be in eight-bit mode (pass8).
*/
int
tt_seteightbit (ttp)
TTYSTRUCT *ttp;
tt_seteightbit (TTYSTRUCT *ttp)
{
#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
ttp->c_iflag &= ~ISTRIP;
@@ -233,9 +221,7 @@ tt_seteightbit (ttp)
/* Set the tty associated with FD and TTP into eight-bit mode */
int
ttfd_eightbit (fd, ttp)
int fd;
TTYSTRUCT *ttp;
ttfd_eightbit (int fd, TTYSTRUCT *ttp)
{
if (tt_seteightbit (ttp) < 0)
return -1;
@@ -244,7 +230,7 @@ ttfd_eightbit (fd, ttp)
/* Set the terminal into eight-bit mode */
int
tteightbit ()
tteightbit (void)
{
TTYSTRUCT tt;
@@ -259,8 +245,7 @@ tteightbit ()
* ttsetattr, the terminal will be in non-canonical input mode.
*/
int
tt_setnocanon (ttp)
TTYSTRUCT *ttp;
tt_setnocanon (TTYSTRUCT *ttp)
{
#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
ttp->c_lflag &= ~ICANON;
@@ -271,9 +256,7 @@ tt_setnocanon (ttp)
/* Set the tty associated with FD and TTP into non-canonical mode */
int
ttfd_nocanon (fd, ttp)
int fd;
TTYSTRUCT *ttp;
ttfd_nocanon (int fd, TTYSTRUCT *ttp)
{
if (tt_setnocanon (ttp) < 0)
return -1;
@@ -282,7 +265,7 @@ ttfd_nocanon (fd, ttp)
/* Set the terminal into non-canonical mode */
int
ttnocanon ()
ttnocanon (void)
{
TTYSTRUCT tt;
@@ -297,8 +280,7 @@ ttnocanon ()
* ttsetattr, the terminal will be in cbreak, no-echo mode.
*/
int
tt_setcbreak(ttp)
TTYSTRUCT *ttp;
tt_setcbreak(TTYSTRUCT *ttp)
{
if (tt_setonechar (ttp) < 0)
return -1;
@@ -308,9 +290,7 @@ tt_setcbreak(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;
ttfd_cbreak (int fd, TTYSTRUCT *ttp)
{
if (tt_setcbreak (ttp) < 0)
return -1;
@@ -319,7 +299,7 @@ ttfd_cbreak (fd, ttp)
/* Set the terminal into cbreak (no-echo, one-character-at-a-time) mode */
int
ttcbreak ()
ttcbreak (void)
{
TTYSTRUCT tt;
+49 -144
View File
@@ -9,7 +9,7 @@
Unix snprintf implementation.
derived from inetutils/libinetutils/snprintf.c Version 1.1
Copyright (C) 2001-2020 Free Software Foundation, Inc.
Copyright (C) 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -77,7 +77,6 @@
#endif
#define HAVE_ISINF_IN_LIBC
#define HAVE_ISNAN_IN_LIBC
#define PREFER_STDARG
#define HAVE_STRINGIZE
#define HAVE_LIMITS_H
#define HAVE_STDDEF_H
@@ -89,19 +88,12 @@
#include <bashtypes.h>
#if defined(PREFER_STDARG)
# include <stdarg.h>
#else
# include <varargs.h>
#endif
#include <stdarg.h>
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#include <bashansi.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#include <chartypes.h>
#ifdef HAVE_STDINT_H
@@ -129,8 +121,8 @@
# define FL_ADDBASE 0x02 /* add base# prefix to converted value */
# define FL_HEXUPPER 0x04 /* use uppercase when converting to hex */
# define FL_UNSIGNED 0x08 /* don't add any sign */
extern char *fmtulong PARAMS((unsigned long int, int, char *, size_t, int));
extern char *fmtullong PARAMS((unsigned long long int, int, char *, size_t, int));
extern char *fmtulong (unsigned long int, int, char *, size_t, int);
extern char *fmtullong (unsigned long long int, int, char *, size_t, int);
#endif
#ifndef FREE
@@ -178,9 +170,6 @@ extern char *fmtullong PARAMS((unsigned long long int, int, char *, size_t, int)
#define ASBUFSIZE 128
#define x_digs "0123456789abcdef"
#define X_digs "0123456789ABCDEF"
static char intbuf[INT_STRLEN_BOUND(unsigned long) + 1];
static int decpoint;
@@ -271,38 +260,38 @@ struct DATA
/* the floating point stuff */
#ifdef FLOATING_POINT
static double pow_10 PARAMS((int));
static int log_10 PARAMS((double));
static double integral PARAMS((double, double *));
static char *numtoa PARAMS((double, int, int, char **));
static double pow_10 (int);
static int log_10 (double);
static double integral (double, double *);
static char *numtoa (double, int, int, char **);
#endif
static void init_data PARAMS((struct DATA *, char *, size_t, const char *, int));
static void init_conv_flag PARAMS((struct DATA *));
static void init_data (struct DATA *, char *, size_t, const char *, int);
static void init_conv_flag (struct DATA *);
/* for the format */
#ifdef FLOATING_POINT
static void floating PARAMS((struct DATA *, double));
static void exponent PARAMS((struct DATA *, double));
static void floating (struct DATA *, double);
static void exponent (struct DATA *, double);
#endif
static void number PARAMS((struct DATA *, unsigned long, int));
static void number (struct DATA *, unsigned long, int);
#ifdef HAVE_LONG_LONG_INT
static void lnumber PARAMS((struct DATA *, unsigned long long, int));
static void lnumber (struct DATA *, unsigned long long, int);
#endif
static void pointer PARAMS((struct DATA *, unsigned long));
static void strings PARAMS((struct DATA *, char *));
static void pointer (struct DATA *, unsigned long);
static void strings (struct DATA *, char *);
#ifdef FLOATING_POINT
# define FALLBACK_FMTSIZE 32
# define FALLBACK_BASE 4096
# define LFALLBACK_BASE 5120
# ifdef HAVE_LONG_DOUBLE
static void ldfallback PARAMS((struct DATA *, const char *, const char *, long double));
static void ldfallback (struct DATA *, const char *, const char *, long double);
# endif
static void dfallback PARAMS((struct DATA *, const char *, const char *, double));
static void dfallback (struct DATA *, const char *, const char *, double);
#endif
static char *groupnum PARAMS((char *));
static char *groupnum (char *);
#if defined (HAVE_LONG_DOUBLE)
# define LONGDOUBLE long double
@@ -331,10 +320,10 @@ static char *groupnum PARAMS((char *));
#endif
#ifdef DRIVER
static void memory_error_and_abort ();
static void *xmalloc PARAMS((size_t));
static void *xrealloc PARAMS((void *, size_t));
static void xfree PARAMS((void *));
static void memory_error_and_abort (void);
static void *xmalloc (size_t);
static void *xrealloc (void *, size_t);
static void xfree (void *);
#else
# include <xmalloc.h>
#endif
@@ -470,8 +459,7 @@ static void xfree PARAMS((void *));
* Find the nth power of 10
*/
static double
pow_10(n)
int n;
pow_10(int n)
{
double P;
@@ -514,8 +502,7 @@ pow_10(n)
* NOTE: do not call this with r == 0 -- an infinite loop results.
*/
static int
log_10(r)
double r;
log_10(double r)
{
int i = 0;
double result = 1.;
@@ -549,9 +536,7 @@ log_10(r)
* In many ways it resemble the modf() found on most Un*x
*/
static double
integral(real, ip)
double real;
double *ip;
integral(double real, double *ip)
{
int j;
double i, s, p;
@@ -598,10 +583,7 @@ integral(real, ip)
* declare with fix size
*/
static char *
numtoa(number, base, precision, fract)
double number;
int base, precision;
char **fract;
numtoa(double number, int base, int precision, char **fract)
{
register int i, j;
double ip, fp; /* integer and fraction part */
@@ -696,10 +678,7 @@ numtoa(number, base, precision, fract)
* the representation with the right padding
*/
static void
number(p, d, base)
struct DATA *p;
unsigned long d;
int base;
number(struct DATA *p, unsigned long d, int base)
{
char *tmp, *t;
long sd;
@@ -772,10 +751,7 @@ number(p, d, base)
* identical to number() but works for `long long'
*/
static void
lnumber(p, d, base)
struct DATA *p;
unsigned long long d;
int base;
lnumber(struct DATA *p, unsigned long long d, int base)
{
char *tmp, *t;
long long sd;
@@ -844,9 +820,7 @@ lnumber(p, d, base)
#endif
static void
pointer(p, d)
struct DATA *p;
unsigned long d;
pointer(struct DATA *p, unsigned long d)
{
char *tmp;
@@ -869,9 +843,7 @@ pointer(p, d)
/* %s strings */
static void
strings(p, tmp)
struct DATA *p;
char *tmp;
strings(struct DATA *p, char *tmp)
{
size_t len;
@@ -886,9 +858,7 @@ strings(p, tmp)
#if HANDLE_MULTIBYTE
/* %ls wide-character strings */
static void
wstrings(p, tmp)
struct DATA *p;
wchar_t *tmp;
wstrings(struct DATA *p, wchar_t *tmp)
{
size_t len;
mbstate_t mbs;
@@ -927,9 +897,7 @@ wstrings(p, tmp)
}
static void
wchars (p, wc)
struct DATA *p;
wint_t wc;
wchars (struct DATA *p, wint_t wc)
{
char *lbuf, *l;
mbstate_t mbs;
@@ -956,10 +924,7 @@ wchars (p, wc)
(mode == 2) we check for NaN. This does the necessary printing. Returns
1 if Inf or Nan, 0 if not. */
static int
chkinfnan(p, d, mode)
struct DATA *p;
double d;
int mode; /* == 1 for inf, == 2 for nan */
chkinfnan(struct DATA *p, double d, int mode)
{
int i;
char *tmp;
@@ -987,9 +952,7 @@ chkinfnan(p, d, mode)
/* %f %F %g %G floating point representation */
static void
floating(p, d)
struct DATA *p;
double d;
floating(struct DATA *p, double d)
{
char *tmp, *tmp2, *t;
int i;
@@ -1058,9 +1021,7 @@ floating(p, d)
/* %e %E %g %G exponent representation */
static void
exponent(p, d)
struct DATA *p;
double d;
exponent(struct DATA *p, double d)
{
char *tmp, *tmp2;
int j, i;
@@ -1160,11 +1121,10 @@ exponent(p, d)
grouping info and thousands separator. If no grouping should be performed,
this returns NULL; the caller needs to check for it. */
static char *
groupnum (s)
char *s;
groupnum (char *s)
{
char *se, *ret, *re, *g;
int len, slen;
size_t len, slen;
if (grouping == 0 || *grouping <= 0 || *grouping == CHAR_MAX)
return ((char *)NULL);
@@ -1221,8 +1181,7 @@ groupnum (s)
/* initialize the conversion specifiers */
static void
init_conv_flag (p)
struct DATA *p;
init_conv_flag (struct DATA *p)
{
p->flags &= PF_ALLOCBUF; /* preserve PF_ALLOCBUF flag */
p->precision = p->width = NOT_FOUND;
@@ -1231,12 +1190,7 @@ init_conv_flag (p)
}
static void
init_data (p, string, length, format, mode)
struct DATA *p;
char *string;
size_t length;
const char *format;
int mode;
init_data (struct DATA *p, char *string, size_t length, const char *format, int mode)
{
p->length = length - 1; /* leave room for '\0' */
p->holder = p->base = string;
@@ -1246,16 +1200,7 @@ init_data (p, string, length, format, mode)
}
static int
#if defined (__STDC__)
vsnprintf_internal(struct DATA *data, char *string, size_t length, const char *format, va_list args)
#else
vsnprintf_internal(data, string, length, format, args)
struct DATA *data;
char *string;
size_t length;
const char *format;
va_list args;
#endif
{
double d; /* temporary holder */
#ifdef HAVE_LONG_DOUBLE
@@ -1639,10 +1584,7 @@ conv_break:
* at it. Fall back to sprintf for long double formats.
*/
static void
ldfallback (data, fs, fe, ld)
struct DATA *data;
const char *fs, *fe;
long double ld;
ldfallback (struct DATA *data, const char *fs, const char *fe, long double ld)
{
register char *x;
char fmtbuf[FALLBACK_FMTSIZE], *obuf;
@@ -1672,10 +1614,7 @@ ldfallback (data, fs, fe, ld)
#ifdef FLOATING_POINT
/* Used for %a, %A if the libc printf supports them. */
static void
dfallback (data, fs, fe, d)
struct DATA *data;
const char *fs, *fe;
double d;
dfallback (struct DATA *data, const char *fs, const char *fe, double d)
{
register char *x;
char fmtbuf[FALLBACK_FMTSIZE], obuf[FALLBACK_BASE];
@@ -1702,15 +1641,7 @@ dfallback (data, fs, fe, d)
#if !HAVE_SNPRINTF
int
#if defined (__STDC__)
vsnprintf(char *string, size_t length, const char *format, va_list args)
#else
vsnprintf(string, length, format, args)
char *string;
size_t length;
const char *format;
va_list args;
#endif
{
struct DATA data;
@@ -1721,21 +1652,13 @@ vsnprintf(string, length, format, args)
}
int
#if defined(PREFER_STDARG)
snprintf(char *string, size_t length, const char * format, ...)
#else
snprintf(string, length, format, va_alist)
char *string;
size_t length;
const char *format;
va_dcl
#endif
{
struct DATA data;
int rval;
va_list args;
SH_VA_START(args, format);
va_start(args, format);
if (string == 0 && length != 0)
return 0;
@@ -1752,14 +1675,7 @@ snprintf(string, length, format, va_alist)
#if !HAVE_ASPRINTF
int
#if defined (__STDC__)
vasprintf(char **stringp, const char *format, va_list args)
#else
vasprintf(stringp, format, args)
char **stringp;
const char *format;
va_list args;
#endif
{
struct DATA data;
char *string;
@@ -1773,19 +1689,12 @@ vasprintf(stringp, format, args)
}
int
#if defined(PREFER_STDARG)
asprintf(char **stringp, const char * format, ...)
#else
asprintf(stringp, format, va_alist)
char **stringp;
const char *format;
va_dcl
#endif
{
int rval;
va_list args;
SH_VA_START(args, format);
va_start(args, format);
rval = vasprintf (stringp, format, args);
@@ -1801,15 +1710,14 @@ asprintf(stringp, format, va_alist)
#ifdef DRIVER
static void
memory_error_and_abort ()
memory_error_and_abort (void)
{
write (2, "out of virtual memory\n", 22);
abort ();
}
static void *
xmalloc(bytes)
size_t bytes;
xmalloc(size_t bytes)
{
void *ret;
@@ -1820,9 +1728,7 @@ xmalloc(bytes)
}
static void *
xrealloc (pointer, bytes)
void *pointer;
size_t bytes;
xrealloc (void *pointer, size_t bytes)
{
void *ret;
@@ -1833,15 +1739,14 @@ xrealloc (pointer, bytes)
}
static void
xfree(x)
void *x;
xfree(void *x)
{
if (x)
free (x);
}
/* set of small tests for snprintf() */
main()
main(int c, char **v)
{
char holder[100];
char *h;
+8 -15
View File
@@ -1,6 +1,6 @@
/* spell.c -- spelling correction for pathnames. */
/* Copyright (C) 2000-2020 Free Software Foundation, Inc.
/* Copyright (C) 2000-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -40,8 +40,8 @@
#include <maxpath.h>
#include <stdc.h>
static int mindist PARAMS((char *, char *, char *));
static int spdist PARAMS((char *, char *));
static int mindist (const char *, char *, char *);
static int spdist (char *, char *);
/*
* `spname' and its helpers are inspired by the code in "The UNIX
@@ -59,9 +59,7 @@ static int spdist PARAMS((char *, char *));
* Stores corrected name in `newname'.
*/
int
spname(oldname, newname)
char *oldname;
char *newname;
spname(char *oldname, char *newname)
{
char *op, *np, *p;
char guess[PATH_MAX + 1], best[PATH_MAX + 1];
@@ -104,10 +102,7 @@ spname(oldname, newname)
* Search directory for a guess
*/
static int
mindist(dir, guess, best)
char *dir;
char *guess;
char *best;
mindist(const char *dir, char *guess, char *best)
{
DIR *fd;
struct dirent *dp;
@@ -155,8 +150,7 @@ mindist(dir, guess, best)
* 3 otherwise
*/
static int
spdist(cur, new)
char *cur, *new;
spdist(char *cur, char *new)
{
while (*cur == *new)
{
@@ -188,10 +182,9 @@ spdist(cur, new)
}
char *
dirspell (dirname)
char *dirname;
dirspell (char *dirname)
{
int n;
size_t n;
char *guess;
n = (strlen (dirname) * 3 + 1) / 2 + 1;
+3 -8
View File
@@ -1,6 +1,6 @@
/* strcasecmp.c - functions for case-insensitive string comparison. */
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995, 2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -29,10 +29,7 @@
/* Compare at most COUNT characters from string1 to string2. Case
doesn't matter. */
int
strncasecmp (string1, string2, count)
const char *string1;
const char *string2;
size_t count;
strncasecmp (const char *string1, const char *string2, size_t count)
{
register const char *s1;
register const char *s2;
@@ -58,9 +55,7 @@ strncasecmp (string1, string2, count)
/* strcmp (), but caseless. */
int
strcasecmp (string1, string2)
const char *string1;
const char *string2;
strcasecmp (const char *string1, const char *string2)
{
register const char *s1;
register const char *s2;
+2 -4
View File
@@ -1,7 +1,7 @@
/* strcasestr.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,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -30,9 +30,7 @@
match in s1. The compare is case insensitive. This is a
case-insensitive strstr(3). */
char *
strcasestr (s1, s2)
const char *s1;
const char *s2;
strcasestr (const char *s1, const char *s2)
{
register int i, l, len, c;
+2 -4
View File
@@ -1,5 +1,5 @@
/* Searching in a string.
Copyright (C) 2012 Free Software Foundation, Inc.
Copyright (C) 2012, 2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,9 +22,7 @@
/* Find the first occurrence of C in S or the final NUL byte. */
char *
strchrnul (s, c_in)
const char *s;
int c_in;
strchrnul (const char *s, int c_in)
{
char c;
register char *s1;
+2 -3
View File
@@ -1,6 +1,6 @@
/* strdup - return a copy of a string in newly-allocated memory. */
/* Copyright (C) 2013 Free Software Foundation, Inc.
/* Copyright (C) 2013,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -26,8 +26,7 @@
/* Duplicate S, returning an identical malloc'd string. */
char *
strdup (s)
const char *s;
strdup (const char *s)
{
size_t len;
void *new;
+2 -3
View File
@@ -1,6 +1,6 @@
/* strerror.c - string corresponding to a particular value of errno. */
/* Copyright (C) 1995 Free Software Foundation, Inc.
/* Copyright (C) 1995,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -49,8 +49,7 @@ extern int errno;
static char *errbase = "Unknown system error ";
char *
strerror (e)
int e;
strerror (int e)
{
static char emsg[40];
#if defined (HAVE_SYS_ERRLIST)
+24 -45
View File
@@ -1,6 +1,6 @@
/* stringlist.c - functions to handle a generic `list of strings' structure */
/* Copyright (C) 2000-2019 Free Software Foundation, Inc.
/* Copyright (C) 2000-2019, 2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -37,11 +37,10 @@
/* Allocate a new STRINGLIST, with room for N strings. */
STRINGLIST *
strlist_create (n)
int n;
strlist_create (size_t n)
{
STRINGLIST *ret;
register int i;
int i;
ret = (STRINGLIST *)xmalloc (sizeof (STRINGLIST));
if (n)
@@ -61,11 +60,9 @@ strlist_create (n)
}
STRINGLIST *
strlist_resize (sl, n)
STRINGLIST *sl;
int n;
strlist_resize (STRINGLIST *sl, size_t n)
{
register int i;
size_t i;
if (sl == 0)
return (sl = strlist_create (n));
@@ -81,8 +78,7 @@ strlist_resize (sl, n)
}
void
strlist_flush (sl)
STRINGLIST *sl;
strlist_flush (STRINGLIST *sl)
{
if (sl == 0 || sl->list == 0)
return;
@@ -91,8 +87,7 @@ strlist_flush (sl)
}
void
strlist_dispose (sl)
STRINGLIST *sl;
strlist_dispose (STRINGLIST *sl)
{
if (sl == 0)
return;
@@ -102,9 +97,7 @@ strlist_dispose (sl)
}
int
strlist_remove (sl, s)
STRINGLIST *sl;
char *s;
strlist_remove (STRINGLIST *sl, const char *s)
{
int r;
@@ -118,11 +111,10 @@ strlist_remove (sl, s)
}
STRINGLIST *
strlist_copy (sl)
STRINGLIST *sl;
strlist_copy (STRINGLIST *sl)
{
STRINGLIST *new;
register int i;
int i;
if (sl == 0)
return ((STRINGLIST *)0);
@@ -144,11 +136,10 @@ strlist_copy (sl)
/* Return a new STRINGLIST with everything from M1 and M2. */
STRINGLIST *
strlist_merge (m1, m2)
STRINGLIST *m1, *m2;
strlist_merge (STRINGLIST *m1, STRINGLIST *m2)
{
STRINGLIST *sl;
int i, n, l1, l2;
size_t i, n, l1, l2;
l1 = m1 ? m1->list_len : 0;
l2 = m2 ? m2->list_len : 0;
@@ -165,10 +156,9 @@ strlist_merge (m1, m2)
/* Make STRINGLIST M1 contain everything in M1 and M2. */
STRINGLIST *
strlist_append (m1, m2)
STRINGLIST *m1, *m2;
strlist_append (STRINGLIST *m1, STRINGLIST *m2)
{
register int i, n, len1, len2;
size_t i, n, len1, len2;
if (m1 == 0)
return (m2 ? strlist_copy (m2) : (STRINGLIST *)0);
@@ -189,11 +179,9 @@ strlist_append (m1, m2)
}
STRINGLIST *
strlist_prefix_suffix (sl, prefix, suffix)
STRINGLIST *sl;
char *prefix, *suffix;
strlist_prefix_suffix (STRINGLIST *sl, const char *prefix, const char *suffix)
{
int plen, slen, tlen, llen, i;
size_t plen, slen, tlen, llen, i;
char *t;
if (sl == 0 || sl->list == 0 || sl->list_len == 0)
@@ -223,11 +211,9 @@ strlist_prefix_suffix (sl, prefix, suffix)
}
void
strlist_print (sl, prefix)
STRINGLIST *sl;
char *prefix;
strlist_print (STRINGLIST *sl, const char *prefix)
{
register int i;
int i;
if (sl == 0)
return;
@@ -236,11 +222,9 @@ strlist_print (sl, prefix)
}
void
strlist_walk (sl, func)
STRINGLIST *sl;
sh_strlist_map_func_t *func;
strlist_walk (STRINGLIST *sl, sh_strlist_map_func_t *func)
{
register int i;
int i;
if (sl == 0)
return;
@@ -250,8 +234,7 @@ strlist_walk (sl, func)
}
void
strlist_sort (sl)
STRINGLIST *sl;
strlist_sort (STRINGLIST *sl)
{
if (sl == 0 || sl->list_len == 0 || sl->list == 0)
return;
@@ -259,9 +242,7 @@ strlist_sort (sl)
}
STRINGLIST *
strlist_from_word_list (list, alloc, starting_index, ip)
WORD_LIST *list;
int alloc, starting_index, *ip;
strlist_from_word_list (WORD_LIST *list, int alloc, int starting_index, int *ip)
{
STRINGLIST *ret;
int slen, len;
@@ -272,7 +253,7 @@ strlist_from_word_list (list, alloc, starting_index, ip)
*ip = 0;
return ((STRINGLIST *)0);
}
slen = list_length (list);
slen = list_length ((GENERIC_LIST *)list);
ret = (STRINGLIST *)xmalloc (sizeof (STRINGLIST));
ret->list = strvec_from_word_list (list, alloc, starting_index, &len);
ret->list_size = slen + starting_index;
@@ -283,9 +264,7 @@ strlist_from_word_list (list, alloc, starting_index, ip)
}
WORD_LIST *
strlist_to_word_list (sl, alloc, starting_index)
STRINGLIST *sl;
int alloc, starting_index;
strlist_to_word_list (STRINGLIST *sl, int alloc, int starting_index)
{
WORD_LIST *list;
+31 -51
View File
@@ -1,6 +1,6 @@
/* stringvec.c - functions for managing arrays of strings. */
/* Copyright (C) 2000-2002 Free Software Foundation, Inc.
/* Copyright (C) 2000-2002,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -27,6 +27,7 @@
#endif
#include <bashansi.h>
#include <stdckdint.h>
#include <stdio.h>
#include <chartypes.h>
@@ -34,42 +35,35 @@
/* Allocate an array of strings with room for N members. */
char **
strvec_create (n)
int n;
strvec_create (size_t n)
{
return ((char **)xmalloc ((n) * sizeof (char *)));
return ((char **)xreallocarray (NULL, n, sizeof (char *)));
}
/* Allocate an array of strings with room for N members. */
char **
strvec_mcreate (n)
int n;
strvec_mcreate (size_t n)
{
return ((char **)malloc ((n) * sizeof (char *)));
return ((char **)reallocarray (NULL, n, sizeof (char *)));
}
char **
strvec_resize (array, nsize)
char **array;
int nsize;
strvec_resize (char **array, size_t nsize)
{
return ((char **)xrealloc (array, nsize * sizeof (char *)));
return ((char **)xreallocarray (array, nsize, sizeof (char *)));
}
char **
strvec_mresize (array, nsize)
char **array;
int nsize;
strvec_mresize (char **array, size_t nsize)
{
return ((char **)realloc (array, nsize * sizeof (char *)));
return ((char **)reallocarray (array, nsize, sizeof (char *)));
}
/* Return the length of ARRAY, a NULL terminated array of char *. */
int
strvec_len (array)
char **array;
size_t
strvec_len (char * const *array)
{
register int i;
register size_t i;
for (i = 0; array[i]; i++);
return (i);
@@ -77,10 +71,9 @@ strvec_len (array)
/* Free the contents of ARRAY, a NULL terminated array of char *. */
void
strvec_flush (array)
char **array;
strvec_flush (char **array)
{
register int i;
register size_t i;
if (array == 0)
return;
@@ -90,8 +83,7 @@ strvec_flush (array)
}
void
strvec_dispose (array)
char **array;
strvec_dispose (char **array)
{
if (array == 0)
return;
@@ -101,10 +93,9 @@ strvec_dispose (array)
}
int
strvec_remove (array, name)
char **array, *name;
strvec_remove (char **array, const char *name)
{
register int i, j;
size_t i, j;
char *x;
if (array == 0)
@@ -124,11 +115,10 @@ strvec_remove (array, name)
/* Find NAME in ARRAY. Return the index of NAME, or -1 if not present.
ARRAY should be NULL terminated. */
int
strvec_search (array, name)
char **array, *name;
ptrdiff_t
strvec_search (char **array, const char *name)
{
int i;
size_t i;
for (i = 0; array[i]; i++)
if (STREQ (name, array[i]))
@@ -139,11 +129,9 @@ strvec_search (array, name)
/* Allocate and return a new copy of ARRAY and its contents. */
char **
strvec_copy (array)
char **array;
strvec_copy (char * const *array)
{
register int i;
int len;
size_t i, len;
char **ret;
len = strvec_len (array);
@@ -161,8 +149,7 @@ strvec_copy (array)
Perform a bytewise comparison if *S1 and *S2 collate equally. */
int
strvec_posixcmp (s1, s2)
register char **s1, **s2;
strvec_posixcmp (char **s1, char **s2)
{
int result;
@@ -181,8 +168,7 @@ strvec_posixcmp (s1, s2)
/* Comparison routine for use with qsort() on arrays of strings. Uses
strcoll(3) if available, otherwise it uses strcmp(3). */
int
strvec_strcmp (s1, s2)
register char **s1, **s2;
strvec_strcmp (char **s1, char **s2)
{
#if defined (HAVE_STRCOLL)
return (strcoll (*s1, *s2));
@@ -198,9 +184,7 @@ strvec_strcmp (s1, s2)
/* Sort ARRAY, a null terminated array of pointers to strings. */
void
strvec_sort (array, posix)
char **array;
int posix;
strvec_sort (char **array, int posix)
{
if (posix)
qsort (array, strvec_len (array), sizeof (char *), (QSFUNC *)strvec_posixcmp);
@@ -217,14 +201,12 @@ strvec_sort (array, posix)
space at the beginning of the array. */
char **
strvec_from_word_list (list, alloc, starting_index, ip)
WORD_LIST *list;
int alloc, starting_index, *ip;
strvec_from_word_list (WORD_LIST *list, int alloc, int starting_index, int *ip)
{
int count;
size_t count;
char **array;
count = list_length (list);
count = list_length ((GENERIC_LIST *)list);
array = (char **)xmalloc ((1 + count + starting_index) * sizeof (char *));
for (count = 0; count < starting_index; count++)
@@ -244,13 +226,11 @@ strvec_from_word_list (list, alloc, starting_index, ip)
in ARRAY to begin. */
WORD_LIST *
strvec_to_word_list (array, alloc, starting_index)
char **array;
int alloc, starting_index;
strvec_to_word_list (char **array, int alloc, int starting_index)
{
WORD_LIST *list;
WORD_DESC *w;
int i, count;
size_t i, count;
if (array == 0 || array[0] == 0)
return (WORD_LIST *)NULL;
+2 -4
View File
@@ -1,6 +1,6 @@
/* strnlen - return length of passed string, with length limit */
/* Copyright (C) 2004 Free Software Foundation, Inc.
/* Copyright (C) 2004, 2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -35,9 +35,7 @@
/* Find the length of S, but scan at most MAXLEN characters. If no '\0'
terminator is found within the first MAXLEN characters, return MAXLEN. */
size_t
strnlen (s, maxlen)
register const char *s;
size_t maxlen;
strnlen (const char *s, size_t maxlen)
{
register const char *e;
size_t n;
+2 -4
View File
@@ -1,6 +1,6 @@
/* strpbrk.c - locate multiple characters in a string */
/* Copyright (C) 1991, 1994 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1994, 2022 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.
@@ -31,9 +31,7 @@
/* Find the first occurrence in S of any character in ACCEPT. */
char *
strpbrk (s, accept)
register const char *s;
register const char *accept;
strpbrk (const char *s, const char *accept)
{
while (*s != '\0')
{
+1 -1
View File
@@ -36,7 +36,7 @@
#endif
#include <sys/types.h>
typedef unsigned chartype;
typedef unsigned int chartype;
#undef strstr
+3 -9
View File
@@ -1,6 +1,6 @@
/* strtod.c - convert string to double-precision floating-point value. */
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1992, 2022-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -41,24 +41,18 @@ extern int errno;
#include <bashansi.h>
#ifndef NULL
# define NULL 0
#endif
#ifndef HUGE_VAL
# define HUGE_VAL HUGE
#endif
#ifndef locale_decpoint
extern int locale_decpoint PARAMS((void));
extern int locale_decpoint (void);
#endif
/* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the
character after the last one used in the number is put in *ENDPTR. */
double
strtod (nptr, endptr)
const char *nptr;
char **endptr;
strtod (const char *nptr, char **endptr)
{
register const char *s;
short sign;
+4 -7
View File
@@ -1,6 +1,6 @@
/* strtoimax - convert string representation of a number into an intmax_t value. */
/* Copyright 1999-2020 Free Software Foundation, Inc.
/* Copyright 1999-2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -45,14 +45,14 @@
"this configure-time declaration test was not run"
#endif
#if !HAVE_DECL_STRTOL
extern long strtol PARAMS((const char *, char **, int));
extern long strtol (const char *, char **, int);
#endif
#ifndef HAVE_DECL_STRTOLL
"this configure-time declaration test was not run"
#endif
#if !HAVE_DECL_STRTOLL && HAVE_LONG_LONG_INT
extern long long strtoll PARAMS((const char *, char **, int));
extern long long strtoll (const char *, char **, int);
#endif
#ifdef strtoimax
@@ -60,10 +60,7 @@ extern long long strtoll PARAMS((const char *, char **, int));
#endif
intmax_t
strtoimax (ptr, endptr, base)
const char *ptr;
char **endptr;
int base;
strtoimax (const char *ptr, char **endptr, int base)
{
#if HAVE_LONG_LONG_INT
verify(size_is_that_of_long_or_long_long,
+2 -9
View File
@@ -1,6 +1,6 @@
/* strtol - convert string representation of a number into a long integer value. */
/* Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001 Free Software Foundation, Inc.
/* Copyright (C) 1991-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -42,10 +42,6 @@ extern int errno;
#include <stdc.h>
#include <bashansi.h>
#ifndef NULL
# define NULL 0
#endif
/* Nonzero if we are defining `strtoul' or `strtoull', operating on
unsigned integers. */
#ifndef UNSIGNED
@@ -90,10 +86,7 @@ extern int errno;
one converted is stored in *ENDPTR. */
INT
strtol (nptr, endptr, base)
const char *nptr;
char **endptr;
int base;
strtol (const char *nptr, char **endptr, int base)
{
int negative;
register unsigned LONG int cutoff;
+4 -7
View File
@@ -1,6 +1,6 @@
/* strtoumax - convert string representation of a number into an uintmax_t value. */
/* Copyright 1999-2020 Free Software Foundation, Inc.
/* Copyright 1999-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -45,14 +45,14 @@
"this configure-time declaration test was not run"
#endif
#if !HAVE_DECL_STRTOUL
extern unsigned long strtoul PARAMS((const char *, char **, int));
extern unsigned long strtoul (const char *, char **, int);
#endif
#ifndef HAVE_DECL_STRTOULL
"this configure-time declaration test was not run"
#endif
#if !HAVE_DECL_STRTOULL && HAVE_UNSIGNED_LONG_LONG_INT
extern unsigned long long strtoull PARAMS((const char *, char **, int));
extern unsigned long long strtoull (const char *, char **, int);
#endif
#ifdef strtoumax
@@ -60,10 +60,7 @@ extern unsigned long long strtoull PARAMS((const char *, char **, int));
#endif
uintmax_t
strtoumax (ptr, endptr, base)
const char *ptr;
char **endptr;
int base;
strtoumax (const char *ptr, char **endptr, int base)
{
#if HAVE_UNSIGNED_LONG_LONG_INT
verify (size_is_that_of_unsigned_long_or_unsigned_long_long,
+21 -34
View File
@@ -1,6 +1,6 @@
/* strtrans.c - Translate and untranslate strings with ANSI-C escape sequences. */
/* Copyright (C) 2000-2015 Free Software Foundation, Inc.
/* Copyright (C) 2000-2015,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -45,24 +45,23 @@
that we're translating a string for `echo -e', and therefore should not
treat a single quote as a character that may be escaped with a backslash.
If (FLAGS&2) is non-zero, we're expanding for the parser and want to
quote CTLESC and CTLNUL with CTLESC. If (flags&4) is non-zero, we want
quote CTLESC and CTLNUL with CTLESC. If (FLAGS&4) is non-zero, we want
to remove the backslash before any unrecognized escape sequence. */
char *
ansicstr (string, len, flags, sawc, rlen)
char *string;
int len, flags, *sawc, *rlen;
ansicstr (const char *string, size_t len, int flags, int *sawc, size_t *rlen)
{
int c, temp;
char *ret, *r, *s;
char *ret, *r;
const char *s;
unsigned long v;
size_t clen;
int b, mb_cur_max;
int mb_cur_max;
#if defined (HANDLE_MULTIBYTE)
wchar_t wc;
#endif
if (string == 0 || *string == '\0')
return ((char *)NULL);
return ((char *)0);
mb_cur_max = MB_CUR_MAX;
#if defined (HANDLE_MULTIBYTE)
@@ -96,13 +95,8 @@ ansicstr (string, len, flags, sawc, rlen)
{
switch (c = *s++)
{
#if defined (__STDC__)
case 'a': c = '\a'; break;
case 'v': c = '\v'; break;
#else
case 'a': c = (int) 0x07; break;
case 'v': c = (int) 0x0B; break;
#endif
case 'b': c = '\b'; break;
case 'e': case 'E': /* ESC -- non-ANSI */
c = ESC; break;
@@ -204,7 +198,9 @@ ansicstr (string, len, flags, sawc, rlen)
s++;
if ((flags & 2) && c == '\\' && c == *s)
s++; /* Posix requires $'\c\\' do backslash escaping */
c = TOCTRL(c);
else if ((flags & 2) && c == CTLESC && (*s == CTLESC || *s == CTLNUL))
c = *s++;
c = TOCTRL(c);
break;
}
/*FALLTHROUGH*/
@@ -227,12 +223,11 @@ ansicstr (string, len, flags, sawc, rlen)
/* Take a string STR, possibly containing non-printing characters, and turn it
into a $'...' ANSI-C style quoted string. Returns a new string. */
char *
ansic_quote (str, flags, rlen)
char *str;
int flags, *rlen;
ansic_quote (const char *str, int flags, int *rlen)
{
char *r, *ret, *s;
int l, rsize;
char *r, *ret;
const char *s;
size_t l, rsize;
unsigned char c;
size_t clen;
int b;
@@ -252,20 +247,15 @@ ansic_quote (str, flags, rlen)
for (s = str; c = *s; s++)
{
b = l = 1; /* 1 == add backslash; 0 == no backslash */
b = 1; /* 1 == add backslash; 0 == no backslash */
l = 1;
clen = 1;
switch (c)
{
case ESC: c = 'E'; break;
#ifdef __STDC__
case '\a': c = 'a'; break;
case '\v': c = 'v'; break;
#else
case 0x07: c = 'a'; break;
case 0x0b: c = 'v'; break;
#endif
case '\b': c = 'b'; break;
case '\f': c = 'f'; break;
case '\n': c = 'n'; break;
@@ -318,8 +308,7 @@ ansic_quote (str, flags, rlen)
#if defined (HANDLE_MULTIBYTE)
int
ansic_wshouldquote (string)
const char *string;
ansic_wshouldquote (const char *string)
{
const wchar_t *wcs;
wchar_t wcc;
@@ -348,8 +337,7 @@ ansic_wshouldquote (string)
/* return 1 if we need to quote with $'...' because of non-printing chars. */
int
ansic_shouldquote (string)
const char *string;
ansic_shouldquote (const char *string)
{
const char *s;
unsigned char c;
@@ -373,12 +361,11 @@ ansic_shouldquote (string)
/* $'...' ANSI-C expand the portion of STRING between START and END and
return the result. The result cannot be longer than the input string. */
char *
ansiexpand (string, start, end, lenp)
char *string;
int start, end, *lenp;
ansiexpand (const char *string, int start, int end, size_t *lenp)
{
char *temp, *t;
int len, tlen;
int len;
size_t tlen;
temp = (char *)xmalloc (end - start + 1);
for (tlen = 0, len = start; len < end; )
+2 -8
View File
@@ -53,12 +53,7 @@
#endif
int
sh_charvis (s, sindp, slen, ret, rindp)
const char *s;
size_t *sindp;
size_t slen;
char *ret;
size_t *rindp;
sh_charvis (const char *s, size_t *sindp, size_t slen, char *ret, size_t *rindp)
{
unsigned char c;
size_t si, ri;
@@ -117,8 +112,7 @@ sh_charvis (s, sindp, slen, ret, rindp)
/* Return a new string with `unsafe' non-graphical characters in S rendered
in a visible way. */
char *
sh_strvis (string)
const char *string;
sh_strvis (const char *string)
{
size_t slen, sind;
char *ret;
+5 -1
View File
@@ -1,6 +1,6 @@
/* timers - functions to manage shell timers */
/* Copyright (C) 2021 Free Software Foundation, Inc.
/* Copyright (C) 2021,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -47,6 +47,10 @@ extern int errno;
#define FREE(s) do { if (s) free (s); } while (0)
#endif
#ifndef USEC_PER_SEC
# define USEC_PER_SEC 1000000
#endif
extern unsigned int falarm (unsigned int, unsigned int);
static void shtimer_zero (sh_timer *);
+3 -4
View File
@@ -1,6 +1,6 @@
/* times.c - times(3) library function */
/* Copyright (C) 1999-2020 Free Software Foundation, Inc.
/* Copyright (C) 1999-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -30,13 +30,12 @@
# include <sys/resource.h>
#endif /* HAVE_SYS_RESOURCE_H && HAVE_GETRUSAGE */
extern long get_clk_tck PARAMS((void));
extern long get_clk_tck (void);
#define CONVTCK(r) (r.tv_sec * clk_tck + r.tv_usec / (1000000 / clk_tck))
clock_t
times(tms)
struct tms *tms;
times(struct tms *tms)
{
clock_t rv;
static long clk_tck = -1;
+27 -33
View File
@@ -1,6 +1,6 @@
/* timeval.c - functions to perform operations on struct timevals */
/* Copyright (C) 1999 Free Software Foundation, Inc.
/* Copyright (C) 1999,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -29,14 +29,13 @@
#include <stdc.h>
#ifndef locale_decpoint
extern int locale_decpoint PARAMS((void));
extern int locale_decpoint (void);
#endif
#include <stdio.h>
struct timeval *
difftimeval (d, t1, t2)
struct timeval *d, *t1, *t2;
difftimeval (struct timeval *d, struct timeval *t1, struct timeval *t2)
{
d->tv_sec = t2->tv_sec - t1->tv_sec;
d->tv_usec = t2->tv_usec - t1->tv_usec;
@@ -54,8 +53,7 @@ difftimeval (d, t1, t2)
}
struct timeval *
addtimeval (d, t1, t2)
struct timeval *d, *t1, *t2;
addtimeval (struct timeval *d, struct timeval *t1, struct timeval *t2)
{
d->tv_sec = t1->tv_sec + t2->tv_sec;
d->tv_usec = t1->tv_usec + t2->tv_usec;
@@ -68,9 +66,7 @@ addtimeval (d, t1, t2)
}
struct timeval *
multimeval (d, m)
struct timeval *d;
int m;
multimeval (struct timeval *d, int m)
{
time_t t;
@@ -81,9 +77,7 @@ multimeval (d, m)
}
struct timeval *
divtimeval (d, m)
struct timeval *d;
int m;
divtimeval (struct timeval *d, int m)
{
time_t t;
@@ -96,8 +90,7 @@ divtimeval (d, m)
/* Do "cpu = ((user + sys) * 10000) / real;" with timevals.
Barely-tested code from Deven T. Corzine <deven@ties.org>. */
int
timeval_to_cpu (rt, ut, st)
struct timeval *rt, *ut, *st; /* real, user, sys */
timeval_to_cpu (struct timeval *rt, struct timeval *ut, struct timeval *st)
{
struct timeval t1, t2;
register int i;
@@ -130,50 +123,51 @@ timeval_to_cpu (rt, ut, st)
return ((t2.tv_sec == 0) ? 0 : t1.tv_sec / t2.tv_sec);
}
/* Convert a pointer to a struct timeval to seconds and thousandths of a
second, returning the values in *SP and *SFP, respectively. This does
rounding on the fractional part, not just truncation to three places. */
/* Convert a pointer to a struct timeval to seconds and fractions of a
second, returning the values in *SP and *SFP, respectively. The precision
of the fractional part is determined by MAXVAL. For instance, if MAXVAL
is 10000000, this just returns the tv_usec field. This does rounding on
the fractional part, not just truncation to three places. */
void
timeval_to_secs (tvp, sp, sfp)
struct timeval *tvp;
time_t *sp;
int *sfp;
timeval_to_secs (struct timeval *tvp, time_t *sp, long *sfp, int maxval)
{
int rest;
*sp = tvp->tv_sec;
*sfp = tvp->tv_usec % 1000000; /* pretty much a no-op */
rest = *sfp % 1000;
*sfp = (*sfp * 1000) / 1000000;
if (rest >= 500)
*sfp += 1;
if (maxval < 1000000) /* don't bother otherwise */
{
rest = *sfp % maxval;
*sfp = (*sfp * maxval) / 1000000;
if (rest >= maxval/2)
*sfp += 1;
}
/* Sanity check */
if (*sfp >= 1000)
if (*sfp >= maxval)
{
*sp += 1;
*sfp -= 1000;
*sfp -= maxval;
}
}
/* Print the contents of a struct timeval * in a standard way to stdio
stream FP. */
void
print_timeval (fp, tvp)
FILE *fp;
struct timeval *tvp;
print_timeval (FILE *fp, struct timeval *tvp)
{
time_t timestamp;
long minutes;
int seconds, seconds_fraction;
int seconds;
long seconds_fraction;
timeval_to_secs (tvp, &timestamp, &seconds_fraction);
timeval_to_secs (tvp, &timestamp, &seconds_fraction, 1000);
minutes = timestamp / 60;
seconds = timestamp % 60;
fprintf (fp, "%ldm%d%c%03ds", minutes, seconds, locale_decpoint (), seconds_fraction);
fprintf (fp, "%ldm%d%c%03lds", minutes, seconds, locale_decpoint (), seconds_fraction);
}
#endif /* HAVE_TIMEVAL */
+82 -38
View File
@@ -2,7 +2,7 @@
* tmpfile.c - functions to create and safely open temp files for the shell.
*/
/* Copyright (C) 2000-2020 Free Software Foundation, Inc.
/* Copyright (C) 2000-2020,2022-2024 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -42,6 +42,10 @@
extern int errno;
#endif
#if defined (HAVE_GETRANDOM) || defined (HAVE_ARC4RANDOM) || defined (HAVE_GETENTROPY)
# define USE_URANDOM32
#endif
#define BASEOPENFLAGS (O_CREAT | O_TRUNC | O_EXCL | O_BINARY)
#define DEFAULT_TMPDIR "." /* bogus default, should be changed */
@@ -54,8 +58,10 @@ extern int errno;
extern pid_t dollar_dollar_pid;
static char *get_sys_tmpdir PARAMS((void));
static char *get_tmpdir PARAMS((int));
static int tmpunlink (const char *);
static char *get_sys_tmpdir (void);
static char *get_tmpdir (int);
static char *sys_tmpdir = (char *)NULL;
static int ntmpfiles;
@@ -63,7 +69,7 @@ static int tmpnamelen = -1;
static unsigned long filenum = 1L;
static char *
get_sys_tmpdir ()
get_sys_tmpdir (void)
{
if (sys_tmpdir)
return sys_tmpdir;
@@ -92,8 +98,7 @@ get_sys_tmpdir ()
}
static char *
get_tmpdir (flags)
int flags;
get_tmpdir (int flags)
{
char *tdir;
@@ -115,7 +120,7 @@ get_tmpdir (flags)
}
static void
sh_seedrand ()
sh_seedrand (void)
{
#if HAVE_RANDOM
int d;
@@ -131,12 +136,20 @@ sh_seedrand ()
#endif
}
char *
sh_mktmpname (nameroot, flags)
char *nameroot;
int flags;
static int
tmpunlink (const char *fn)
{
char *filename, *tdir, *lroot;
int r;
r = unlink (fn);
return r;
}
char *
sh_mktmpname (const char *nameroot, int flags)
{
char *filename, *tdir;
const char *lroot;
struct stat sb;
int r, tdlen;
static int seeded = 0;
@@ -156,22 +169,30 @@ sh_mktmpname (nameroot, flags)
if (flags & MT_TEMPLATE)
strcpy (filename, nameroot);
else
sprintf (filename, "%s/%s.XXXXXX", tdir, lroot);
snprintf (filename, PATH_MAX, "%s/%s.XXXXXX", tdir, lroot);
if (mktemp (filename) == 0)
{
free (filename);
filename = NULL;
}
#else /* !USE_MKTEMP */
#ifndef USE_URANDOM32
sh_seedrand ();
#endif
while (1)
{
unsigned long x;
#ifdef USE_URANDOM32
x = (unsigned long) ((flags & MT_USERANDOM) ? get_urandom32 () : ntmpfiles++);
#else
x = (unsigned long) ((flags & MT_USERANDOM) ? random () : ntmpfiles++);
#endif
filenum = (filenum << 1) ^
(unsigned long) time ((time_t *)0) ^
(unsigned long) dollar_dollar_pid ^
(unsigned long) ((flags & MT_USERANDOM) ? random () : ntmpfiles++);
sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
x;
snprintf (filename, PATH_MAX, "%s/%s-%lu", tdir, lroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32) /* XXX */
filename[tdlen + 1 + tmpnamelen] = '\0';
# ifdef HAVE_LSTAT
r = lstat (filename, &sb);
@@ -187,12 +208,10 @@ sh_mktmpname (nameroot, flags)
}
int
sh_mktmpfd (nameroot, flags, namep)
char *nameroot;
int flags;
char **namep;
sh_mktmpfd (const char *nameroot, int flags, char **namep)
{
char *filename, *tdir, *lroot;
char *filename, *tdir;
const char *lroot;
int fd, tdlen;
filename = (char *)xmalloc (PATH_MAX + 1);
@@ -210,8 +229,15 @@ sh_mktmpfd (nameroot, flags, namep)
if (flags & MT_TEMPLATE)
strcpy (filename, nameroot);
else
sprintf (filename, "%s/%s.XXXXXX", tdir, lroot);
snprintf (filename, PATH_MAX, "%s/%s.XXXXXX", tdir, lroot);
fd = mkstemp (filename);
if ((flags & MT_UNLINK) && tmpunlink (filename) < 0)
{
int e = errno;
close (fd);
fd = -1;
errno = e;
}
if (fd < 0 || namep == 0)
{
free (filename);
@@ -219,36 +245,53 @@ sh_mktmpfd (nameroot, flags, namep)
}
if (namep)
*namep = filename;
return fd;
#else /* !USE_MKSTEMP */
#ifndef USE_URANDOM32
sh_seedrand ();
#endif
do
{
unsigned long x;
#ifdef USE_URANDOM32
x = (unsigned long) ((flags & MT_USERANDOM) ? get_urandom32 () : ntmpfiles++);
#else
x = (unsigned long) ((flags & MT_USERANDOM) ? random () : ntmpfiles++);
#endif
filenum = (filenum << 1) ^
(unsigned long) time ((time_t *)0) ^
(unsigned long) dollar_dollar_pid ^
(unsigned long) ((flags & MT_USERANDOM) ? random () : ntmpfiles++);
sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
x;
snprintf (filename, PATH_MAX, "%s/%s-%lu", tdir, lroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32) /* XXX */
filename[tdlen + 1 + tmpnamelen] = '\0';
fd = open (filename, BASEOPENFLAGS | ((flags & MT_READWRITE) ? O_RDWR : O_WRONLY), 0600);
}
while (fd < 0 && errno == EEXIST);
if ((flags & MT_UNLINK) && (tmpunlink (filename) < 0)
{
int e = errno;
close (fd);
fd = -1;
errno = e;
}
if (fd < 0 || namep == 0)
{
free (filename);
filename = NULL;
}
if (namep)
*namep = filename;
else
free (filename);
return fd;
#endif /* !USE_MKSTEMP */
}
FILE *
sh_mktmpfp (nameroot, flags, namep)
char *nameroot;
int flags;
char **namep;
sh_mktmpfp (const char *nameroot, int flags, char **namep)
{
int fd;
FILE *fp;
@@ -263,14 +306,15 @@ sh_mktmpfp (nameroot, flags, namep)
}
char *
sh_mktmpdir (nameroot, flags)
char *nameroot;
int flags;
sh_mktmpdir (const char *nameroot, int flags)
{
char *filename, *tdir, *lroot, *dirname;
int fd, tdlen;
char *filename;
int fd;
#ifdef USE_MKDTEMP
char *tdir, *dirname;
const char *lroot;
int tdlen;
filename = (char *)xmalloc (PATH_MAX + 1);
tdir = get_tmpdir (flags);
tdlen = strlen (tdir);
@@ -285,7 +329,7 @@ sh_mktmpdir (nameroot, flags)
if (flags & MT_TEMPLATE)
strcpy (filename, nameroot);
else
sprintf (filename, "%s/%s.XXXXXX", tdir, lroot);
snprintf (filename, PATH_MAX, "%s/%s.XXXXXX", tdir, lroot);
dirname = mkdtemp (filename);
if (dirname == 0)
{
+5 -8
View File
@@ -1,7 +1,7 @@
/* uconvert - convert string representations of decimal numbers into whole
number/fractional value pairs. */
/* Copyright (C) 2008,2009,2020 Free Software Foundation, Inc.
/* Copyright (C) 2008,2009,2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -40,7 +40,7 @@
#define RETURN(x) \
do { \
if (ip) *ip = ipart * mult; \
if (up) *up = upart; \
if (up) *up = upart * (ipart == 0 ? mult : 1); \
if (ep) *ep = p; \
return (x); \
} while (0)
@@ -57,10 +57,7 @@ static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 };
Return 1 if value converted; 0 if invalid integer for either whole or
fractional parts. */
int
uconvert(s, ip, up, ep)
char *s;
long *ip, *up;
char **ep;
uconvert(const char *s, long *ip, long *up, char **ep)
{
int n, mult;
long ipart, upart;
@@ -72,10 +69,10 @@ uconvert(s, ip, up, ep)
if (s && (*s == '-' || *s == '+'))
{
mult = (*s == '-') ? -1 : 1;
p = s + 1;
p = (char *)s + 1;
}
else
p = s;
p = (char *)s;
for ( ; p && *p; p++)
{
+60 -24
View File
@@ -1,6 +1,6 @@
/* ufuncs - sleep and alarm functions that understand fractional values */
/* Copyright (C) 2008,2009-2020 Free Software Foundation, Inc.
/* Copyright (C) 2008,2009-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -33,19 +33,21 @@
extern int errno;
#endif /* !errno */
#include "quit.h"
#if defined (HAVE_SELECT)
# include "posixselect.h"
# include "quit.h"
# include "trap.h"
# include "stat-time.h"
#endif
#include "error.h"
/* A version of `alarm' using setitimer if it's available. */
#if defined (HAVE_SETITIMER)
unsigned int
falarm(secs, usecs)
unsigned int secs, usecs;
falarm (unsigned int secs, unsigned int usecs)
{
struct itimerval it, oit;
@@ -65,8 +67,7 @@ falarm(secs, usecs)
}
#else
int
falarm (secs, usecs)
unsigned int secs, usecs;
falarm (unsigned int secs, unsigned int usecs)
{
if (secs == 0 && usecs == 0)
return (alarm (0));
@@ -83,58 +84,93 @@ falarm (secs, usecs)
/* A version of sleep using fractional seconds and select. I'd like to use
`usleep', but it's already taken */
#if defined (HAVE_NANOSLEEP)
static int
nsleep (unsigned int sec, unsigned int usec)
{
int r;
struct timespec req, rem;
req.tv_sec = sec;
req.tv_nsec = usec * 1000;
for (;;)
{
QUIT;
r = nanosleep (&req, &rem);
if (r == 0 || errno != EINTR)
return r;
req = rem;
}
return r;
}
#endif
#if defined (HAVE_TIMEVAL) && (defined (HAVE_SELECT) || defined (HAVE_PSELECT))
int
fsleep(sec, usec)
unsigned int sec, usec;
static int
ssleep (unsigned int sec, unsigned int usec)
{
int e, r;
sigset_t blocked_sigs, prevmask;
#if defined (HAVE_PSELECT)
sigset_t blocked_sigs;
# if defined (HAVE_PSELECT)
struct timespec ts;
#else
# else
sigset_t prevmask;
struct timeval tv;
#endif
# endif
sigemptyset (&blocked_sigs);
# if defined (SIGCHLD)
sigaddset (&blocked_sigs, SIGCHLD);
# endif
#if defined (HAVE_PSELECT)
# if defined (HAVE_PSELECT)
ts.tv_sec = sec;
ts.tv_nsec = usec * 1000;
#else
# else
sigemptyset (&prevmask);
tv.tv_sec = sec;
tv.tv_usec = usec;
#endif /* !HAVE_PSELECT */
# endif /* !HAVE_PSELECT */
do
{
#if defined (HAVE_PSELECT)
# if defined (HAVE_PSELECT)
r = pselect(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &ts, &blocked_sigs);
#else
# else
sigprocmask (SIG_SETMASK, &blocked_sigs, &prevmask);
r = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);
sigprocmask (SIG_SETMASK, &prevmask, NULL);
#endif
# endif
e = errno;
if (r < 0 && errno == EINTR)
return -1; /* caller will handle */
return -1; /* caller will handle XXX - QUIT;? */
errno = e;
}
while (r < 0 && errno == EINTR);
return r;
}
#else /* !HAVE_TIMEVAL || !HAVE_SELECT */
int
fsleep(sec, usec)
long sec, usec;
#endif
#if !defined (HAVE_SELECT)
static int
ancientsleep(unsigned int sec, unsigned int usec)
{
if (usec >= 500000) /* round */
sec++;
return (sleep(sec));
}
#endif
int
fsleep(unsigned int sec, unsigned int usec)
{
#if defined (HAVE_NANOSLEEP)
return (nsleep (sec, usec));
#elif defined (HAVE_TIMEVAL) && (defined (HAVE_SELECT) || defined (HAVE_PSELECT))
return (ssleep (sec, usec));
#else /* !HAVE_TIMEVAL || !HAVE_SELECT */
return (ancientsleep (sec, usec));
#endif /* !HAVE_TIMEVAL || !HAVE_SELECT */
}
+20 -25
View File
@@ -1,6 +1,6 @@
/* unicode.c - functions to convert unicode characters */
/* Copyright (C) 2010-2020 Free Software Foundation, Inc.
/* Copyright (C) 2010-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -35,6 +35,10 @@
# include <iconv.h>
#endif
#if HAVE_LANGINFO_CODESET
# include <langinfo.h>
#endif
#include <xmalloc.h>
#ifndef USHORT_MAX
@@ -50,9 +54,9 @@
#endif /* !STREQ */
#if defined (HAVE_LOCALE_CHARSET)
extern const char *locale_charset PARAMS((void));
extern const char *locale_charset (void);
#else
extern char *get_locale_var PARAMS((char *));
extern char *get_locale_var (const char *);
#endif
extern int locale_utf8locale;
@@ -67,7 +71,7 @@ static iconv_t localconv;
static char charsetbuf[40];
static char *
stub_charset ()
stub_charset (void)
{
char *locale, *s, *t;
@@ -94,7 +98,7 @@ stub_charset ()
#endif
void
u32reset ()
u32reset (void)
{
#if defined (HAVE_ICONV)
if (u32init && localconv != (iconv_t)-1)
@@ -109,9 +113,7 @@ u32reset ()
/* u32toascii ? */
int
u32tochar (x, s)
unsigned long x;
char *s;
u32tochar (unsigned long x, char *s)
{
int l;
@@ -136,9 +138,7 @@ u32tochar (x, s)
}
int
u32tocesc (wc, s)
u_bits32_t wc;
char *s;
u32tocesc (u_bits32_t wc, char *s)
{
int l;
@@ -151,9 +151,7 @@ u32tocesc (wc, s)
/* Convert unsigned 32-bit int to utf-8 character string */
int
u32toutf8 (wc, s)
u_bits32_t wc;
char *s;
u32toutf8 (u_bits32_t wc, char *s)
{
int l;
@@ -214,9 +212,7 @@ u32toutf8 (wc, s)
/* Convert a 32-bit unsigned int (unicode) to a UTF-16 string. Rarely used,
only if sizeof(wchar_t) == 2. */
int
u32toutf16 (c, s)
u_bits32_t c;
wchar_t *s;
u32toutf16 (u_bits32_t c, wchar_t *s)
{
int l;
@@ -240,9 +236,7 @@ u32toutf16 (c, s)
/* convert a single unicode-32 character into a multibyte string and put the
result in S, which must be large enough (at least max(10,MB_LEN_MAX) bytes) */
int
u32cconv (c, s)
unsigned long c;
char *s;
u32cconv (unsigned long c, char *s)
{
wchar_t wc;
wchar_t ws[3];
@@ -268,17 +262,18 @@ u32cconv (c, s)
#endif
#if HAVE_ICONV
/* this is mostly from coreutils-8.5/lib/unicodeio.c */
/* this is mostly from coreutils-8.5/lib/unicodeio.c but prefers nl_langinfo
to be consistent with locale.c:locale_isutf8() */
if (u32init == 0)
{
utf8locale = locale_utf8locale;
localconv = (iconv_t)-1;
if (utf8locale == 0)
{
#if HAVE_LOCALE_CHARSET
charset = locale_charset ();
#elif HAVE_NL_LANGINFO
#if HAVE_LANGINFO_CODESET
charset = nl_langinfo (CODESET);
#elif HAVE_LOCALE_CHARSET
charset = locale_charset ();
#else
charset = stub_charset ();
#endif
@@ -333,7 +328,7 @@ u32cconv (c, s)
}
#else
void
u32reset ()
u32reset (void)
{
}
#endif /* HANDLE_MULTIBYTE */
+9 -19
View File
@@ -1,6 +1,6 @@
/* utf8.c - UTF-8 character handling functions */
/* Copyright (C) 2018 Free Software Foundation, Inc.
/* Copyright (C) 2018, 2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -33,26 +33,22 @@ extern int locale_utf8locale;
#if defined (HANDLE_MULTIBYTE)
char *
utf8_mbschr (s, c)
const char *s;
int c;
utf8_mbschr (const char *s, int c)
{
return strchr (s, c); /* for now */
}
int
utf8_mbscmp (s1, s2)
const char *s1, *s2;
utf8_mbscmp (const char *s1, const char *s2)
{
/* Use the fact that the UTF-8 encoding preserves lexicographic order. */
return strcmp (s1, s2);
}
char *
utf8_mbsmbchar (str)
const char *str;
utf8_mbsmbchar (const char *str)
{
register char *s;
char *s;
for (s = (char *)str; *s; s++)
if ((*s & 0xc0) == 0x80)
@@ -61,12 +57,9 @@ utf8_mbsmbchar (str)
}
int
utf8_mbsnlen(src, srclen, maxlen)
const char *src;
size_t srclen;
int maxlen;
utf8_mbsnlen(const char *src, size_t srclen, int maxlen)
{
register int sind, count;
int sind, count;
for (sind = count = 0; src[sind] && sind <= maxlen; sind++)
{
@@ -78,9 +71,7 @@ utf8_mbsnlen(src, srclen, maxlen)
/* Adapted from GNU gnulib. Handles UTF-8 characters up to 4 bytes long */
int
utf8_mblen (s, n)
const char *s;
size_t n;
utf8_mblen (const char *s, size_t n)
{
unsigned char c, c1, c2, c3;
@@ -174,8 +165,7 @@ utf8_mblen (s, n)
/* We can optimize this if we know the locale is UTF-8, but needs to handle
malformed byte sequences. */
size_t
utf8_mbstrlen(s)
const char *s;
utf8_mbstrlen (const char *s)
{
size_t clen, nc;
int mb_cur_max;
+3 -12
View File
@@ -25,11 +25,7 @@
#include <stdio.h>
#if !defined (NULL)
# if defined (__STDC__)
# define NULL ((void *)0)
# else
# define NULL 0x0
# endif /* __STDC__ */
# define NULL 0
#endif /* !NULL */
/*
@@ -40,10 +36,7 @@
#include <varargs.h>
int
vfprintf (iop, fmt, ap)
FILE *iop;
char *fmt;
va_list ap;
vfprintf (FILE *iop, char *fmt, va_list ap)
{
int len;
char localbuf[BUFSIZ];
@@ -68,9 +61,7 @@ vfprintf (iop, fmt, ap)
* Ditto for vsprintf
*/
int
vsprintf (str, fmt, ap)
char *str, *fmt;
va_list ap;
vsprintf (char *str, char *fmt, va_list ap)
{
FILE f;
int len;
+2 -3
View File
@@ -1,6 +1,6 @@
/* wcsdup.c - duplicate wide character string */
/* Copyright (C) 2006 Free Software Foundation, Inc.
/* Copyright (C) 2006,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -28,8 +28,7 @@
#include <xmalloc.h>
wchar_t *
wcsdup (ws)
const wchar_t *ws;
wcsdup (const wchar_t *ws)
{
wchar_t *ret;
size_t len;
+2 -4
View File
@@ -1,7 +1,7 @@
/* wcsnwidth.c - compute display width of wide character string, up to max
specified width, return length. */
/* Copyright (C) 2012 Free Software Foundation, Inc.
/* Copyright (C) 2012,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -31,9 +31,7 @@
PWCS. If the display width exceeds MAX, return the number of wide chars
from PWCS required to display MAX characters on the screen. */
int
wcsnwidth(pwcs, n, max)
const wchar_t *pwcs;
size_t n, max;
wcsnwidth(const wchar_t *pwcs, size_t n, size_t max)
{
wchar_t wc, *ws;
int len, l;
+2 -4
View File
@@ -1,6 +1,6 @@
/* wcswidth.c - compute display width of wide character string */
/* Copyright (C) 2010 Free Software Foundation, Inc.
/* Copyright (C) 2010,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -27,9 +27,7 @@
#include <bashansi.h>
int
wcswidth(pwcs, n)
const wchar_t *pwcs;
size_t n;
wcswidth(const wchar_t *pwcs, size_t n)
{
wchar_t wc;
int len, l;
+4 -12
View File
@@ -1,6 +1,6 @@
/* winsize.c - handle window size changes and information. */
/* Copyright (C) 2005-2020 Free Software Foundation, Inc.
/* Copyright (C) 2005-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -32,12 +32,6 @@
/* Try to find the definitions of `struct winsize' and TIOGCWINSZ */
#if 0
#if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ)
# include <sys/ioctl.h>
#endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */
#endif
#if defined (STRUCT_WINSIZE_IN_TERMIOS) && !defined (STRUCT_WINSIZE_IN_SYS_IOCTL)
# include <termios.h>
#endif /* STRUCT_WINSIZE_IN_TERMIOS && !STRUCT_WINSIZE_IN_SYS_IOCTL */
@@ -73,14 +67,12 @@ extern int shell_tty;
extern int interactive_shell;
extern int no_line_editing;
extern int bash_readline_initialized;
extern void rl_set_screen_size PARAMS((int, int));
extern void rl_set_screen_size (int, int);
#endif
extern void sh_set_lines_and_columns PARAMS((int, int));
extern void sh_set_lines_and_columns (int, int);
void
get_new_window_size (from_sig, rp, cp)
int from_sig;
int *rp, *cp;
get_new_window_size (int from_sig, int *rp, int *cp)
{
#if defined (TIOCGWINSZ)
struct winsize win;
+4 -6
View File
@@ -1,6 +1,6 @@
/* zcatfd - copy contents of file descriptor to another */
/* Copyright (C) 2002-2020 Free Software Foundation, Inc.
/* Copyright (C) 2002-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -38,15 +38,13 @@ extern int errno;
# define ZBUFSIZ 4096
#endif
extern ssize_t zread PARAMS((int, char *, size_t));
extern int zwrite PARAMS((int, char *, ssize_t));
extern ssize_t zread (int, char *, size_t);
extern int zwrite (int, char *, ssize_t);
/* Dump contents of file descriptor FD to OFD. FN is the filename for
error messages (not used right now). */
int
zcatfd (fd, ofd, fn)
int fd, ofd;
char *fn;
zcatfd (int fd, int ofd, const char *fn)
{
ssize_t nr;
int rval;
+10 -15
View File
@@ -1,7 +1,7 @@
/* 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-2020 Free Software Foundation, Inc.
/* Copyright (C) 2008-2020,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -34,13 +34,13 @@
extern int errno;
#endif
extern ssize_t zread PARAMS((int, char *, size_t));
extern ssize_t zreadc PARAMS((int, char *));
extern ssize_t zreadintr PARAMS((int, char *, size_t));
extern ssize_t zreadcintr PARAMS((int, char *));
extern ssize_t zread (int, char *, size_t);
extern ssize_t zreadc (int, char *);
extern ssize_t zreadintr (int, char *, size_t);
extern ssize_t zreadcintr (int, char *);
typedef ssize_t breadfunc_t PARAMS((int, char *, size_t));
typedef ssize_t creadfunc_t PARAMS((int, char *));
typedef ssize_t breadfunc_t (int, char *, size_t);
typedef ssize_t creadfunc_t (int, char *);
/* Initial memory allocation for automatic growing buffer in zreadlinec */
#define GET_LINE_INITIAL_ALLOCATION 16
@@ -61,15 +61,10 @@ typedef ssize_t creadfunc_t PARAMS((int, char *));
Returns number of bytes read or -1 on error. */
ssize_t
zgetline (fd, lineptr, n, delim, unbuffered_read)
int fd;
char **lineptr;
size_t *n;
int delim;
int unbuffered_read;
zgetline (int fd, char **lineptr, size_t *n, int delim, int unbuffered_read)
{
int retval;
size_t nr;
ssize_t retval;
ssize_t nr;
char *line, c;
if (lineptr == 0 || n == 0 || (*lineptr == 0 && *n != 0))
+3 -6
View File
@@ -1,6 +1,6 @@
/* zmapfd - read contents of file descriptor into a newly-allocated buffer */
/* Copyright (C) 2006-2020 Free Software Foundation, Inc.
/* Copyright (C) 2006-2020,2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -40,15 +40,12 @@ extern int errno;
# define ZBUFSIZ 4096
#endif
extern ssize_t zread PARAMS((int, char *, size_t));
extern ssize_t zread (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;
zmapfd (int fd, char **ostr, const char *fn)
{
ssize_t nr;
int rval;
+9 -26
View File
@@ -1,6 +1,6 @@
/* zread - read data from file descriptor into buffer with retries */
/* Copyright (C) 1999-2020 Free Software Foundation, Inc.
/* Copyright (C) 1999-2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -51,10 +51,7 @@ extern int read_builtin_timeout (int);
/* Read LEN bytes from FD into BUF. Retry the read on EINTR. Any other
error causes the loop to break. */
ssize_t
zread (fd, buf, len)
int fd;
char *buf;
size_t len;
zread (int fd, char *buf, size_t len)
{
ssize_t r;
@@ -87,10 +84,7 @@ zread (fd, buf, len)
#define NUM_INTR 3
ssize_t
zreadretry (fd, buf, len)
int fd;
char *buf;
size_t len;
zreadretry (int fd, char *buf, size_t len)
{
ssize_t r;
int nintr;
@@ -112,10 +106,7 @@ zreadretry (fd, buf, len)
/* Call read(2) and allow it to be interrupted. Just a stub for now. */
ssize_t
zreadintr (fd, buf, len)
int fd;
char *buf;
size_t len;
zreadintr (int fd, char *buf, size_t len)
{
check_signals ();
return (read (fd, buf, len));
@@ -129,9 +120,7 @@ static char lbuf[ZBUFSIZ];
static size_t lind, lused;
ssize_t
zreadc (fd, cp)
int fd;
char *cp;
zreadc (int fd, char *cp)
{
ssize_t nr;
@@ -154,9 +143,7 @@ zreadc (fd, cp)
/* Don't mix calls to zreadc and zreadcintr in the same function, since they
use the same local buffer. */
ssize_t
zreadcintr (fd, cp)
int fd;
char *cp;
zreadcintr (int fd, char *cp)
{
ssize_t nr;
@@ -179,10 +166,7 @@ zreadcintr (fd, cp)
/* Like zreadc, but read a specified number of characters at a time. Used
for `read -N'. */
ssize_t
zreadn (fd, cp, len)
int fd;
char *cp;
size_t len;
zreadn (int fd, char *cp, size_t len)
{
ssize_t nr;
@@ -205,7 +189,7 @@ zreadn (fd, cp, len)
}
void
zreset ()
zreset (void)
{
lind = lused = 0;
}
@@ -213,8 +197,7 @@ zreset ()
/* Sync the seek pointer for FD so that the kernel's idea of the last char
read is the last char returned by zreadc. */
void
zsyncfd (fd)
int fd;
zsyncfd (int fd)
{
off_t off, r;
+2 -5
View File
@@ -1,6 +1,6 @@
/* zwrite - write contents of buffer to file descriptor, retrying on error */
/* Copyright (C) 1999-2002 Free Software Foundation, Inc.
/* Copyright (C) 1999-2002, 2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -36,10 +36,7 @@ extern int errno;
it is interrupted. We retry three times if we get a zero-length
write. Any other signal causes this function to return prematurely. */
int
zwrite (fd, buf, nb)
int fd;
char *buf;
size_t nb;
zwrite (int fd, char *buf, size_t nb)
{
int n, i, nt;