- reset_shopt_options: set glob_always_skip_dot_and_dotdot to 1,
since that's the current default in lib/glob/glob.c
+ 1/4
+ ---
+execute_cmd.c,parse.y,general.c,make_cmd.c,print_cmd.c,variables.c,expr.c
+jobs.c,subst.c,input.c,unwind_prot.c,pathexp.c,pathexp.h,alias.c,bashline.c
+bashhist.c,lib/sh/shquote.c,externs.h,stringlib.c,locale.c,findcmd.c
+builtins/common.c,builtins/declare.def,builtins/enable.def,builtins/fc.def
+lib/sh/zmapfd.c,builtins/help.def,builtins/mapfile.def,builtins/read.def
+builtins/shopt.def,lib/glob/glob.c,lib/glob/smatch.c,lib/glob/sm_loop.c
+lib/glob/xmbsrtowcs.c,lib/glob/gmisc.c,lib/glob/gm_loop.c
+lib/sh/getenv.c,lib/sh/makepath.c,lib/sh/pathphys.c,lib/sh/tmpfile.c
+lib/sh/stringlib.c,lib/sh/spell.c,lib/sh/strtrans.c,lib/sh/zgetline.c
+lib/sh/mbscasecmp.c,lib/sh/utf8.c
+lib/readline/readline.c,lib/readline/rlprivate.h,lib/readline/vi_mode.c
+lib/readline/complete.c,lib/readline/bind.c,lib/readline/isearch.c
+lib/readline/util.c,lib/readline/kill.c,lib/readline/macro.c
+lib/readline/text.c,lib/readline/histexpand.c,lib/readline/histfile.c
+lib/readline/mbutil.c,lib/tilde/tilde.c
+ - size_t changes
+ - remove some unused variables
+ - remove `register'
-Wcast-align -Wstrict-prototypes -Wconversion -Wformat \
-Wformat-nonliteral -Wmissing-braces -Wuninitialized \
-Wmissing-declarations -Winline \
- -Wmissing-prototypes -Wtraditional -Wredundant-decls \
+ -Wmissing-prototypes -Wredundant-decls \
-Wformat-security -pedantic
GCC_LINT_CFLAGS = $(BASE_CCFLAGS) $(CPPFLAGS) $(GCC_LINT_FLAGS)
map_over_aliases (sh_alias_map_func_t *function)
{
register int i;
- register BUCKET_CONTENTS *tlist;
+ BUCKET_CONTENTS *tlist;
alias_t *alias, **list;
int list_index;
alias_expand (char *string)
{
- register int i, j, start;
+ int i, start;
char *line, *token;
- int line_len, tl, real_start, expand_next, expand_this_token;
+ size_t j, line_len;
+ int tl, real_start, expand_next, expand_this_token;
alias_t *alias;
line_len = strlen (string) + 1;
(alias = find_alias (token)))
{
char *v;
- int vlen, llen;
+ size_t vlen, llen;
v = alias->value;
vlen = strlen (v);
}
else
{
- int llen, tlen;
+ size_t llen, tlen;
llen = strlen (line);
tlen = i - real_start; /* tlen == strlen(token) */
savecmd = this_command_name;
if (integer_p (var))
- this_command_name = (char *)NULL; /* no command name for errors */
+ this_command_name = 0; /* no command name for errors */
if (assoc_p (var))
bind_assoc_var_internal (var, nhash, akey, val, iflags);
else
void
bash_add_history (char *line)
{
- int add_it, offset, curlen, is_comment;
+ int add_it, offset, is_comment;
+ size_t curlen;
HIST_ENTRY *current, *old;
char *chars_to_add, *new_line;
static int bash_complete_command (int, int);
static int bash_possible_command_completions (int, int);
-static int completion_glob_pattern (char *);
+static int completion_glob_pattern (const char *);
static char *glob_complete_word (const char *, int);
static int bash_glob_completion_internal (int);
static int bash_glob_complete_word (int, int);
static int
bash_spell_correct_shellword (int count, int key)
{
- int opoint, wbeg, wend;
+ int wbeg, wend;
char *text, *newdir;
- opoint = rl_point;
while (count)
{
bash_backward_shellword (1, key);
/* This could be a globbing pattern, so try to expand it using pathname
expansion. */
- if (!matches && completion_glob_pattern ((char *)text))
+ if (!matches && completion_glob_pattern (text))
{
matches = rl_completion_matches (text, glob_complete_word);
/* A glob expression that matches more than one filename is problematic.
static char *dequoted_hint = (char *)NULL;
static char *directory_part = (char *)NULL;
static char **glob_matches = (char **)NULL;
- static int path_index, hint_len, istate, igncase;
+ static int path_index, istate, igncase;
+ static size_t hint_len;
static int mapping_over, local_index, searching_path, hint_is_dir;
static int old_glob_ignore_case, globpat;
static SHELL_VAR **varlist = (SHELL_VAR **)NULL;
glob_matches = (char **)NULL;
}
- globpat = completion_glob_pattern ((char *)hint_text);
+ globpat = completion_glob_pattern (hint_text);
/* If this is an absolute program name, do not check it against
aliases, reserved words, functions or builtins. We must check
#else
static char *sname = (char *)NULL;
static struct servent *srvent;
- static int snamelen;
+ static size_t snamelen;
char *value;
char **alist, *aentry;
int afound;
#else
static char *gname = (char *)NULL;
static struct group *grent;
- static int gnamelen;
+ static size_t gnamelen;
char *value;
if (state == 0)
static int
history_and_alias_expand_line (int count, int ignore)
{
- char *new_line, *t;
+ char *new_line;
new_line = 0;
#if defined (BANG_HISTORY)
_ignore_completion_names (char **names, sh_ignore_func_t *name_func)
{
char **newnames;
- int idx, nidx;
+ size_t idx, nidx;
char **oldnames;
int oidx;
name_is_acceptable (const char *name)
{
struct ign *p;
- int nlen;
+ size_t nlen;
for (nlen = strlen (name), p = fignore.ignores; p->val; p++)
{
static char *
restore_tilde (const char *val, char *directory_part)
{
- int l, vl, dl2, xl;
+ size_t l, vl, dl2, xl;
char *dh2, *expdir, *ret, *v;
vl = strlen (val);
if (no_symbolic_links == 0 && (local_dirname[0] != '.' || local_dirname[1]))
{
char *temp1, *temp2;
- int len1, len2;
+ size_t len1, len2;
/* If we have a relative path
(local_dirname[0] != '/' && local_dirname[0] != '.')
}
static char **history_completion_array = (char **)NULL;
-static int harry_size;
-static int harry_len;
+static size_t harry_size;
+static size_t harry_len;
static void
build_history_completion_array (void)
static char *
history_completion_generator (const char *hint_text, int state)
{
- static int local_index, len;
+ static int local_index;
+ static size_t len;
static const char *text;
/* If this is the first call to the generator, then initialize the
}
static int
-completion_glob_pattern (char *string)
+completion_glob_pattern (const char *string)
{
return (glob_pattern_p (string) == 1);
}
{
static char **matches = (char **)NULL;
static int ind;
- int glen;
+ size_t glen;
char *ret, *ttext;
if (state == 0)
bash_dequote_filename (char *text, int quote_char)
{
char *ret, *p, *r;
- int l, quoted;
+ int quoted;
+ size_t l;
l = strlen (text);
ret = (char *)xmalloc (l + 1);
quote_word_break_chars (char *text)
{
char *ret, *r, *s;
- int l;
+ size_t l;
l = strlen (text);
ret = (char *)xmalloc ((2 * l) + 1);
static void
set_filename_quote_chars (int expchar, int nextch, int closer)
{
- int i, j, c;
+ size_t i, j;
+ int c;
if (rl_filename_quote_characters && *rl_filename_quote_characters)
{
bash_quote_filename (char *s, int rtype, char *qcp)
{
char *rtext, *mtext, *ret;
- int rlen, cs;
- int expchar, nextch, closer;
+ size_t rlen;
+ int cs, expchar, nextch, closer;
rtext = (char *)NULL;
register int i, r;
intmax_t mi;
sh_parser_state_t ps;
- char *cmd, *value, *ce, old_ch;
+ char *cmd, *value, *ce;
SHELL_VAR *v;
char ibuf[INT_STRLEN_BOUND(int) + 1];
Keymap cmd_xmap;
/* common.c - utility functions for all builtins */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
int
get_job_by_name (const char *name, int flags)
{
- register int i, wl, cl, match, job;
- register PROCESS *p;
- register JOB *j;
+ int i, match, job;
+ size_t wl, cl;
+ PROCESS *p;
+ JOB *j;
job = NO_JOB;
wl = strlen (name);
int
builtin_arrayref_flags (WORD_DESC *w, int baseflags)
{
- char *t;
int vflags;
vflags = baseflags;
This file is declare.def, from which is created declare.c.
It implements the builtins "declare" and "local" in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
simple_array_assign = 1;
else if ((making_array_special || creating_array || array_exists) && offset)
{
- int vlen;
+ size_t vlen;
vlen = STRLEN (value);
/*itrace("declare_builtin: name = %s value = %s flags = %d", name, value, wflags);*/
This file is enable.def, from which is created enable.c.
It implements the builtin "enable" in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
WORD_LIST *l;
void *handle;
- int total, size, new, replaced, r;
+ int total, new, replaced, r;
+ size_t size;
char *struct_name, *name, *funcname;
sh_load_func_t *loadfunc;
struct builtin **new_builtins, *b, *new_shell_builtins, *old_builtin;
void *handle;
char *funcname;
sh_unload_func_t *unloadfunc;
- int ref, i, size;
+ int ref, i;
+ size_t size;
b = builtin_address_internal (name, 1);
if (b == 0)
/* evalfile.c - read and evaluate commands from a file or file descriptor */
-/* Copyright (C) 1996-2017,2022 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2017,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* evalstring.c - evaluate a string as one or more shell commands. */
-/* Copyright (C) 1996-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
open_redir_file (REDIRECT *r, char **fnp)
{
char *fn;
- int fd, rval;
+ int fd;
if (r->instruction != r_input_direction)
return -1;
#include "common.h"
#include "builtext.h" /* for jobs_builtin */
-extern int check_jobs_at_exit;
-
static int exit_or_logout (WORD_LIST *);
static int sourced_logout;
This file is fc.def, from which is created fc.c.
It implements the builtin "fc" in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
#define HN_LISTING 0x01
#define HN_FIRST 0x02
+#ifndef HAVE_UNISTD_H
extern int unlink (const char *);
+#endif
extern FILE *sh_mktmpfp (char *, int, char **);
static int
fc_gethnum (char *command, HIST_ENTRY **hlist, int mode)
{
- int sign, n, clen, rh;
- register int i, j, last_hist, real_last, listing;
- register char *s;
+ int sign, n, rh;
+ size_t clen;
+ int i, j, last_hist, real_last, listing;
+ char *s;
listing = mode & HN_LISTING;
sign = 1;
static void
fc_replhist (char *command)
{
- int n;
+ size_t n;
if (command == 0 || *command == '\0')
return;
This file is hash.def, from which is created hash.c.
It implements the builtin "hash" in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
#include "common.h"
#include "bashgetopt.h"
-extern int dot_found_in_search;
-
static int add_hashed_command (char *, int);
static int print_hash_info (BUCKET_CONTENTS *);
static int print_portable_hash_info (BUCKET_CONTENTS *);
This file is help.def, from which is created help.c.
It implements the builtin "help" in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
extern const char * const bash_license;
static void show_builtin_command_help (void);
-static int open_helpfile (char *);
+static int open_helpfile (const char *);
static void show_desc (char *, int);
static void show_manpage (char *, int);
static void show_longdoc (int);
{
register int i;
char *pattern, *name;
- int plen, match_found, sflag, dflag, mflag, m, pass, this_found;
+ int match_found, sflag, dflag, mflag, m, pass, this_found;
+ size_t plen;
dflag = sflag = mflag = 0;
reset_internal_getopt ();
}
static int
-open_helpfile (char *name)
+open_helpfile (const char *name)
{
int fd;
show_manpage (char *name, int i)
{
register int j;
- char **doc, *line;
+ char * const *doc;
+ char *line;
int fd, usefile;
- doc = (char **)shell_builtins[i].long_doc;
+ doc = shell_builtins[i].long_doc;
usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL);
if (usefile)
dispcolumn (int i, char *buf, size_t bufsize, int width, int height)
{
int j;
- int dispcols;
+ size_t dispcols;
char *helpdoc;
/* first column */
static void
show_builtin_command_help (void)
{
- int i, j;
+ int i;
int height, width;
char *t, blurb[128];
It implements the builtin "mapfile" in Bash.
Copyright (C) 2005-2006 Rocky Bernstein for Free Software Foundation, Inc.
-Copyright (C) 2008-2022 Free Software Foundation, Inc.
+Copyright (C) 2008-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
#define MAPF_CLEARARRAY 0x01
#define MAPF_CHOP 0x02
-static int delim;
-
static int
run_callback (const char *callback, unsigned int curindex, const char *curline)
{
int
mapfile_builtin (WORD_LIST *list)
{
- int opt, code, fd, flags;
+ int opt, code, fd, flags, delim;
intmax_t intval;
long lines, origin, nskip, callback_quantum;
char *array_name, *callback;
static char **pushd_directory_list = (char **)NULL;
/* Number of existing slots in this list. */
-static int directory_list_size;
+static size_t directory_list_size;
/* Offset to the end of the list. */
static int directory_list_offset;
sh_timer *read_timeout;
static int reading, tty_modified;
-static SigHandler *old_alrm;
static unsigned char delim;
static struct ttsave termsave;
int
read_builtin (WORD_LIST *list)
{
- register char *varname;
- int size, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2, nflag;
+ char *varname;
+ int nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2, nflag;
+ size_t size;
volatile int i;
int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
int raw, edit, nchars, silent, have_timeout, ignore_delim, fd;
if (retval <= 0)
{
- int t;
+ int x;
- t = errno;
+ x = errno;
if (retval < 0 && errno == EINTR)
{
check_signals (); /* in case we didn't call zread via zreadc */
ttyrestore (&termsave); /* fix terminal before exiting */
CHECK_TERMSIG;
eof = 1;
- errno = t; /* preserve it for the error message below */
+ errno = x; /* preserve it for the error message below */
break;
}
/* XXX -- use i + mb_cur_max (at least 4) for multibyte/read_mbchar */
if (i + (mb_cur_max > 4 ? mb_cur_max : 4) >= size)
{
- char *t;
- t = (char *)xrealloc (input_string, size += 128);
+ char *x;
+ x = (char *)xrealloc (input_string, size += 128);
/* Only need to change unwind-protect if input_string changes */
- if (t != input_string)
+ if (x != input_string)
{
- input_string = t;
+ input_string = x;
remove_unwind_protect ();
add_unwind_protect (xfree, input_string);
}
edit_line (char *p, char *itext)
{
char *ret;
- int len;
+ size_t len;
if (bash_readline_initialized == 0)
initialize_readline ();
This file is set.def, from which is created set.c.
It implements the "set" and "unset" builtins in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
{
char *value;
char tflag[N_O_OPTIONS];
- int vsize, i, vptr, *ip, exported;
+ int i, *ip, exported;
+ size_t vsize, vptr;
SHELL_VAR *v;
for (vsize = i = 0; o_options[i].name; i++)
This file is shopt.def, from which is created shopt.c.
It implements the Bash `shopt' builtin.
-Copyright (C) 1994-2022 Free Software Foundation, Inc.
+Copyright (C) 1994-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* If we're unsetting one of the compatibility options, make sure the
current value is in the range of the compatNN space. */
- if (mode == 0)
- oldval = shell_compatibility_level;
+ oldval = (mode == 0) ? shell_compatibility_level : 0;
/* If we're setting something, redo some of the work we did above in
toggle_shopt(). Unset everything and reset the appropriate option
get_shopt_options (void)
{
char **ret;
- int n, i;
+ int i;
+ size_t n;
n = sizeof (shopt_vars) / sizeof (shopt_vars[0]);
ret = strvec_create (n + 1);
{
char *value;
char tflag[N_SHOPT_OPTIONS];
- int vsize, i, vptr, *ip, exported;
+ int i, exported;
+ size_t vsize, vptr;
SHELL_VAR *v;
for (vsize = i = 0; shopt_vars[i].name; i++)
This file is ulimit.def, from which is created ulimit.c.
It implements the builtin "ulimit" in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static ULCMD *cmdlist;
static int ncmd;
-static int cmdlistsz;
+static size_t cmdlistsz;
#if !defined (HAVE_RESOURCE) && !defined (HAVE_ULIMIT)
long
This file is wait.def, from which is created wait.c.
It implements the builtin "wait" in Bash.
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
set_waitlist (WORD_LIST *list)
{
sigset_t set, oset;
- int job, r, njob;
+ int job, njob;
intmax_t pid;
WORD_LIST *l;
#endif
}
+ rv = EXECUTION_SUCCESS; /* suppress uninitialized use warnings */
old_flags = command->flags;
COPY_PROCENV (top_level, save_top_level);
command->flags &= ~(CMD_TIME_PIPELINE|CMD_TIME_POSIX);
size_increment = 1;
/* Now the argument, if any. */
- for (firstarg = (char *)NULL, start = i; WHITECHAR(i); i++)
+ for (firstarg = NULL, start = i; WHITECHAR(i); i++)
;
/* If there is more text on the line, then it is an argument for the
if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
{
char *interp;
- int ilen;
+ size_t ilen;
interp = getinterp (sample, sample_len, (int *)NULL);
ilen = strlen (interp);
static struct lvalue curlval = {0, 0, 0, -1};
static struct lvalue lastlval = {0, 0, 0, -1};
-static int _is_arithop (int);
+static int is_arithop (int);
+static int is_multiop (int);
static void readtok (void); /* lexical analyzer */
static void init_lvalue (struct lvalue *);
/* Global var which contains the stack of expression contexts. */
static EXPR_CONTEXT **expr_stack;
static int expr_depth; /* Location in the stack. */
-static int expr_stack_size; /* Number of slots already allocated. */
+static size_t expr_stack_size; /* Number of slots already allocated. */
#if defined (ARRAY_VARS)
extern const char * const bash_badsub_errmsg;
static intmax_t
exppower (void)
{
- register intmax_t val1, val2, c;
+ register intmax_t val1, val2;
val1 = expunary ();
while (curtok == POWER)
}
static inline int
-_is_multiop (int c)
+is_multiop (int c)
{
switch (c)
{
}
static inline int
-_is_arithop (int c)
+is_arithop (int c)
{
switch (c)
{
static void
readtok (void)
{
- register char *cp, *xp;
- register unsigned char c, c1;
- register int e;
- struct lvalue lval;
+ char *cp, *xp;
+ unsigned char c, c1;
+ int e;
/* Skip leading whitespace. */
cp = tp;
- c = e = 0;
+ c = 0;
+ e = 0;
while (cp && (c = *cp) && (cr_whitespace (c)))
cp++;
assigntok = c; /* a OP= b */
c = OP_ASSIGN;
}
- else if (_is_arithop (c) == 0)
+ else if (is_arithop (c) == 0)
{
cp--;
/* use curtok, since it hasn't been copied to lasttok yet */
- if (curtok == 0 || _is_arithop (curtok) || _is_multiop (curtok))
+ if (curtok == 0 || is_arithop (curtok) || is_multiop (curtok))
evalerror (_("arithmetic syntax error: operand expected"));
else
evalerror (_("arithmetic syntax error: invalid arithmetic operator"));
/* declarations for functions defined in lib/sh/shquote.c */
extern char *sh_single_quote (const char *);
extern char *sh_double_quote (const char *);
-extern char *sh_mkdoublequoted (const char *, int, int);
+extern char *sh_mkdoublequoted (const char *, size_t, int);
extern char *sh_un_double_quote (char *);
extern char *sh_backslash_quote (char *, const char *, int);
extern char *sh_backslash_quote_for_double_quotes (char *, int);
extern ssize_t zgetline (int, char **, size_t *, int, int);
/* declarations for functions defined in lib/sh/zmapfd.c */
-extern int zmapfd (int, char **, char *);
+extern int zmapfd (int, char **, const char *);
/* declarations for functions defined in lib/sh/zread.c */
extern ssize_t zread (int, char *, size_t);
static char *_find_user_command_internal (const char *, int);
static char *find_user_command_internal (const char *, int);
static char *find_user_command_in_path (const char *, char *, int, int *);
-static char *find_in_path_element (const char *, char *, int, int, struct stat *, int *);
+static char *find_in_path_element (const char *, char *, int, size_t, struct stat *, int *);
static char *find_absolute_program (const char *, int);
static char *get_next_path_element (char *, int *);
user_command_matches (const char *name, int flags, int state)
{
register int i;
- int path_index, name_len;
+ int path_index;
+ size_t name_len;
char *path_list, *path_element, *match;
struct stat dotinfo;
static char **match_list = NULL;
- static int match_list_size = 0;
- static int match_index = 0;
+ static size_t match_list_size = 0;
+ static size_t match_index = 0;
if (state == 0)
{
}
static char *
-find_in_path_element (const char *name, char *path, int flags, int name_len, struct stat *dotinfop, int *rflagsp)
+find_in_path_element (const char *name, char *path, int flags, size_t name_len, struct stat *dotinfop, int *rflagsp)
{
int status;
char *full_path, *xpath;
find_user_command_in_path (const char *name, char *path_list, int flags, int *rflagsp)
{
char *full_path, *path;
- int path_index, name_len, rflags;
+ int path_index, rflags;
+ size_t name_len;
struct stat dotinfo;
/* We haven't started looking, so we certainly haven't seen
int
assignment (const char *string, int flags)
{
- register unsigned char c;
- register int newi, indx;
+ unsigned char c;
+ int newi, indx;
c = string[indx = 0];
{
const char *r;
char *ret;
- int l;
+ size_t l;
for (r = s; *r && *r != '/'; r++)
{
bp->b_fd = fd;
bp->b_buffer = buffer;
bp->b_size = bufsize;
- bp->b_used = bp->b_inputp = bp->b_flag = 0;
+ bp->b_used = 0;
+ bp->b_inputp = bp->b_flag = 0;
if (bufsize == 1)
bp->b_flag |= B_UNBUFF;
if (O_TEXT && (fcntl (fd, F_GETFL) & O_TEXT) != 0)
/* This file works with both POSIX and BSD systems. It implements job
control. */
-/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
{
register int i;
int os;
- PROCESS *discard;
if (js.j_jobslots == 0 || jobs_list_frozen)
return;
pid_t
make_child (char *command, int flags)
{
- int async_p, forksleep;
- sigset_t set, oset, termset, chldset, oset_copy;
+ int async_p;
+ unsigned int forksleep;
+ sigset_t set, oset, oset_copy;
pid_t pid;
SigHandler *oterm;
queue_sigchld++;
/* XXX could use js.j_firstj here */
- for (job = 0, dir = (char *)NULL; job < js.j_jobslots; job++)
+ for (job = 0, dir = NULL; job < js.j_jobslots; job++)
{
if (jobs[job] && IS_NOTIFIED (job) == 0)
{
/* glob.c -- file-name wildcard pattern matching for Bash.
- Copyright (C) 1985-2022 Free Software Foundation, Inc.
+ Copyright (C) 1985-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne-Again SHell.
static int
skipname (char *pat, char *dname, int flags)
{
- int i;
-
#if EXTENDED_GLOB
if (extglob_pattern_p (pat)) /* XXX */
return (extglob_skipname (pat, dname, flags));
static int
wskipname (wchar_t *pat, wchar_t *dname, int flags)
{
- int i;
-
if (glob_always_skip_dot_and_dotdot && WDOT_OR_DOTDOT (dname))
return 1;
mbstate_t ps;
size_t len, n;
wchar_t *wpathname;
- int i, j;
wchar_t *orig_wpathname;
if (mbsmbchar (pathname) == 0)
static struct globval *
finddirs (char *pat, char *sdir, int flags, struct globval **ep, int *np)
{
- char **r, *n;
+ char **r;
int ndirs;
struct globval *ret, *e, *g;
glob_vector (char *pat, char *dir, int flags)
{
DIR *d;
- register struct dirent *dp;
- struct globval *lastlink, *e, *dirlist;
- register struct globval *nextlink;
- register char *nextname, *npat, *subdir;
- unsigned int count;
- int lose, skip, ndirs, isdir, sdlen, add_current, patlen;
- register char **name_vector;
- register unsigned int i;
+ struct dirent *dp;
+ struct globval *nextlink, *lastlink, *e, *dirlist;
+ char *nextname, *npat, *subdir;
+ unsigned int count, i;
+ int lose, skip, ndirs, isdir, add_current;
+ size_t patlen, sdlen;
+ char **name_vector;
int mflags; /* Flags passed to strmatch (). */
int pflags; /* flags passed to sh_makepath () */
int hasglob; /* return value from glob_pattern_p */
char *convfn;
lastlink = 0;
- count = lose = skip = add_current = 0;
+ count = 0;
+ lose = skip = add_current = 0;
firstmalloc = 0;
nalloca = 0;
hasglob = 0;
if (skip == 0 && ((hasglob = glob_pattern_p (pat)) == 0 || hasglob == 2))
{
- int dirlen;
+ size_t dirlen;
struct stat finfo;
if (glob_testdir (dir, 0) < 0)
static char **
glob_dir_to_array (char *dir, char **array, int flags)
{
- register unsigned int i, l;
+ unsigned int i;
+ size_t l;
int add_slash;
char **result, *new;
struct stat sb;
char **result, **new_result;
unsigned int result_size;
char *directory_name, *filename, *dname, *fn;
- unsigned int directory_len;
+ size_t directory_len;
int free_dirname; /* flag */
int dflags, hasglob;
if (directory_len > 0 && (hasglob = glob_pattern_p (directory_name)) == 1)
{
char **directories, *d, *p;
- register unsigned int i;
+ unsigned int i;
int all_starstar, last_starstar;
all_starstar = last_starstar = 0;
so we can compensate if filename is [star][star] */
if ((flags & GX_GLOBSTAR) && all_starstar == 0)
{
- int dl, prev;
+ size_t dl, prev;
prev = dl = directory_len;
while (dl >= 4 && d[dl - 1] == '/' &&
d[dl - 2] == '*' &&
/* Special handling for symlinks to directories with globstar on */
if (all_starstar && (dflags & GX_NULLDIR) == 0)
{
- int dlen;
-
/* If we have a directory name that is not null (GX_NULLDIR above)
and is a symlink to a directory, we return the symlink if
we're not `descending' into it (filename[0] == 0) and return
else
{
char **array;
- register unsigned int l;
+ unsigned int l;
/* If we're expanding **, we don't need to glue the directory
name to the results; we've already done it in glob_vector */
NULL_PLACEHOLDER (temp_results))
#undef NULL_PLACEHOLDER
{
- register int i, n;
+ int i, n;
for (n = 0; temp_results[n] && *temp_results[n] == 0; n++)
;
i = n;
-/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2017,2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
size_t max;
{
CHAR c;
- int matlen, bracklen, t, in_cclass, in_collsym, in_equiv;
+ int matlen, bracklen, in_cclass, in_collsym, in_equiv;
if (*pat == 0)
return (0);
-/* Copyright (C) 1991-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
globbing. */
-/* Copyright (C) 1991-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
{
static char s1[2] = { ' ', '\0' };
static char s2[2] = { ' ', '\0' };
- int ret;
/* Eight bits only. Period. */
c1 &= 0xFF;
{
static wchar_t s1[2] = { L' ', L'\0' };
static wchar_t s2[2] = { L' ', L'\0' };
- int r;
if (c1 == c2)
return 0;
int ret;
size_t n;
wchar_t *wpattern, *wstring;
- size_t plen, slen, mplen, mslen;
glob_recursion_depth = 0;
size_t cur_max; /* XXX - locale_cur_max */
char buf[64], *destptr, *tmp_dest;
unsigned char uc;
- mbstate_t prev_state;
cur_max = MB_CUR_MAX;
if (cur_max > sizeof (buf)) /* Holy cow. */
/* bind.c -- key binding and startup file support for the readline library. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
/* Stack of previous values of parsing_conditionalized_out. */
static unsigned char *if_stack = (unsigned char *)NULL;
static int if_stack_depth;
-static int if_stack_size;
+static size_t if_stack_size;
/* Push _rl_parsing_conditionalized_out, and set parser state based
on ARGS. */
if (_rl_stricmp (string, "set") == 0)
{
char *var, *value, *e;
- int s;
var = string + i;
/* Make VAR point to start of variable name. */
if (*funname == '\'' || *funname == '"')
{
char useq[2];
- int fl = strlen (funname);
+ size_t fl = strlen (funname);
useq[0] = key; useq[1] = '\0';
if (fl && funname[fl - 1] == *funname)
static char *users_dirname = (char *)NULL;
static int filename_len;
char *temp, *dentry, *convfn;
- int dirlen, dentlen, convlen;
+ size_t dirlen;
+ int dentlen, convlen;
int tilde_dirname;
struct dirent *entry;
/* Now that we have some state, we can read the directory. */
entry = (struct dirent *)NULL;
+ convfn = dentry = 0;
while (directory && (entry = readdir (directory)))
{
convfn = dentry = entry->d_name;
static int full_completion = 0; /* set to 1 if menu completion should reinitialize on next call */
static int orig_start, orig_end;
static char quote_char;
- static int delimiter, cstate;
+ static int delimiter;
/* The first time through, we generate the list of matches and set things
up to insert them. */
/* histexpand.c -- history expansion. */
-/* Copyright (C) 1989-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2021,2023 Free Software Foundation, Inc.
This file contains the GNU History Library (History), a set of
routines for managing the text of previously typed lines.
int i, n, starting_index;
int substitute_globally, subst_bywords, want_quotes, print_only;
char *event, *temp, *result, *tstr, *t, c, *word_spec;
- int result_len;
+ size_t result_len;
#if defined (HANDLE_MULTIBYTE)
mbstate_t ps;
#define ADD_STRING(s) \
do \
{ \
- int sl = strlen (s); \
+ size_t sl = strlen (s); \
j += sl; \
if (j >= result_len) \
{ \
int
history_expand (char *hstring, char **output)
{
- register int j;
- int i, r, l, passc, cc, modified, eindex, only_printing, dquote, squote, flag;
+ int j;
+ int i, r, passc, cc, modified, eindex, only_printing, dquote, squote, flag;
+ size_t l;
char *string;
/* The output string, and its length. */
- int result_len;
+ size_t result_len;
char *result;
#if defined (HANDLE_MULTIBYTE)
{
register int i, len;
char *result;
- int size, offset;
+ size_t size, offset;
char **list;
/* XXX - think about making history_tokenize return a struct array,
static int
history_tokenize_word (const char *string, int ind)
{
- register int i, j;
+ int i, j;
int delimiter, nestdelim, delimopen;
i = ind;
history_tokenize_internal (const char *string, int wind, int *indp)
{
char **result;
- register int i, start, result_index, size;
+ int i, start, result_index;
+ size_t size;
/* If we're searching for a string that's not part of a word (e.g., " "),
make sure we set *INDP to a reasonable value. */
/* Get a token, and stuff it into RESULT. The tokens are split
exactly where the shell would split them. */
- for (i = result_index = size = 0, result = (char **)NULL; string[i]; )
+ for (i = result_index = 0, size = 0, result = (char **)NULL; string[i]; )
{
/* Skip leading whitespace. */
for (; string[i] && fielddelim (string[i]); i++)
{
char *return_val;
const char *home;
- int home_len;
+ size_t home_len;
return_val = filename ? savestring (filename) : (char *)NULL;
char *ret, linkbuf[PATH_MAX+1];
size_t len;
ssize_t n;
- struct stat fs;
fn = filename;
#if defined (HAVE_READLINK)
char *ret, linkbuf[PATH_MAX+1];
size_t len;
ssize_t n;
- struct stat fs;
int pid;
fn = filename;
register int i;
char *output, *tempname, *histname;
int file, mode, rv, exists;
- struct stat finfo, nfinfo;
+ struct stat finfo;
#ifdef HISTORY_USE_MMAP
size_t cursize;
Suggested by Peter Ho (peter@robosts.oxford.ac.uk). */
{
HIST_ENTRY **the_history; /* local */
- register int j;
- int buffer_size;
+ size_t j;
+ size_t buffer_size;
char *buffer;
the_history = history_list ();
if (history_stifled && (history_length == history_max_entries))
{
- register int i;
-
/* If the history is stifled, and history_length is zero,
and it equals history_max_entries, we don't save items. */
if (history_length == 0)
static int
history_search_internal (const char *string, int direction, int flags)
{
- register int i, reverse;
- register char *line;
- register int line_index;
- int string_len, anchored, patsearch;
+ int i, reverse;
+ char *line;
+ int line_index;
+ size_t string_len;
+ int anchored, patsearch;
HIST_ENTRY **the_history; /* local */
i = history_offset;
/* */
/* **************************************************************** */
-/* Copyright (C) 1987-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2021,2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
int
_rl_isearch_dispatch (_rl_search_cxt *cxt, int c)
{
- int n, wstart, wlen, limit, cval, incr;
+ int n, wstart, wlen, limit, cval;
char *paste;
size_t pastelen;
int j;
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
{
- int j;
+ int w;
if (cxt->mb[0] == 0 || cxt->mb[1] == 0)
cxt->search_string[cxt->search_string_index++] = cxt->mb[0];
else
- for (j = 0; j < wlen; )
- cxt->search_string[cxt->search_string_index++] = cxt->mb[j++];
+ for (w = 0; w < wlen; )
+ cxt->search_string[cxt->search_string_index++] = cxt->mb[w++];
}
else
#endif
/* kill.c -- kill ring management. */
-/* Copyright (C) 1994-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1994-2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
int
rl_bracketed_paste_begin (int count, int key)
{
- int retval, c;
- size_t len, cap;
+ int retval;
+ size_t len;
char *buf;
buf = _rl_bracketed_text (&len);
_rl_read_bracketed_paste_prefix (int c)
{
char pbuf[BRACK_PASTE_SLEN+1], *pbpref;
- int key, ind, j;
+ int key, ind;
pbpref = BRACK_PASTE_PREF; /* XXX - debugging */
if (c != pbpref[0])
int
_rl_bracketed_read_mbstring (char *mb, int mlen)
{
- int c, r;
+ int c;
c = _rl_bracketed_read_key ();
if (c < 0)
static char *current_macro = (char *)NULL;
/* The size of the buffer allocated to current_macro. */
-static int current_macro_size;
+static size_t current_macro_size;
/* The index at which characters are being added to current_macro. */
static int current_macro_index;
/* mbutil.c -- readline multibyte character utility functions */
-/* Copyright (C) 2001-2021 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2021,2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
static int
_rl_find_prev_utf8char (const char *string, int seed, int find_non_zero)
{
- char *s;
unsigned char b;
int save, prev;
size_t len;
size_t tmp;
WCHAR_T wc;
mbstate_t ps;
- int l;
+ size_t l;
if (MB_LEN_MAX == 1 || rl_byte_oriented)
return ((WCHAR_T) buf[ind]);
int
_rl_free_saved_history_line (void)
{
- UNDO_LIST *orig;
-
if (_rl_saved_line_for_history)
{
if (rl_undo_list && rl_undo_list == (UNDO_LIST *)_rl_saved_line_for_history->data)
/* readline.c -- a general facility for reading lines of input
with emacs style editing and completion. */
-/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
int rl_executing_key;
char *rl_executing_keyseq = 0;
-int _rl_executing_keyseq_size = 0;
+size_t _rl_executing_keyseq_size = 0;
struct _rl_cmd _rl_pending_command;
struct _rl_cmd *_rl_command_to_execute = (struct _rl_cmd *)NULL;
char *prompt;
/* global state */
- int rlstate;
+ int rlstate; /* XXX -- needs to be unsigned long */
int done;
Keymap kmap;
extern _rl_keyseq_cxt *_rl_kscxt;
extern int _rl_keyseq_timeout;
-extern int _rl_executing_keyseq_size;
+extern size_t _rl_executing_keyseq_size;
extern rl_hook_func_t *_rl_internal_startup_hook;
static int _rl_history_search_flags;
static char *history_search_string;
-static int history_string_size;
+static size_t history_string_size;
static void make_history_line_current (HIST_ENTRY *);
static int noninc_search_from_pos (char *, int, int, int, int *);
/* **************************************************************** */
#if defined (HAVE_POSIX_SIGNALS)
-static sigset_t sigint_set, sigint_oset;
static sigset_t sigwinch_set, sigwinch_oset;
#else /* !HAVE_POSIX_SIGNALS */
# if defined (HAVE_BSD_SIGNALS)
/* text.c -- text handling commands for readline. */
-/* Copyright (C) 1987-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2021,2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
void
rl_free_undo_list (void)
{
- UNDO_LIST *release, *orig_list;
+ UNDO_LIST *orig_list;
orig_list = rl_undo_list;
_rl_free_undo_list (rl_undo_list);
char *
_rl_strindex (const char *s1, const char *s2)
{
- register int i, l, len;
+ int i;
+ size_t l, len;
for (i = 0, l = strlen (s2), len = strlen (s1); (len - i) >= l; i++)
if (_rl_strnicmp (s1 + i, s2, l) == 0)
/* vi_mode.c -- A vi emulation mode for Bash.
Derived from code written by Jeff Sparkes (jsparkes@bnr.ca). */
-/* Copyright (C) 1987-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2021,2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
/* If non-zero, we have text inserted after a c[motion] command that put
us implicitly into insert mode. Some people want this text to be
attached to the command so that it is `redoable' with `.'. */
-static int vi_continued_command;
static char *vi_insert_buffer;
static int vi_insert_buffer_size;
int
rl_vi_domove (int x, int *ignore)
{
- int r;
_rl_vimotion_cxt *m;
m = _rl_vimvcxt;
/* 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.
}
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
/* makepath.c - glue PATH and DIR together into a full pathname. */
-/* Copyright (C) 1987-2020,2022 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.
char *
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')
/* mbscasecmp - case-insensitive multibyte string comparison. */
-/* Copyright (C) 2009-2022 Free Software Foundation, Inc.
+/* Copyright (C) 2009-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
int
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;
char *
strchr (const char *string, int c)
{
- register char *s;
+ char *s;
for (s = string; s && *s; s++)
if (*s == c)
char *
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);
/* pathphys.c -- return pathname with all symlinks expanded. */
-/* Copyright (C) 2000-2020,2022 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.
extern char *get_working_directory (char *);
static inline int
-_path_readlink (char *path, char *buf, int bufsiz)
+_path_readlink (char *path, char *buf, size_t bufsiz)
{
#ifdef HAVE_READLINK
return readlink (path, buf, bufsiz);
{
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;
+ size_t linklen;
linklen = strlen (path);
char *
sh_single_quote (const char *string)
{
- register int c;
+ int c;
char *result, *r;
const char *s;
char *
sh_double_quote (const char *string)
{
- register unsigned char c;
+ unsigned char c;
int mb_cur_max;
char *result, *r;
size_t slen;
/* Turn S into a simple double-quoted string. If FLAGS is non-zero, quote
double quote characters in S with backslashes. */
char *
-sh_mkdoublequoted (const char *s, int slen, int 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;
char *
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);
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);
/* spell.c -- spelling correction for pathnames. */
-/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
char *
dirspell (char *dirname)
{
- int n;
+ size_t n;
char *guess;
n = (strlen (dirname) * 3 + 1) / 2 + 1;
strlist_create (size_t n)
{
STRINGLIST *ret;
- register int i;
+ int i;
ret = (STRINGLIST *)xmalloc (sizeof (STRINGLIST));
if (n)
STRINGLIST *
strlist_resize (STRINGLIST *sl, size_t n)
{
- register int i;
+ size_t i;
if (sl == 0)
return (sl = strlist_create (n));
strlist_copy (STRINGLIST *sl)
{
STRINGLIST *new;
- register int i;
+ int i;
if (sl == 0)
return ((STRINGLIST *)0);
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;
STRINGLIST *
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);
STRINGLIST *
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)
void
strlist_print (STRINGLIST *sl, const char *prefix)
{
- register int i;
+ int i;
if (sl == 0)
return;
void
strlist_walk (STRINGLIST *sl, sh_strlist_map_func_t *func)
{
- register int i;
+ int i;
if (sl == 0)
return;
/* strtrans.c - Translate and untranslate strings with ANSI-C escape sequences. */
-/* Copyright (C) 2000-2015,2022 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.
ansicstr (const char *string, int len, int flags, int *sawc, int *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)
#else
ret = (char *)xmalloc (2*len + 1); /* 2*len for possible CTLESC */
#endif
- for (r = ret, s = (char *)string; s && *s; )
+ for (r = ret, s = string; s && *s; )
{
c = *s++;
if (c != '\\' || *s == '\0')
char *
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;
*r++ = '$';
*r++ = '\'';
- for (s = (char *)str; c = *s; s++)
+ 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)
* tmpfile.c - functions to create and safely open temp files for the shell.
*/
-/* Copyright (C) 2000-2020,2022 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.
char *
sh_mktmpdir (const char *nameroot, int flags)
{
- char *filename, *tdir, *dirname;
+ char *filename;
+#ifdef USE_MKDTEMP
+ char *tdir, *dirname;
const char *lroot;
int fd, tdlen;
-#ifdef USE_MKDTEMP
filename = (char *)xmalloc (PATH_MAX + 1);
tdir = get_tmpdir (flags);
tdlen = strlen (tdir);
fsleep(unsigned int sec, unsigned int usec)
{
int e, r;
- sigset_t blocked_sigs, prevmask;
+ sigset_t blocked_sigs;
#if defined (HAVE_PSELECT)
struct timespec ts;
#else
+ sigset_t prevmask;
struct timeval tv;
#endif
char *
utf8_mbsmbchar (const char *str)
{
- register char *s;
+ char *s;
for (s = (char *)str; *s; s++)
if ((*s & 0xc0) == 0x80)
int
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++)
{
/* 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,2022 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.
ssize_t
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))
/* Dump contents of file descriptor FD to *OSTR. FN is the filename for
error messages (not used right now). */
int
-zmapfd (int fd, char **ostr, char *fn)
+zmapfd (int fd, char **ostr, const char *fn)
{
ssize_t nr;
int rval;
/* tilde.c -- Tilde expansion code (~/foo := $HOME/foo). */
-/* Copyright (C) 1988-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1988-2020,2023 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
glue_prefix_and_suffix (char *prefix, const char *suffix, int suffind)
{
char *ret;
- int plen, slen;
+ size_t plen, slen;
plen = (prefix && *prefix) ? strlen (prefix) : 0;
slen = strlen (suffix + suffind);
reset_locale_vars (void)
{
char *t, *x;
+ int retval;
+
#if defined (HAVE_SETLOCALE)
if (lang == 0 || *lang == '\0')
maybe_make_export_env (); /* trust that this will change environment for setlocale */
if (setlocale (LC_ALL, lang ? lang : "") == 0)
return 0;
+ retval = 1;
x = 0;
# if defined (LC_CTYPE)
x = setlocale (LC_CTYPE, get_locale_var ("LC_CTYPE"));
+ if (x == 0)
+ retval = 0;
# endif
# if defined (LC_COLLATE)
t = setlocale (LC_COLLATE, get_locale_var ("LC_COLLATE"));
+ if (t == 0)
+ retval = 0;
# endif
# if defined (LC_MESSAGES)
t = setlocale (LC_MESSAGES, get_locale_var ("LC_MESSAGES"));
+ if (t == 0)
+ retval = 0;
# endif
# if defined (LC_NUMERIC)
t = setlocale (LC_NUMERIC, get_locale_var ("LC_NUMERIC"));
+ if (t == 0)
+ retval = 0;
# endif
# if defined (LC_TIME)
t = setlocale (LC_TIME, get_locale_var ("LC_TIME"));
+ if (t == 0)
+ retval = 0;
# endif
locale_setblanks ();
# endif
u32reset ();
#endif
- return 1;
+ return retval;
}
#if defined (TRANSLATABLE_STRINGS)
/* make_cmd.c -- Functions for making instances of the various
parser constructs. */
-/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
void
make_here_document (REDIRECT *temp, int lineno)
{
- int kill_leading, redir_len;
+ int kill_leading;
+ size_t redir_len;
char *redir_word, *document, *full_line;
- int document_index, document_size, delim_unquoted;
+ int document_index, delim_unquoted;
+ size_t document_size;
if (temp->instruction != r_deblank_reading_until &&
temp->instruction != r_reading_until)
kill_leading = temp->instruction == r_deblank_reading_until;
full_line = document = (char *)NULL;
- document_index = document_size = 0;
+ document_index = 0;
+ document_size = 0;
delim_unquoted = (temp->redirectee.filename->flags & W_QUOTED) == 0;
while (full_line = read_secondary_line (delim_unquoted))
{
register char *line;
- int len;
+ size_t len;
here_doc_first_line = 0;
line = full_line;
{
REDIRECT *temp;
WORD_DESC *w;
- int wlen;
+ size_t wlen;
intmax_t lfd;
temp = (REDIRECT *)xmalloc (sizeof (REDIRECT));
/* parse.y - Yacc grammar for bash. */
-/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
yy_readline_get (void)
{
SigHandler *old_sigint;
- int line_len;
+ size_t line_len;
unsigned char c;
if (current_readline_line == 0)
read_secondary_line (int remove_quoted_newline)
{
char *ret;
- int n, c;
prompt_string_pointer = &ps2_prompt;
if (SHOULD_PROMPT ())
static char *
mk_alexpansion (const char *s)
{
- int l;
+ size_t l;
char *r;
l = strlen (s);
sh_input_line_state_t ls;
int nc, sflags;
size_t slen;
- char *ret, *ep;
+ char *ep;
COMMAND *cmd;
if (*string == 0)
/* Try to quote anything the user can set in the file system */
if (promptvars || posixly_correct)
{
- char *t;
t = sh_strvis (temp);
temp = sh_backslash_quote_for_double_quotes (t, 0);
free (t);
second argument of Q_DOUBLE_QUOTES if we use this
function here. */
{
- char *t;
t = sh_strvis (t_string);
temp = sh_backslash_quote_for_double_quotes (t, 0);
free (t);
void
restore_parser_state (sh_parser_state_t *ps)
{
- int i;
-
if (ps == 0)
return;
ignore_globbed_names (char **names, sh_ignore_func_t *name_func)
{
char **newnames;
- int n, i;
+ size_t n, i;
for (i = 0; names[i]; i++)
;
struct ign {
char *val;
- int len, flags;
+ size_t len;
+ int flags;
};
typedef int sh_iv_item_func_t (struct ign *);
#endif
#define STRDUP(x) ((x) ? savestring (x) : (char *)NULL)
-typedef SHELL_VAR **SVFUNC ();
+typedef SHELL_VAR **SVFUNC (void);
#ifndef HAVE_STRPBRK
extern char *strpbrk (char *, char *);
static int
shouldexp_filterpat (char *s)
{
- register char *p;
+ char *p;
for (p = s; p && *p; p++)
{
completions_to_stringlist (char **matches)
{
STRINGLIST *sl;
- int mlen, i, n;
+ int i, n;
+ size_t mlen;
mlen = (matches == 0) ? 0 : strvec_len (matches);
sl = strlist_create (mlen + 1);
{
#ifdef ALIAS
alias_t **alias_list;
- register int i, n;
+ int i;
+ size_t n;
STRINGLIST *sl;
alias_list = all_aliases ();
{
SHELL_VAR **vlist;
STRINGLIST *sl;
- register int i, n;
+ int i;
+ size_t n;
vlist = (*svfunc) ();
if (vlist == 0)
it_init_builtins (ITEMLIST *itp)
{
STRINGLIST *sl;
- register int i, n;
+ int i;
+ size_t n;
sl = strlist_create (num_shell_builtins);
for (i = n = 0; i < num_shell_builtins; i++)
it_init_enabled (ITEMLIST *itp)
{
STRINGLIST *sl;
- register int i, n;
+ int i;
+ size_t n;
sl = strlist_create (num_shell_builtins);
for (i = n = 0; i < num_shell_builtins; i++)
it_init_disabled (ITEMLIST *itp)
{
STRINGLIST *sl;
- register int i, n;
+ int i;
+ size_t n;
sl = strlist_create (num_shell_builtins);
for (i = n = 0; i < num_shell_builtins; i++)
it_init_helptopics (ITEMLIST *itp)
{
STRINGLIST *sl;
- register int i, n;
+ int i;
+ size_t n;
sl = strlist_create (num_shell_builtins);
for (i = n = 0; i < num_shell_builtins; i++)
{
#if defined (JOB_CONTROL)
STRINGLIST *sl;
- register int i;
- register PROCESS *p;
+ int i;
+ PROCESS *p;
char *s, *t;
JOB *j;
JOB_STATE ws; /* wanted state */
it_init_keywords (ITEMLIST *itp)
{
STRINGLIST *sl;
- register int i, n;
+ int i;
+ size_t n;
for (n = 0; word_token_alist[n].word; n++)
;
gen_matches_from_itemlist (ITEMLIST *itp, const char *text)
{
STRINGLIST *ret, *sl;
- int tlen, i, n;
+ size_t tlen, i, n;
char *ntxt;
if ((itp->flags & (LIST_DIRTY|LIST_DYNAMIC)) ||
{
WORD_LIST *l, *l2;
STRINGLIST *sl;
- int nw, tlen;
+ size_t nw, tlen;
char *ntxt; /* dequoted TEXT to use in comparisons */
if (cs->words == 0 || cs->words[0] == '\0')
int nw, int cw)
{
char *csbuf, *cscmd, *t;
- int cmdlen, cmdsize, n, ws, we;
+ int ws, we;
+ size_t cmdlen, cmdsize, n;
WORD_LIST *cmdlist, *cl;
WORD_DESC *tw;
STRINGLIST *sl;
/* print_command -- A way to make readable commands from a command tree. */
-/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
static void newline (char *);
static void indent (int);
static void semicolon (void);
-static void the_printed_command_resize (int);
+static void the_printed_command_resize (size_t);
static void make_command_string_internal (COMMAND *);
static void _print_word_list (WORD_LIST *, char *, PFUNC *);
#define PRINTED_COMMAND_GROW_SIZE 128
char *the_printed_command = (char *)NULL;
-int the_printed_command_size = 0;
+size_t the_printed_command_size = 0;
int command_string_index = 0;
int xtrace_fd = -1;
/* A buffer to indicate the indirection level (PS4) when set -x is enabled. */
static char *indirection_string = 0;
-static int indirection_stringsiz = 0;
+static size_t indirection_stringsiz = 0;
/* Print COMMAND (a command tree) on standard output. */
void
register int i, j;
char *ps4;
char ps4_firstc[MB_LEN_MAX+1];
- int ps4_firstc_len, ps4_len, ineed, old;
+ size_t ps4_firstc_len, ps4_len, ineed;
+ int old;
DECLARE_MBSTATE;
ps4 = get_string_value ("PS4");
print_redirection_list (REDIRECT *redirects)
{
REDIRECT *heredocs, *hdtail, *newredir;
- char *rw;
heredocs = (REDIRECT *)NULL;
hdtail = heredocs;
else
hdtail = heredocs = newredir;
}
-#if 0
- /* Remove this heuristic now that the command printing code doesn't
- unconditionally put in the redirector file descriptor. */
- else if (redirects->instruction == r_duplicating_output_word && (redirects->flags & REDIR_VARASSIGN) == 0 && redirects->redirector.dest == 1)
- {
- /* Temporarily translate it as the execution code does. */
- rw = redirects->redirectee.filename->word;
- if (rw && *rw != '-' && DIGIT (*rw) == 0 && EXPCHAR (*rw) == 0)
- redirects->instruction = r_err_and_out;
- print_redirection (redirects);
- redirects->instruction = r_duplicating_output_word;
- }
-#endif
else
print_redirection (redirects);
}
static char *indentation_string;
-static int indentation_size;
+static size_t indentation_size;
static void
indent (int amount)
static void
cprintf (const char *control, ...)
{
- register const char *s;
+ const char *s;
char char_arg[2], *argp, intbuf[INT_STRLEN_BOUND (unsigned int) + 1];
- int digit_arg, arg_len, c;
+ int digit_arg, c;
+ size_t arg_len;
va_list args;
SH_VA_START (args, control);
/* Ensure that there is enough space to stuff LENGTH characters into
THE_PRINTED_COMMAND. */
static void
-the_printed_command_resize (int length)
+the_printed_command_resize (size_t length)
{
if (the_printed_command == 0)
{
}
else if ((command_string_index + length) >= the_printed_command_size)
{
- int new;
+ size_t new;
new = command_string_index + length + 1;
/* Round up to the next multiple of PRINTED_COMMAND_GROW_SIZE. */
arg_index = 1;
if (arg_index > argc)
arg_index = argc;
- command_execution_string = shell_script_filename = (char *)NULL;
+ command_execution_string = shell_script_filename = NULL;
want_pending_command = locally_skip_execution = read_from_stdin = 0;
default_input = stdin;
#if defined (BUFFERED_INPUT)
}
arg_index++;
}
- this_command_name = (char *)NULL;
+ this_command_name = NULL;
/* First, let the outside world know about our interactive status.
A shell is interactive if the `-i' flag was given, or if all of
#if defined (BUFFERED_INPUT)
default_buffered_input = fileno (stdin); /* == 0 */
#else
- setbuf (default_input, (char *)NULL);
+ setbuf (default_input, NULL);
#endif /* !BUFFERED_INPUT */
read_from_stdin = 1;
}
{
#if defined (MALLOC_DEBUG) && defined (USING_BASH_MALLOC)
if (malloc_trace_at_exit && (subshell_environment & (SUBSHELL_COMSUB|SUBSHELL_PROCSUB)) == 0)
- trace_malloc_stats (get_name_for_error (), (char *)NULL);
+ trace_malloc_stats (get_name_for_error (), NULL);
/* mlocation_write_table (); */
#endif
FREE (current_user.user_name);
FREE (current_user.shell);
FREE (current_user.home_dir);
- current_user.user_name = current_user.shell = current_user.home_dir = (char *)NULL;
+ current_user.user_name = current_user.shell = current_user.home_dir = NULL;
}
current_user.uid = u;
current_user.gid = getgid ();
if (exec_argv0)
{
free (exec_argv0);
- exec_argv0 = (char *)NULL;
+ exec_argv0 = NULL;
}
if (file_isdir (filename))
if (alist[i].token == token)
return (savestring (alist[i].word));
}
- return ((char *)NULL);
+ return (NULL);
}
int
char *
substring (const char *string, int start, int end)
{
- register int len;
- register char *result;
+ int len;
+ char *result;
len = end - start;
result = (char *)xmalloc (len + 1);
{
size_t patlen, replen, templen, tempsize, i;
int repl;
- char *temp, *r;
+ char *temp, *r;;
patlen = strlen (pat);
replen = strlen (rep);
- for (temp = (char *)NULL, i = templen = tempsize = 0, repl = 1; string[i]; )
+ for (temp = NULL, i = templen = tempsize = 0, repl = 1; string[i]; )
{
if (repl && STREQN (string + i, pat, patlen))
{
char *
strcreplace (const char *string, int c, const char *text, int flags)
{
- char *ret, *r, *p, *t;
+ char *ret, *r, *t;
+ const char *p;
size_t len, rlen, ind, tlen;
int do_glob, escape_backslash;
rlen = len + strlen (string) + 2;
ret = (char *)xmalloc (rlen);
- for (p = (char *)string, r = ret; p && *p; )
+ for (p = string, r = ret; p && *p; )
{
if (*p == c)
{
extern int singlequote_translations;
extern int extended_quote;
-#if defined (JOB_CONTROL) && defined (PROCESS_SUBSTITUTION)
-extern PROCESS *last_procsub_child;
-#endif
-
#if !defined (HAVE_WCSDUP) && defined (HANDLE_MULTIBYTE)
extern wchar_t *wcsdup (const wchar_t *);
#endif
size_t slen;
char *t, *result;
int pass_character, nesting_level, in_comment;
- int len_closer, len_opener, len_alt_opener;
+ size_t len_closer, len_opener, len_alt_opener;
DECLARE_MBSTATE;
slen = strlen (string + *sindex) + *sindex;
int
unclosed_pair (char *string, int eindex, char *openstr)
{
- int i, pass_next, openc, olen;
- size_t slen;
+ int i, pass_next, openc;
+ size_t olen, slen;
DECLARE_MBSTATE;
slen = strlen (string);
#if defined (HANDLE_MULTIBYTE)
-#define WFOLD(c) (match_ignore_case && iswupper (c) ? towlower (c) : (c))
+#define WFOLD(c) (match_ignore_case && iswupper (c) ? towlower (c) : (wint_t)(c))
/* Match WPAT anywhere in WSTRING and return the match boundaries.
This returns 1 in case of a successful match, 0 otherwise. Wide
WORD_DESC *w;
SHELL_VAR *v;
+ v = 0; /* silence a maybe-uninitialized warning */
+
/* See if it's a nameref first, behave in ksh93-compatible fashion.
There is at least one incompatibility: given ${!foo[0]} where foo=bar,
bash performs an indirect lookup on foo[0] and expands the result;
static WORD_LIST *
expand_word_list_internal (WORD_LIST *list, int eflags)
{
- WORD_LIST *new_list, *temp_list;
+ WORD_LIST *new_list;
tempenv_assign_error = 0;
if (list == 0)
/* And remove such quoted special characters. */
extern char *remove_quoted_escapes (char *);
+/* Quote escape characters on the rhs of a word expansion. */
+extern char *quote_rhs (const char *);
+
/* Remove CTLNUL characters from STRING unless they are quoted with CTLESC. */
extern char *remove_quoted_nulls (char *);
static void
unwind_protect_mem_internal (char *var, char *psize)
{
- int size, allocated;
+ int size;
+ size_t allocated;
UNWIND_ELT *elt;
size = *(int *) psize;
extern void clear_unwind_protect_list (int);
extern int have_unwind_protects (void);
extern int unwind_protect_tag_on_stack (const char *);
-extern void uwp_init (void);
/* Define for people who like their code to look a certain way. */
#define end_unwind_frame()
{
/* Fast path for common case. */
char *cdir;
- int len;
+ size_t len;
cdir = get_string_value ("PWD");
if (cdir)
nameref_transform_name (const char *name, int flags)
{
SHELL_VAR *v;
- char *newname;
v = 0;
if (flags & ASS_MKLOCAL)
{
char *retval, *oval;
intmax_t lval, rval;
- int expok, olen, op;
+ int expok, op;
+ size_t olen;
/* If this variable has had its type set to integer (via `declare -i'),
then do expression evaluation on it and store the result. The
{
SHELL_VAR **varlist;
char **rlist;
- int rind, plen;
- size_t vind;
+ int rind;
+ size_t plen, vind;
plen = STRLEN (prefix);
varlist = all_visible_variables ();
push_posix_temp_var (PTR_T data)
{
SHELL_VAR *var, *v;
+#if 0
HASH_TABLE *binding_table;
+#endif
var = (SHELL_VAR *)data;
/* XXX - do we need to worry about array variables here? */
+#if 0
/* If this modifies an existing local variable, v->context will be non-zero.
If it comes back with v->context == 0, we bound at the global context.
Set binding_table appropriately. It doesn't matter whether it's correct
if the variable is local, only that it's not global_variables->table */
binding_table = v->context ? shell_variables->table : global_variables->table;
+#endif
/* global variables are no longer temporary and don't need propagating. */
if (v->context == 0)
};
static struct saved_dollar_vars *dollar_arg_stack = (struct saved_dollar_vars *)NULL;
-static int dollar_arg_stack_slots;
+static size_t dollar_arg_stack_slots;
static int dollar_arg_stack_index;
/* Functions to manipulate dollar_vars array. Need to keep these in sync with