From b2613ad1c010401b4a2bcf5a16457bec5879be41 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Tue, 3 Jan 2023 11:59:43 -0500 Subject: [PATCH] third set of ANSI C changes: const function parameters --- CWRU/CWRU.chlog | 11 +++ arrayfunc.c | 36 ++++---- arrayfunc.h | 22 ++--- assoc.c | 6 +- assoc.h | 6 +- bashhist.c | 4 +- bashhist.h | 4 +- bashline.c | 30 +++---- bashline.h | 4 +- builtins/common.c | 34 +++---- builtins/common.h | 32 +++---- expr.c | 22 ++--- externs.h | 52 +++++------ findcmd.c | 4 +- findcmd.h | 4 +- general.h | 6 +- lib/sh/getcwd.c | 2 +- lib/sh/inet_aton.c | 4 +- lib/sh/netopen.c | 20 ++--- lib/sh/spell.c | 4 +- lib/sh/stringlist.c | 6 +- lib/sh/stringvec.c | 8 +- lib/sh/strnlen.c | 2 +- lib/sh/strtrans.c | 10 +-- lib/sh/tmpfile.c | 17 ++-- lib/sh/uconvert.c | 6 +- lib/sh/zcatfd.c | 2 +- locale.c | 14 +-- mailcheck.c | 10 +-- parse.y | 2 +- pathexp.c | 4 +- pathexp.h | 4 +- pcomplete.c | 10 +-- pcomplete.h | 2 +- redir.c | 8 +- stringlib.c | 17 ++-- subst.c | 211 +++++++++++++++++++++++--------------------- subst.h | 40 ++++----- test.c | 8 +- trap.c | 28 +++--- trap.h | 24 ++--- variables.c | 104 +++++++++++----------- variables.h | 78 ++++++++-------- 43 files changed, 477 insertions(+), 445 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 16a32084..92084e09 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -4891,3 +4891,14 @@ builtins/{umask.def,wait.def} - C89-style function declarations - add `const' and `inline' where it makes sense + 1/2/2023 + -------- +lib/sh/{stringvec.c,inet_aton.c,strnlen.c,spell.c,netopen.c,stringlist.c} +lib/sh/{strtrans.c,tmpfile.c,uconvert.c,zcatfd.c} +builtins/{common.c,common.h} +mailcheck.c,bashline.c,pathexp.c,stringlib.c,locale.c,pcomplete.c,redir.c +test.c,trap.c,variables.c,bashhist.c,expr.c,arrayfunc.c,assoc.c,variables.c +subst.c,findcmd.c +arrayfunc.h,variables.h,findcmd.h,bashline.h,trap.h,pathexp.h,externs.h, +pcomplete.h,bashhist.h,assoc.h,general.h,subst.h + - more `const' changes, remove `register' diff --git a/arrayfunc.c b/arrayfunc.c index 17be8ccf..b1e68b74 100644 --- a/arrayfunc.c +++ b/arrayfunc.c @@ -1,6 +1,6 @@ /* arrayfunc.c -- High-level array functions used by other parts of the shell. */ -/* Copyright (C) 2001-2022 Free Software Foundation, Inc. +/* Copyright (C) 2001-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -52,8 +52,8 @@ int assoc_expand_once = 0; /* Ditto for indexed array subscripts -- currently unused */ int array_expand_once = 0; -static SHELL_VAR *bind_array_var_internal (SHELL_VAR *, arrayind_t, char *, char *, int); -static SHELL_VAR *assign_array_element_internal (SHELL_VAR *, char *, char *, char *, int, char *, int, array_eltstate_t *); +static SHELL_VAR *bind_array_var_internal (SHELL_VAR *, arrayind_t, char *, const char *, int); +static SHELL_VAR *assign_array_element_internal (SHELL_VAR *, const char *, char *, char *, int, const char *, int, array_eltstate_t *); static void assign_assoc_from_kvlist (SHELL_VAR *, WORD_LIST *, HASH_TABLE *, int); @@ -146,7 +146,7 @@ convert_var_to_assoc (SHELL_VAR *var) } char * -make_array_variable_value (SHELL_VAR *entry, arrayind_t ind, char *key, char *value, int flags) +make_array_variable_value (SHELL_VAR *entry, arrayind_t ind, const char *key, const char *value, int flags) { SHELL_VAR *dentry; char *newval; @@ -188,7 +188,7 @@ make_array_variable_value (SHELL_VAR *entry, arrayind_t ind, char *key, char *va XXX - make sure that any dynamic associative array variables recreate the hash table on each assignment. BASH_CMDS and BASH_ALIASES already do this */ static SHELL_VAR * -bind_assoc_var_internal (SHELL_VAR *entry, HASH_TABLE *hash, char *key, char *value, int flags) +bind_assoc_var_internal (SHELL_VAR *entry, HASH_TABLE *hash, char *key, const char *value, int flags) { char *newval; @@ -211,7 +211,7 @@ bind_assoc_var_internal (SHELL_VAR *entry, HASH_TABLE *hash, char *key, char *va /* Perform ENTRY[IND]=VALUE or ENTRY[KEY]=VALUE. This is not called for every assignment to an associative array; see assign_compound_array_list below. */ static SHELL_VAR * -bind_array_var_internal (SHELL_VAR *entry, arrayind_t ind, char *key, char *value, int flags) +bind_array_var_internal (SHELL_VAR *entry, arrayind_t ind, char *key, const char *value, int flags) { char *newval; @@ -239,7 +239,7 @@ bind_array_var_internal (SHELL_VAR *entry, arrayind_t ind, char *key, char *valu If NAME does not exist, just create an array variable, no matter what IND's value may be. */ SHELL_VAR * -bind_array_variable (char *name, arrayind_t ind, char *value, int flags) +bind_array_variable (const char *name, arrayind_t ind, const char *value, int flags) { SHELL_VAR *entry; @@ -276,7 +276,7 @@ bind_array_element (SHELL_VAR *entry, arrayind_t ind, char *value, int flags) } SHELL_VAR * -bind_assoc_variable (SHELL_VAR *entry, char *name, char *key, char *value, int flags) +bind_assoc_variable (SHELL_VAR *entry, const char *name, char *key, const char *value, int flags) { if ((readonly_p (entry) && (flags&ASS_FORCE) == 0) || noassign_p (entry)) { @@ -311,7 +311,7 @@ flush_eltstate (array_eltstate_t *estatep) assign VALUE to that array element by calling bind_array_variable(). Flags are ASS_ assignment flags */ SHELL_VAR * -assign_array_element (char *name, char *value, int flags, array_eltstate_t *estatep) +assign_array_element (const char *name, const char *value, int flags, array_eltstate_t *estatep) { char *sub, *vname; int sublen, isassoc, avflags; @@ -359,8 +359,8 @@ assign_array_element (char *name, char *value, int flags, array_eltstate_t *esta } static SHELL_VAR * -assign_array_element_internal (SHELL_VAR *entry, char *name, char *vname, - char *sub, int sublen, char *value, +assign_array_element_internal (SHELL_VAR *entry, const char *name, char *vname, + char *sub, int sublen, const char *value, int flags, array_eltstate_t *estatep) { char *akey, *nkey; @@ -423,7 +423,7 @@ assign_array_element_internal (SHELL_VAR *entry, char *name, char *vname, for assignment (e.g., by the `read' builtin). If FLAGS&2 is non-zero, we create an associative array. */ SHELL_VAR * -find_or_make_array_variable (char *name, int flags) +find_or_make_array_variable (const char *name, int flags) { SHELL_VAR *var; @@ -474,7 +474,7 @@ find_or_make_array_variable (char *name, int flags) /* Perform a compound assignment statement for array NAME, where VALUE is the text between the parens: NAME=( VALUE ) */ SHELL_VAR * -assign_array_from_string (char *name, char *value, int flags) +assign_array_from_string (const char *name, char *value, int flags) { SHELL_VAR *var; int vflags; @@ -618,7 +618,7 @@ kvpair_assignment_p (WORD_LIST *l) } char * -expand_and_quote_kvpair_word (char *w) +expand_and_quote_kvpair_word (const char *w) { char *r, *s, *t; @@ -1186,7 +1186,7 @@ print_assoc_assignment (SHELL_VAR *var, int quoted) not be modified. */ /* We need to reserve 1 for FLAGS, which we pass to skipsubscript. */ int -tokenize_array_reference (char *name, int flags, char **subp) +tokenize_array_reference (const char *name, int flags, char **subp) { char *t; int r, len, isassoc, ssflags; @@ -1248,12 +1248,12 @@ tokenize_array_reference (char *name, int flags, char **subp) int valid_array_reference (const char *name, int flags) { - return tokenize_array_reference ((char *)name, flags, (char **)NULL); + return tokenize_array_reference (name, flags, (char **)NULL); } /* Expand the array index beginning at S and extending LEN characters. */ arrayind_t -array_expand_index (SHELL_VAR *var, char *s, int len, int flags) +array_expand_index (SHELL_VAR *var, const char *s, int len, int flags) { char *exp, *t, *savecmd; int expok, eflag; @@ -1560,7 +1560,7 @@ get_array_value (const char *s, int flags, array_eltstate_t *estatep) } char * -array_keys (char *s, int quoted, int pflags) +array_keys (const char *s, int quoted, int pflags) { int len; char *retval, *t, *temp; diff --git a/arrayfunc.h b/arrayfunc.h index 9d9052ff..8fcec160 100644 --- a/arrayfunc.h +++ b/arrayfunc.h @@ -1,6 +1,6 @@ /* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */ -/* Copyright (C) 2001-2022 Free Software Foundation, Inc. +/* Copyright (C) 2001-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -76,17 +76,17 @@ extern int array_expand_once; extern SHELL_VAR *convert_var_to_array (SHELL_VAR *); extern SHELL_VAR *convert_var_to_assoc (SHELL_VAR *); -extern char *make_array_variable_value (SHELL_VAR *, arrayind_t, char *, char *, int); +extern char *make_array_variable_value (SHELL_VAR *, arrayind_t, const char *, const char *, int); -extern SHELL_VAR *bind_array_variable (char *, arrayind_t, char *, int); +extern SHELL_VAR *bind_array_variable (const char *, arrayind_t, const char *, int); extern SHELL_VAR *bind_array_element (SHELL_VAR *, arrayind_t, char *, int); -extern SHELL_VAR *assign_array_element (char *, char *, int, array_eltstate_t *); +extern SHELL_VAR *assign_array_element (const char *, const char *, int, array_eltstate_t *); -extern SHELL_VAR *bind_assoc_variable (SHELL_VAR *, char *, char *, char *, int); +extern SHELL_VAR *bind_assoc_variable (SHELL_VAR *, const char *, char *, const char *, int); -extern SHELL_VAR *find_or_make_array_variable (char *, int); +extern SHELL_VAR *find_or_make_array_variable (const char *, int); -extern SHELL_VAR *assign_array_from_string (char *, char *, int); +extern SHELL_VAR *assign_array_from_string (const char *, char *, int); extern SHELL_VAR *assign_array_var_from_word_list (SHELL_VAR *, WORD_LIST *, int); extern WORD_LIST *expand_compound_array_assignment (SHELL_VAR *, char *, int); @@ -97,7 +97,7 @@ extern char *expand_and_quote_assoc_word (char *, int); extern void quote_compound_array_list (WORD_LIST *, int); extern int kvpair_assignment_p (WORD_LIST *); -extern char *expand_and_quote_kvpair_word (char *); +extern char *expand_and_quote_kvpair_word (const char *); extern int unbind_array_element (SHELL_VAR *, char *, int); extern int skipsubscript (const char *, int, int); @@ -105,14 +105,14 @@ extern int skipsubscript (const char *, int, int); extern void print_array_assignment (SHELL_VAR *, int); extern void print_assoc_assignment (SHELL_VAR *, int); -extern arrayind_t array_expand_index (SHELL_VAR *, char *, int, int); +extern arrayind_t array_expand_index (SHELL_VAR *, const char *, int, int); extern int valid_array_reference (const char *, int); -extern int tokenize_array_reference (char *, int, char **); +extern int tokenize_array_reference (const char *, int, char **); extern char *array_value (const char *, int, int, array_eltstate_t *); extern char *get_array_value (const char *, int, array_eltstate_t *); -extern char *array_keys (char *, int, int); +extern char *array_keys (const char *, int, int); extern char *array_variable_name (const char *, int, char **, int *); extern SHELL_VAR *array_variable_part (const char *, int, char **, int *); diff --git a/assoc.c b/assoc.c index d61545d0..5a8e8180 100644 --- a/assoc.c +++ b/assoc.c @@ -7,7 +7,7 @@ * chet@ins.cwru.edu */ -/* Copyright (C) 2008,2009,2011-2022 Free Software Foundation, Inc. +/* Copyright (C) 2008,2009,2011-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -103,7 +103,7 @@ assoc_replace (HASH_TABLE *hash, char *key, char *value) } void -assoc_remove (HASH_TABLE *hash, char *string) +assoc_remove (HASH_TABLE *hash, const char *string) { BUCKET_CONTENTS *b; @@ -117,7 +117,7 @@ assoc_remove (HASH_TABLE *hash, char *string) } char * -assoc_reference (HASH_TABLE *hash, char *string) +assoc_reference (HASH_TABLE *hash, const char *string) { BUCKET_CONTENTS *b; diff --git a/assoc.h b/assoc.h index 403e68df..46dc0aef 100644 --- a/assoc.h +++ b/assoc.h @@ -1,7 +1,7 @@ /* assoc.h -- definitions for the interface exported by assoc.c that allows the rest of the shell to manipulate associative array variables. */ -/* Copyright (C) 2008,2009-2021 Free Software Foundation, Inc. +/* Copyright (C) 2008,2009-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -41,9 +41,9 @@ extern void assoc_flush (HASH_TABLE *); extern int assoc_insert (HASH_TABLE *, char *, char *); extern PTR_T assoc_replace (HASH_TABLE *, char *, char *); -extern void assoc_remove (HASH_TABLE *, char *); +extern void assoc_remove (HASH_TABLE *, const char *); -extern char *assoc_reference (HASH_TABLE *, char *); +extern char *assoc_reference (HASH_TABLE *, const char *); extern char *assoc_subrange (HASH_TABLE *, arrayind_t, arrayind_t, int, int, int); extern char *assoc_patsub (HASH_TABLE *, char *, char *, int); diff --git a/bashhist.c b/bashhist.c index 8295188e..c05e3c39 100644 --- a/bashhist.c +++ b/bashhist.c @@ -1,6 +1,6 @@ /* bashhist.c -- bash interface to the GNU history library. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -979,7 +979,7 @@ histignore_item_func (struct ign *ign) } void -setup_history_ignore (char *varname) +setup_history_ignore (const char *varname) { setup_ignore_patterns (&histignore); } diff --git a/bashhist.h b/bashhist.h index 4ce049cf..453bff7e 100644 --- a/bashhist.h +++ b/bashhist.h @@ -1,6 +1,6 @@ /* bashhist.h -- interface to the bash history functions in bashhist.c. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -82,7 +82,7 @@ extern void bash_add_history (char *); extern int check_add_history (char *, int); extern int history_number (void); -extern void setup_history_ignore (char *); +extern void setup_history_ignore (const char *); extern char *last_history_line (void); diff --git a/bashline.c b/bashline.c index ab761ee0..cdff17c1 100644 --- a/bashline.c +++ b/bashline.c @@ -1,6 +1,6 @@ /* bashline.c -- Bash's interface to the readline library. */ -/* 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. @@ -145,7 +145,7 @@ static int bash_transpose_shellwords (int, int); static int bash_spell_correct_shellword (int, int); /* Helper functions for Readline. */ -static char *restore_tilde (char *, char *); +static char *restore_tilde (const char *, char *); static char *maybe_restore_tilde (char *, char *); static char *bash_filename_rewrite_hook (char *, int); @@ -166,7 +166,7 @@ static void restore_directory_hook (rl_icppfunc_t); static int directory_exists (const char *, int); static void cleanup_expansion_error (void); -static void maybe_make_readline_line (char *); +static void maybe_make_readline_line (const char *); static void set_up_new_line (char *); static int check_redir (int); @@ -181,9 +181,9 @@ static int dynamic_complete_history (int, int); static int bash_dabbrev_expand (int, int); static void initialize_hostname_list (void); -static void add_host_name (char *); -static void snarf_hosts_from_file (char *); -static char **hostnames_matching (char *); +static void add_host_name (const char *); +static void snarf_hosts_from_file (const char *); +static char **hostnames_matching (const char *); static void _ignore_completion_names (char **, sh_ignore_func_t *); static int name_is_acceptable (const char *); @@ -268,7 +268,7 @@ static int bash_glob_list_expansions (int, int); #endif /* SPECIFIC_COMPLETION_FUNCTIONS */ -static int edit_and_execute_command (int, int, int, char *); +static int edit_and_execute_command (int, int, int, const char *); #if defined (VI_MODE) static int vi_edit_and_execute_command (int, int); static int bash_vi_complete (int, int); @@ -715,7 +715,7 @@ bash_push_line (void) /* Call this to set the initial text for the next line to read from readline. */ int -bash_re_edit (char *line) +bash_re_edit (const char *line) { FREE (push_to_readline); @@ -781,7 +781,7 @@ initialize_hostname_list (void) /* Add NAME to the list of hosts. */ static void -add_host_name (char *name) +add_host_name (const char *name) { if (hostname_list_length + 2 > hostname_list_size) { @@ -796,7 +796,7 @@ add_host_name (char *name) #define cr_whitespace(c) ((c) == '\r' || (c) == '\n' || whitespace(c)) static void -snarf_hosts_from_file (char *filename) +snarf_hosts_from_file (const char *filename) { FILE *file; char *temp, buffer[256], name[256]; @@ -885,7 +885,7 @@ clear_hostname_list (void) Initialize the hostname list the first time if necessary. The array is malloc ()'ed, but not the individual strings. */ static char ** -hostnames_matching (char *text) +hostnames_matching (const char *text) { register int i, len, nmatch, rsize; char **result; @@ -938,7 +938,7 @@ hostnames_matching (char *text) #define POSIX_VI_EDIT_COMMAND "fc -e vi" static int -edit_and_execute_command (int count, int c, int editing_mode, char *edit_command) +edit_and_execute_command (int count, int c, int editing_mode, const char *edit_command) { char *command, *metaval; int r, rrs, metaflag; @@ -2692,7 +2692,7 @@ cleanup_expansion_error (void) undo record to get from the readline line buffer contents to the new line and make NEW_LINE the current readline line. */ static void -maybe_make_readline_line (char *new_line) +maybe_make_readline_line (const char *new_line) { if (new_line && strcmp (new_line, rl_line_buffer) != 0) { @@ -3042,7 +3042,7 @@ name_is_acceptable (const char *name) #if 0 static int -ignore_dot_names (char *name) +ignore_dot_names (const char *name) { return (name[0] != '.'); } @@ -3126,7 +3126,7 @@ bash_ignore_everything (char **names) is an expanded filename. DIRECTORY_PART is the tilde-prefix portion of the un-tilde-expanded version of VAL (what the user typed). */ static char * -restore_tilde (char *val, char *directory_part) +restore_tilde (const char *val, char *directory_part) { int l, vl, dl2, xl; char *dh2, *expdir, *ret, *v; diff --git a/bashline.h b/bashline.h index b728233e..d9fb7379 100644 --- a/bashline.h +++ b/bashline.h @@ -1,6 +1,6 @@ /* bashline.h -- interface to the bash readline functions in bashline.c. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -41,7 +41,7 @@ extern int enable_hostname_completion (int); extern void initialize_readline (void); extern void bashline_reset (void); extern void bashline_reinitialize (void); -extern int bash_re_edit (char *); +extern int bash_re_edit (const char *); extern void bashline_set_event_hook (void); extern void bashline_reset_event_hook (void); diff --git a/builtins/common.c b/builtins/common.c index 92ddfd40..da8b5fae 100644 --- a/builtins/common.c +++ b/builtins/common.c @@ -185,19 +185,19 @@ no_options (WORD_LIST *list) } void -sh_needarg (char *s) +sh_needarg (const char *s) { builtin_error (_("%s: option requires an argument"), s); } void -sh_neednumarg (char *s) +sh_neednumarg (const char *s) { builtin_error (_("%s: numeric argument required"), s); } void -sh_notfound (char *s) +sh_notfound (const char *s) { builtin_error (_("%s: not found"), s); } @@ -205,25 +205,25 @@ sh_notfound (char *s) /* Function called when one of the builtin commands detects an invalid option. */ void -sh_invalidopt (char *s) +sh_invalidopt (const char *s) { builtin_error (_("%s: invalid option"), s); } void -sh_invalidoptname (char *s) +sh_invalidoptname (const char *s) { builtin_error (_("%s: invalid option name"), s); } void -sh_invalidid (char *s) +sh_invalidid (const char *s) { builtin_error (_("`%s': not a valid identifier"), s); } void -sh_invalidnum (char *s) +sh_invalidnum (const char *s) { char *msg; @@ -237,13 +237,13 @@ sh_invalidnum (char *s) } void -sh_invalidsig (char *s) +sh_invalidsig (const char *s) { builtin_error (_("%s: invalid signal specification"), s); } void -sh_badpid (char *s) +sh_badpid (const char *s) { builtin_error (_("`%s': not a pid or valid job spec"), s); } @@ -261,7 +261,7 @@ sh_noassign (const char *s) } void -sh_erange (char *s, char *desc) +sh_erange (const char *s, const char *desc) { if (s) builtin_error (_("%s: %s out of range"), s, desc ? desc : _("argument")); @@ -271,13 +271,13 @@ sh_erange (char *s, char *desc) #if defined (JOB_CONTROL) void -sh_badjob (char *s) +sh_badjob (const char *s) { builtin_error (_("%s: no such job"), s); } void -sh_nojobs (char *s) +sh_nojobs (const char *s) { if (s) builtin_error (_("%s: no job control"), s); @@ -288,7 +288,7 @@ sh_nojobs (char *s) #if defined (RESTRICTED_SHELL) void -sh_restricted (char *s) +sh_restricted (const char *s) { if (s) builtin_error (_("%s: restricted"), s); @@ -298,7 +298,7 @@ sh_restricted (char *s) #endif void -sh_notbuiltin (char *s) +sh_notbuiltin (const char *s) { builtin_error (_("%s: not a shell builtin"), s); } @@ -594,7 +594,7 @@ read_octal (char *string) char *the_current_working_directory = (char *)NULL; char * -get_working_directory (char *for_whom) +get_working_directory (const char *for_whom) { if (no_symbolic_links) { @@ -623,7 +623,7 @@ get_working_directory (char *for_whom) /* Make NAME our internal idea of the current working directory. */ void -set_working_directory (char *name) +set_working_directory (const char *name) { FREE (the_current_working_directory); the_current_working_directory = savestring (name); @@ -905,7 +905,7 @@ find_special_builtin (const char *name) } static int -shell_builtin_compare (struct builtin *sbp1, struct builtin *sbp2) +shell_builtin_compare (const struct builtin *sbp1, const struct builtin *sbp2) { int result; diff --git a/builtins/common.h b/builtins/common.h index 72586d8e..630ebd44 100644 --- a/builtins/common.h +++ b/builtins/common.h @@ -88,22 +88,22 @@ extern void no_args (WORD_LIST *); extern int no_options (WORD_LIST *); /* common error message functions */ -extern void sh_needarg (char *); -extern void sh_neednumarg (char *); -extern void sh_notfound (char *); -extern void sh_invalidopt (char *); -extern void sh_invalidoptname (char *); -extern void sh_invalidid (char *); -extern void sh_invalidnum (char *); -extern void sh_invalidsig (char *); +extern void sh_needarg (const char *); +extern void sh_neednumarg (const char *); +extern void sh_notfound (const char *); +extern void sh_invalidopt (const char *); +extern void sh_invalidoptname (const char *); +extern void sh_invalidid (const char *); +extern void sh_invalidnum (const char *); +extern void sh_invalidsig (const char *); extern void sh_readonly (const char *); extern void sh_noassign (const char *); -extern void sh_erange (char *, char *); -extern void sh_badpid (char *); -extern void sh_badjob (char *); -extern void sh_nojobs (char *); -extern void sh_restricted (char *); -extern void sh_notbuiltin (char *); +extern void sh_erange (const char *, const char *); +extern void sh_badpid (const char *); +extern void sh_badjob (const char *); +extern void sh_nojobs (const char *); +extern void sh_restricted (const char *); +extern void sh_notbuiltin (const char *); extern void sh_wrerror (void); extern void sh_ttyerror (int); extern int sh_chkwrite (int); @@ -123,8 +123,8 @@ extern int read_octal (char *); /* Keeps track of the current working directory. */ extern char *the_current_working_directory; -extern char *get_working_directory (char *); -extern void set_working_directory (char *); +extern char *get_working_directory (const char *); +extern void set_working_directory (const char *); #if defined (JOB_CONTROL) extern int get_job_by_name (const char *, int); diff --git a/expr.c b/expr.c index 2fbf64f5..3ff34fb1 100644 --- a/expr.c +++ b/expr.c @@ -1,6 +1,6 @@ /* expr.c -- arithmetic expression evaluation. */ -/* Copyright (C) 1990-2022 Free Software Foundation, Inc. +/* Copyright (C) 1990-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -196,12 +196,12 @@ static void evalerror (const char *); static void pushexp (void); static void popexp (void); static void expr_unwind (void); -static void expr_bind_variable (char *, char *); +static void expr_bind_variable (const char *, const char *); #if defined (ARRAY_VARS) -static void expr_bind_array_element (char *, arrayind_t, char *); +static void expr_bind_array_element (const char *, arrayind_t, const char *); #endif -static intmax_t subexpr (char *); +static intmax_t subexpr (const char *); static intmax_t expcomma (void); static intmax_t expassign (void); @@ -320,7 +320,7 @@ expr_unwind (void) } static void -expr_bind_variable (char *lhs, char *rhs) +expr_bind_variable (const char *lhs, const char *rhs) { SHELL_VAR *v; int aflags; @@ -364,7 +364,7 @@ expr_skipsubscript (char *vp, char *cp) /* Rewrite tok, which is of the form vname[expression], to vname[ind], where IND is the already-calculated value of expression. */ static void -expr_bind_array_element (char *tok, arrayind_t ind, char *rhs) +expr_bind_array_element (const char *tok, arrayind_t ind, const char *rhs) { char *lhs, *vname; size_t llen; @@ -399,7 +399,7 @@ expr_bind_array_element (char *tok, arrayind_t ind, char *rhs) safe to let the loop terminate when expr_depth == 0, without freeing up any of the expr_depth[0] stuff. */ intmax_t -evalexp (char *expr, int flags, int *validp) +evalexp (const char *expr, int flags, int *validp) { intmax_t val; int c; @@ -441,12 +441,12 @@ evalexp (char *expr, int flags, int *validp) } static intmax_t -subexpr (char *expr) +subexpr (const char *expr) { intmax_t val; char *p; - for (p = expr; p && *p && cr_whitespace (*p); p++) + for (p = (char *)expr; p && *p && cr_whitespace (*p); p++) ; if (p == NULL || *p == '\0') @@ -1232,7 +1232,7 @@ expr_streval (char *tok, int e, struct lvalue *lvalue) return (tval); } -static int +static inline int _is_multiop (int c) { switch (c) @@ -1258,7 +1258,7 @@ _is_multiop (int c) } } -static int +static inline int _is_arithop (int c) { switch (c) diff --git a/externs.h b/externs.h index a75fedb3..eded48bb 100644 --- a/externs.h +++ b/externs.h @@ -1,7 +1,7 @@ /* externs.h -- extern function declarations which do not appear in their own header file. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -29,7 +29,7 @@ /* Functions from expr.c. */ #define EXP_EXPANDED 0x01 -extern intmax_t evalexp (char *, int, int *); +extern intmax_t evalexp (const char *, int, int *); /* Functions from print_cmd.c. */ #define FUNC_MULTILINE 0x01 @@ -109,7 +109,7 @@ extern char **brace_expand (char *); extern int yyparse (void); extern int return_EOF (void); extern void push_token (int); -extern char *xparse_dolparen (char *, char *, int *, int); +extern char *xparse_dolparen (const char *, char *, int *, int); extern COMMAND *parse_string_to_command (char *, int); extern void reset_parser (void); extern void reset_readahead_token (void); @@ -138,13 +138,13 @@ extern char *history_delimiting_chars (const char *); /* Declarations for functions defined in locale.c */ extern void set_default_locale (void); extern void set_default_locale_vars (void); -extern int set_locale_var (char *, char *); -extern int set_lang (char *, char *); +extern int set_locale_var (const char *, const char *); +extern int set_lang (const char *, const char *); extern void set_default_lang (void); -extern char *get_locale_var (char *); -extern char *localetrans (char *, int, int *); +extern char *get_locale_var (const char *); +extern char *localetrans (const char *, int, int *); extern char *mk_msgstr (char *, int *); -extern char *locale_expand (char *, int, int, int, int *); +extern char *locale_expand (const char *, int, int, int, int *); #ifndef locale_decpoint extern int locale_decpoint (void); #endif @@ -165,8 +165,8 @@ extern char *find_token_in_alist (int, STRING_INT_ALIST *, int); extern int find_index_in_alist (char *, STRING_INT_ALIST *, int); extern char *substring (const char *, int, int); -extern char *strsub (char *, char *, char *, int); -extern char *strcreplace (char *, int, const char *, int); +extern char *strsub (const char *, const char *, const char *, int); +extern char *strcreplace (const char *, int, const char *, int); extern void strip_leading (char *); extern void strip_trailing (char *, int, int); extern void xbcopy (char *, char *, size_t); @@ -397,12 +397,12 @@ extern STRINGLIST *strlist_create (int); extern STRINGLIST *strlist_resize (STRINGLIST *, int); extern void strlist_flush (STRINGLIST *); extern void strlist_dispose (STRINGLIST *); -extern int strlist_remove (STRINGLIST *, char *); +extern int strlist_remove (STRINGLIST *, const char *); extern STRINGLIST *strlist_copy (STRINGLIST *); extern STRINGLIST *strlist_merge (STRINGLIST *, STRINGLIST *); extern STRINGLIST *strlist_append (STRINGLIST *, STRINGLIST *); -extern STRINGLIST *strlist_prefix_suffix (STRINGLIST *, char *, char *); -extern void strlist_print (STRINGLIST *, char *); +extern STRINGLIST *strlist_prefix_suffix (STRINGLIST *, const char *, const char *); +extern void strlist_print (STRINGLIST *, const char *); extern void strlist_walk (STRINGLIST *, sh_strlist_map_func_t *); extern void strlist_sort (STRINGLIST *); @@ -414,10 +414,10 @@ extern char **strvec_mcreate (int); extern char **strvec_mresize (char **, int); extern void strvec_flush (char **); extern void strvec_dispose (char **); -extern int strvec_remove (char **, char *); -extern int strvec_len (char **); -extern int strvec_search (char **, char *); -extern char **strvec_copy (char **); +extern int strvec_remove (char **, const char *); +extern int strvec_len (char * const *); +extern int strvec_search (char **, const char *); +extern char **strvec_copy (char * const *); extern int strvec_posixcmp (char **, char **); extern int strvec_strcmp (char **, char **); extern void strvec_sort (char **, int); @@ -471,10 +471,10 @@ extern uintmax_t strtoumax (const char *, char **, int); #endif /* declarations for functions defined in lib/sh/strtrans.c */ -extern char *ansicstr (char *, int, int, int *, int *); -extern char *ansic_quote (char *, int, int *); +extern char *ansicstr (const char *, int, int, int *, int *); +extern char *ansic_quote (const char *, int, int *); extern int ansic_shouldquote (const char *); -extern char *ansiexpand (char *, int, int, int *); +extern char *ansiexpand (const char *, int, int, int *); /* declarations for functions defined in lib/sh/strvis.c */ extern int sh_charvis (const char *, size_t *, size_t, char *, size_t *); @@ -492,13 +492,13 @@ extern void print_timeval (); #define MT_USERANDOM 0x0004 #define MT_TEMPLATE 0x0008 -extern char *sh_mktmpname (char *, int); -extern int sh_mktmpfd (char *, int, char **); -/* extern FILE *sh_mktmpfp (char *, int, char **); */ -extern char *sh_mktmpdir (char *, int); +extern char *sh_mktmpname (const char *, int); +extern int sh_mktmpfd (const char *, int, char **); +/* extern FILE *sh_mktmpfp (const char *, int, char **); */ +extern char *sh_mktmpdir (const char *, int); /* declarations for functions defined in lib/sh/uconvert.c */ -extern int uconvert (char *, long *, long *, char **); +extern int uconvert (const char *, long *, long *, char **); /* declarations for functions defined in lib/sh/ufuncs.c */ extern unsigned int falarm (unsigned int, unsigned int); @@ -525,7 +525,7 @@ extern int wcsnwidth (const wchar_t *, size_t, int); extern void get_new_window_size (int, int *, int *); /* declarations for functions defined in lib/sh/zcatfd.c */ -extern int zcatfd (int, int, char *); +extern int zcatfd (int, int, const char *); /* declarations for functions defined in lib/sh/zgetline.c */ extern ssize_t zgetline (int, char **, size_t *, int, int); diff --git a/findcmd.c b/findcmd.c index 468cbd8b..9b211047 100644 --- a/findcmd.c +++ b/findcmd.c @@ -1,6 +1,6 @@ /* findcmd.c -- Functions to search for commands by name. */ -/* Copyright (C) 1997-2022 Free Software Foundation, Inc. +/* Copyright (C) 1997-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -89,7 +89,7 @@ static struct ignorevar execignore = }; void -setup_exec_ignore (char *varname) +setup_exec_ignore (const char *varname) { setup_ignore_patterns (&execignore); } diff --git a/findcmd.h b/findcmd.h index cc4070b4..b0d80d11 100644 --- a/findcmd.h +++ b/findcmd.h @@ -1,6 +1,6 @@ /* findcmd.h - functions from findcmd.c. */ -/* Copyright (C) 1997-2015,2020-2022 Free Software Foundation, Inc. +/* Copyright (C) 1997-2015,2020-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -37,7 +37,7 @@ extern char *find_in_path (const char *, char *, int); extern char *find_path_file (const char *); extern char *search_for_command (const char *, int); extern char *user_command_matches (const char *, int, int); -extern void setup_exec_ignore (char *); +extern void setup_exec_ignore (const char *); extern int dot_found_in_search; diff --git a/general.h b/general.h index c6d000af..42563e56 100644 --- a/general.h +++ b/general.h @@ -1,6 +1,6 @@ /* general.h -- defines that everybody likes to use. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -226,14 +226,14 @@ typedef void sh_vmsg_func_t (const char *, ...); /* printf(3)-like */ /* Specific function pointer typedefs. Most of these could be done with #defines. */ -typedef void sh_sv_func_t (char *); /* sh_vcpfunc_t */ +typedef void sh_sv_func_t (const char *); typedef void sh_free_func_t (PTR_T); /* sh_vptrfunc_t */ typedef void sh_resetsig_func_t (int); /* sh_vintfunc_t */ typedef int sh_ignore_func_t (const char *); /* sh_icpfunc_t */ typedef int sh_assign_func_t (const char *); -typedef int sh_wassign_func_t (WORD_DESC *, int); +typedef int sh_wassign_func_t (const WORD_DESC *, int); typedef int sh_load_func_t (char *); typedef void sh_unload_func_t (char *); diff --git a/lib/sh/getcwd.c b/lib/sh/getcwd.c index e45ccb00..1a39b9f6 100644 --- a/lib/sh/getcwd.c +++ b/lib/sh/getcwd.c @@ -73,7 +73,7 @@ extern int errno; the inode corresponding to PATH/DIR is identical to THISINO. */ #if !defined (D_FILENO_AVAILABLE) static int -_path_checkino (char *dotp, char *name, ino_t thisino) +_path_checkino (const char *dotp, const char *name, ino_t thisino) { char *fullpath; int r, e; diff --git a/lib/sh/inet_aton.c b/lib/sh/inet_aton.c index 4900a62d..3715850c 100644 --- a/lib/sh/inet_aton.c +++ b/lib/sh/inet_aton.c @@ -94,7 +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(register const char *cp) +inet_addr(const char *cp) { struct in_addr val; @@ -112,7 +112,7 @@ inet_addr(register const char *cp) * cannot distinguish between failure and a local broadcast address. */ int -inet_aton(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; diff --git a/lib/sh/netopen.c b/lib/sh/netopen.c index 23901b7f..aedac592 100644 --- a/lib/sh/netopen.c +++ b/lib/sh/netopen.c @@ -67,21 +67,21 @@ extern int inet_aton (const char *, struct in_addr *); #endif #ifndef HAVE_GETADDRINFO -static int _getaddr (char *, struct in_addr *); -static int _getserv (char *, int, unsigned short *); -static int _netopen4 (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 (char *, char *, int); +static int _netopen6 (const char *, const char *, int); #endif -static int _netopen (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 (char *host, struct in_addr *ap) +_getaddr (const char *host, struct in_addr *ap) { struct hostent *h; int r; @@ -112,7 +112,7 @@ _getaddr (char *host, struct in_addr *ap) /* Return 1 if SERV is a valid port number and stuff the converted value into PP in network byte order. */ static int -_getserv (char *serv, int proto, unsigned short *pp) +_getserv (const char *serv, int proto, unsigned short *pp) { intmax_t l; unsigned short s; @@ -149,7 +149,7 @@ _getserv (char *serv, int proto, unsigned short *pp) * traditional BSD mechanisms. Returns the connected socket or -1 on error. */ static int -_netopen4(char *host, char *serv, int typ) +_netopen4(const char *host, const char *serv, int typ) { struct in_addr ina; struct sockaddr_in sin; @@ -202,7 +202,7 @@ _netopen4(char *host, char *serv, int typ) * on error. */ static int -_netopen6 (char *host, char *serv, int typ) +_netopen6 (const char *host, const char *serv, int typ) { int s, e; struct addrinfo hints, *res, *res0; @@ -265,7 +265,7 @@ _netopen6 (char *host, char *serv, int typ) * Returns the connected socket or -1 on error. */ static int -_netopen(char *host, char *serv, int typ) +_netopen(const char *host, const char *serv, int typ) { #ifdef HAVE_GETADDRINFO return (_netopen6 (host, serv, typ)); diff --git a/lib/sh/spell.c b/lib/sh/spell.c index d25e4135..7e197bbb 100644 --- a/lib/sh/spell.c +++ b/lib/sh/spell.c @@ -40,7 +40,7 @@ #include #include -static int mindist (char *, char *, char *); +static int mindist (const char *, char *, char *); static int spdist (char *, char *); /* @@ -102,7 +102,7 @@ spname(char *oldname, char *newname) * Search directory for a guess */ static int -mindist(char *dir, char *guess, char *best) +mindist(const char *dir, char *guess, char *best) { DIR *fd; struct dirent *dp; diff --git a/lib/sh/stringlist.c b/lib/sh/stringlist.c index 8c1de7c7..da31ab89 100644 --- a/lib/sh/stringlist.c +++ b/lib/sh/stringlist.c @@ -97,7 +97,7 @@ strlist_dispose (STRINGLIST *sl) } int -strlist_remove (STRINGLIST *sl, char *s) +strlist_remove (STRINGLIST *sl, const char *s) { int r; @@ -179,7 +179,7 @@ strlist_append (STRINGLIST *m1, STRINGLIST *m2) } STRINGLIST * -strlist_prefix_suffix (STRINGLIST *sl, char *prefix, char *suffix) +strlist_prefix_suffix (STRINGLIST *sl, const char *prefix, const char *suffix) { int plen, slen, tlen, llen, i; char *t; @@ -211,7 +211,7 @@ strlist_prefix_suffix (STRINGLIST *sl, char *prefix, char *suffix) } void -strlist_print (STRINGLIST *sl, char *prefix) +strlist_print (STRINGLIST *sl, const char *prefix) { register int i; diff --git a/lib/sh/stringvec.c b/lib/sh/stringvec.c index fd3d3e47..c06690ca 100644 --- a/lib/sh/stringvec.c +++ b/lib/sh/stringvec.c @@ -60,7 +60,7 @@ strvec_mresize (char **array, int nsize) /* Return the length of ARRAY, a NULL terminated array of char *. */ int -strvec_len (char **array) +strvec_len (char * const *array) { register int i; @@ -92,7 +92,7 @@ strvec_dispose (char **array) } int -strvec_remove (char **array, char *name) +strvec_remove (char **array, const char *name) { register int i, j; char *x; @@ -115,7 +115,7 @@ strvec_remove (char **array, char *name) /* Find NAME in ARRAY. Return the index of NAME, or -1 if not present. ARRAY should be NULL terminated. */ int -strvec_search (char **array, char *name) +strvec_search (char **array, const char *name) { int i; @@ -128,7 +128,7 @@ strvec_search (char **array, char *name) /* Allocate and return a new copy of ARRAY and its contents. */ char ** -strvec_copy (char **array) +strvec_copy (char * const *array) { register int i; int len; diff --git a/lib/sh/strnlen.c b/lib/sh/strnlen.c index 06eaa0b9..e93904e0 100644 --- a/lib/sh/strnlen.c +++ b/lib/sh/strnlen.c @@ -35,7 +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 (register const char *s, size_t maxlen) +strnlen (const char *s, size_t maxlen) { register const char *e; size_t n; diff --git a/lib/sh/strtrans.c b/lib/sh/strtrans.c index 5d5f7599..29e30812 100644 --- a/lib/sh/strtrans.c +++ b/lib/sh/strtrans.c @@ -48,7 +48,7 @@ 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 (char *string, int len, int flags, int *sawc, int *rlen) +ansicstr (const char *string, int len, int flags, int *sawc, int *rlen) { int c, temp; char *ret, *r, *s; @@ -71,7 +71,7 @@ ansicstr (char *string, int len, int flags, int *sawc, int *rlen) #else ret = (char *)xmalloc (2*len + 1); /* 2*len for possible CTLESC */ #endif - for (r = ret, s = string; s && *s; ) + for (r = ret, s = (char *)string; s && *s; ) { c = *s++; if (c != '\\' || *s == '\0') @@ -225,7 +225,7 @@ ansicstr (char *string, int len, int flags, int *sawc, int *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 (char *str, int flags, int *rlen) +ansic_quote (const char *str, int flags, int *rlen) { char *r, *ret, *s; int l, rsize; @@ -246,7 +246,7 @@ ansic_quote (char *str, int flags, int *rlen) *r++ = '$'; *r++ = '\''; - for (s = str; c = *s; s++) + for (s = (char *)str; c = *s; s++) { b = l = 1; /* 1 == add backslash; 0 == no backslash */ clen = 1; @@ -367,7 +367,7 @@ ansic_shouldquote (const char *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 (char *string, int start, int end, int *lenp) +ansiexpand (const char *string, int start, int end, int *lenp) { char *temp, *t; int len, tlen; diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c index 098c111b..9736e06d 100644 --- a/lib/sh/tmpfile.c +++ b/lib/sh/tmpfile.c @@ -135,9 +135,10 @@ sh_seedrand (void) } char * -sh_mktmpname (char *nameroot, int flags) +sh_mktmpname (const char *nameroot, int flags) { - char *filename, *tdir, *lroot; + char *filename, *tdir; + const char *lroot; struct stat sb; int r, tdlen; static int seeded = 0; @@ -196,9 +197,10 @@ sh_mktmpname (char *nameroot, int flags) } int -sh_mktmpfd (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); @@ -259,7 +261,7 @@ sh_mktmpfd (char *nameroot, int flags, char **namep) } FILE * -sh_mktmpfp (char *nameroot, int flags, char **namep) +sh_mktmpfp (const char *nameroot, int flags, char **namep) { int fd; FILE *fp; @@ -274,9 +276,10 @@ sh_mktmpfp (char *nameroot, int flags, char **namep) } char * -sh_mktmpdir (char *nameroot, int flags) +sh_mktmpdir (const char *nameroot, int flags) { - char *filename, *tdir, *lroot, *dirname; + char *filename, *tdir, *dirname; + const char *lroot; int fd, tdlen; #ifdef USE_MKDTEMP diff --git a/lib/sh/uconvert.c b/lib/sh/uconvert.c index 909686cf..39790f6b 100644 --- a/lib/sh/uconvert.c +++ b/lib/sh/uconvert.c @@ -57,7 +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(char *s, long *ip, long *up, char **ep) +uconvert(const char *s, long *ip, long *up, char **ep) { int n, mult; long ipart, upart; @@ -69,10 +69,10 @@ uconvert(char *s, long *ip, long *up, char **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++) { diff --git a/lib/sh/zcatfd.c b/lib/sh/zcatfd.c index fe7b2a23..d365b193 100644 --- a/lib/sh/zcatfd.c +++ b/lib/sh/zcatfd.c @@ -44,7 +44,7 @@ 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 (int fd, int ofd, char *fn) +zcatfd (int fd, int ofd, const char *fn) { ssize_t nr; int rval; diff --git a/locale.c b/locale.c index bccbe6d9..60e08a69 100644 --- a/locale.c +++ b/locale.c @@ -1,6 +1,6 @@ /* locale.c - Miscellaneous internationalization functions. */ -/* Copyright (C) 1996-2009,2012,2016-2022 Free Software Foundation, Inc. +/* Copyright (C) 1996-2009,2012,2016-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -174,7 +174,7 @@ set_default_locale_vars (void) /* Set one of the locale categories (specified by VAR) to VALUE. Returns 1 if successful, 0 otherwise. */ int -set_locale_var (char *var, char *value) +set_locale_var (const char *var, const char *value) { int r; char *x; @@ -302,7 +302,7 @@ set_locale_var (char *var, char *value) reset_locale_vars() to reset any default values if LC_ALL is unset or null. */ int -set_lang (char *var, char *value) +set_lang (const char *var, const char *value) { FREE (lang); if (value) @@ -334,7 +334,7 @@ set_default_lang (void) The precedence is as POSIX.2 specifies: LC_ALL has precedence over the specific locale variables, and LANG, if set, is used as the default. */ char * -get_locale_var (char *var) +get_locale_var (const char *var) { char *locale; @@ -403,7 +403,7 @@ reset_locale_vars (void) is not available, the passed string is returned unchanged. The length of the translated string is returned in LENP, if non-null. */ char * -localetrans (char *string, int len, int *lenp) +localetrans (const char *string, int len, int *lenp) { char *locale, *t; char *translated; @@ -436,7 +436,7 @@ localetrans (char *string, int len, int *lenp) if (default_domain && *default_domain) translated = dgettext (default_domain, string); else - translated = string; + translated = (char *)string; if (translated == string) /* gettext returns its argument if untranslatable */ { @@ -508,7 +508,7 @@ mk_msgstr (char *string, int *foundnlp) by the caller. The length of the translated string is returned in LENP, if non-null. */ char * -locale_expand (char *string, int start, int end, int lineno, int *lenp) +locale_expand (const char *string, int start, int end, int lineno, int *lenp) { int len, tlen, foundnl; char *temp, *t, *t2; diff --git a/mailcheck.c b/mailcheck.c index a29f3e0d..118c1a5f 100644 --- a/mailcheck.c +++ b/mailcheck.c @@ -1,6 +1,6 @@ /* mailcheck.c -- The check is in the mail... */ -/* 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. @@ -72,9 +72,9 @@ int mail_warning; static int find_mail_file (const char *); static void init_mail_file (int); static void update_mail_file (int); -static int add_mail_file (char *, char *); +static int add_mail_file (char *, const char *); -static FILEINFO *alloc_mail_file (char *, char *); +static FILEINFO *alloc_mail_file (char *, const char *); static void dispose_mail_file (FILEINFO *); static int file_mod_date_changed (int); @@ -174,7 +174,7 @@ update_mail_file (int i) /* Add this file to the list of remembered files and return its index in the list of mail files. */ static int -add_mail_file (char *file, char *msg) +add_mail_file (char *file, const char *msg) { struct stat finfo; char *filename; @@ -212,7 +212,7 @@ reset_mail_files (void) } static FILEINFO * -alloc_mail_file (char *filename, char *msg) +alloc_mail_file (char *filename, const char *msg) { FILEINFO *mf; diff --git a/parse.y b/parse.y index ed39bf16..8f330897 100644 --- a/parse.y +++ b/parse.y @@ -4202,7 +4202,7 @@ INTERNAL_DEBUG(("current_token (%d) != shell_eof_token (%c)", current_token, she called by the word expansion code and so does not have to reset as much parser state before calling yyparse(). */ char * -xparse_dolparen (char *base, char *string, int *indp, int flags) +xparse_dolparen (const char *base, char *string, int *indp, int flags) { sh_parser_state_t ps; sh_input_line_state_t ls; diff --git a/pathexp.c b/pathexp.c index 0ae7862a..81cf543a 100644 --- a/pathexp.c +++ b/pathexp.c @@ -1,6 +1,6 @@ /* pathexp.c -- The shell interface to the globbing library. */ -/* Copyright (C) 1995-2022 Free Software Foundation, Inc. +/* Copyright (C) 1995-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -441,7 +441,7 @@ static struct ignorevar globignore = has changed. If GLOBIGNORE is being unset, we also need to disable the globbing of filenames beginning with a `.'. */ void -setup_glob_ignore (char *name) +setup_glob_ignore (const char *name) { char *v; diff --git a/pathexp.h b/pathexp.h index 7bd2665c..e78db524 100644 --- a/pathexp.h +++ b/pathexp.h @@ -1,6 +1,6 @@ /* pathexp.h -- The shell interface to the globbing library. */ -/* 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. @@ -97,7 +97,7 @@ struct ignorevar { extern void setup_ignore_patterns (struct ignorevar *); -extern void setup_glob_ignore (char *); +extern void setup_glob_ignore (const char *); extern int should_ignore_glob_matches (void); extern void ignore_glob_matches (char **); diff --git a/pcomplete.c b/pcomplete.c index d8398c3f..737b6cf6 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -1,6 +1,6 @@ /* pcomplete.c - functions to generate lists of matches for programmable completion. */ -/* Copyright (C) 1999-2022 Free Software Foundation, Inc. +/* Copyright (C) 1999-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -111,7 +111,7 @@ static int it_init_setopts (ITEMLIST *); static int it_init_shopts (ITEMLIST *); static int shouldexp_filterpat (char *); -static char *preproc_filterpat (char *, const char *); +static char *preproc_filterpat (const char *, const char *); static void init_itemlist_from_varlist (ITEMLIST *, SVFUNC *); @@ -140,7 +140,7 @@ static SHELL_VAR *bind_comp_words (WORD_LIST *); #endif static void bind_compfunc_variables (char *, int, WORD_LIST *, int, int); static void unbind_compfunc_variables (int); -static WORD_LIST *build_arg_list (char *, const char *, const char *, WORD_LIST *, int); +static WORD_LIST *build_arg_list (const char *, const char *, const char *, WORD_LIST *, int); static WORD_LIST *command_line_to_word_list (char *, int, int, int *, int *); static int compgen_compspec = 0; /* are we generating completions for compgen? */ @@ -263,7 +263,7 @@ shouldexp_filterpat (char *s) quote a `&' and inhibit substitution. Returns a new string. This just calls stringlib.c:strcreplace(). */ static char * -preproc_filterpat (char *pat, const char *text) +preproc_filterpat (const char *pat, const char *text) { char *ret; @@ -1004,7 +1004,7 @@ unbind_compfunc_variables (int exported) make do with the COMP_LINE and COMP_POINT variables. */ static WORD_LIST * -build_arg_list (char *cmd, const char *cname, const char *text, WORD_LIST *lwords, int ind) +build_arg_list (const char *cmd, const char *cname, const char *text, WORD_LIST *lwords, int ind) { WORD_LIST *ret, *cl, *l; WORD_DESC *w; diff --git a/pcomplete.h b/pcomplete.h index 1b2b0a0c..f0821b19 100644 --- a/pcomplete.h +++ b/pcomplete.h @@ -1,7 +1,7 @@ /* pcomplete.h - structure definitions and other stuff for programmable completion. */ -/* Copyright (C) 1999-2022 Free Software Foundation, Inc. +/* Copyright (C) 1999-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. diff --git a/redir.c b/redir.c index 38a94281..f3407c69 100644 --- a/redir.c +++ b/redir.c @@ -103,11 +103,11 @@ static int undoablefd (int); static int do_redirection_internal (REDIRECT *, int, char **); static char *heredoc_expand (WORD_DESC *, enum r_instruction, size_t *); -static int heredoc_write (int, char *, size_t); +static int heredoc_write (int, const char *, size_t); static int here_document_to_fd (WORD_DESC *, enum r_instruction); static int redir_special_open (int, char *, int, int, enum r_instruction); -static int noclobber_open (char *, int, int, enum r_instruction); +static int noclobber_open (const char *, int, int, enum r_instruction); static int redir_open (char *, int, int, enum r_instruction); static int redir_varassign (REDIRECT *, int); @@ -400,7 +400,7 @@ heredoc_expand (WORD_DESC *redirectee, enum r_instruction ri, size_t *lenp) /* Write HEREDOC (of length HDLEN) to FD, returning 0 on success and ERRNO on error. Don't handle interrupts. */ static int -heredoc_write (int fd, char *heredoc, size_t herelen) +heredoc_write (int fd, const char *heredoc, size_t herelen) { ssize_t nw; int e; @@ -646,7 +646,7 @@ redir_special_open (int spec, char *filename, int flags, int mode, enum r_instru race conditions and avoiding the problem where the file is replaced between the stat(2) and open(2). */ static int -noclobber_open (char *filename, int flags, int mode, enum r_instruction ri) +noclobber_open (const char *filename, int flags, int mode, enum r_instruction ri) { int r, fd; struct stat finfo, finfo2; diff --git a/stringlib.c b/stringlib.c index c91fc2c2..068cd6a3 100644 --- a/stringlib.c +++ b/stringlib.c @@ -1,6 +1,6 @@ /* stringlib.c - Miscellaneous string functions. */ -/* Copyright (C) 1996-2009,2022 Free Software Foundation, Inc. +/* Copyright (C) 1996-2009,2022-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -131,7 +131,7 @@ substring (const char *string, int start, int end) replace all occurrences, otherwise replace only the first. This returns a new string; the caller should free it. */ char * -strsub (char *string, char *pat, char *rep, int global) +strsub (const char *string, const char *pat, const char *rep, int global) { size_t patlen, replen, templen, tempsize, i; int repl; @@ -146,8 +146,13 @@ strsub (char *string, char *pat, char *rep, int global) if (replen) RESIZE_MALLOCED_BUFFER (temp, templen, replen, tempsize, (replen * 2)); - for (r = rep; *r; ) /* can rep == "" */ +#if 0 + for (r = (char *)rep; *r; ) /* can rep == "" */ temp[templen++] = *r++; +#else + memcpy (temp + templen, rep, replen); + templen += replen; +#endif i += patlen ? patlen : 1; /* avoid infinite recursion */ repl = global != 0; @@ -170,9 +175,9 @@ strsub (char *string, char *pat, char *rep, int global) globbing. Backslash may be used to quote C. If (FLAGS & 2) we allow backslash to escape backslash as well. */ char * -strcreplace (char *string, int c, const char *text, int flags) +strcreplace (const char *string, int c, const char *text, int flags) { - char *ret, *p, *r, *t; + char *ret, *r, *p, *t; size_t len, rlen, ind, tlen; int do_glob, escape_backslash; @@ -183,7 +188,7 @@ strcreplace (char *string, int c, const char *text, int flags) rlen = len + strlen (string) + 2; ret = (char *)xmalloc (rlen); - for (p = string, r = ret; p && *p; ) + for (p = (char *)string, r = ret; p && *p; ) { if (*p == c) { diff --git a/subst.c b/subst.c index c2146f96..a3b59c21 100644 --- a/subst.c +++ b/subst.c @@ -4,7 +4,7 @@ /* ``Have a little faith, there's magic in the night. You ain't a beauty, but, hey, you're alright.'' */ -/* 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. @@ -144,7 +144,7 @@ extern int errno; /* An expansion function that takes a string and a quoted flag and returns a WORD_LIST *. Used as the type of the third argument to expand_string_if_necessary(). */ -typedef WORD_LIST *EXPFUNC (char *, int); +typedef WORD_LIST *EXPFUNC (const char *, int); /* Process ID of the last command executed within command substitution. */ pid_t last_command_subst_pid = NO_PID; @@ -240,10 +240,10 @@ static char *quoted_strchr (char *, int, int); static char *expand_string_if_necessary (char *, int, EXPFUNC *); static inline char *expand_string_to_string_internal (char *, int, EXPFUNC *); static WORD_LIST *call_expand_word_internal (WORD_DESC *, int, int, int *, int *); -static WORD_LIST *expand_string_internal (char *, int); -static WORD_LIST *expand_string_leave_quoted (char *, int); -static WORD_LIST *expand_string_for_rhs (char *, int, int, int, int *, int *); -static WORD_LIST *expand_string_for_pat (char *, int, int *, int *); +static WORD_LIST *expand_string_internal (const char *, int); +static WORD_LIST *expand_string_leave_quoted (const char *, int); +static WORD_LIST *expand_string_for_rhs (const char *, int, int, int, int *, int *); +static WORD_LIST *expand_string_for_pat (const char *, int, int *, int *); static char *quote_escapes_internal (const char *, int); @@ -253,28 +253,28 @@ static WORD_LIST *list_dequote_escapes (WORD_LIST *); static char *make_quoted_char (int); static WORD_LIST *quote_list (WORD_LIST *); -static int unquoted_substring (char *, char *); -static int unquoted_member (int, char *); +static int unquoted_substring (const char *, const char *); +static int unquoted_member (int, const char *); #if defined (ARRAY_VARS) -static SHELL_VAR *do_compound_assignment (char *, char *, int); +static SHELL_VAR *do_compound_assignment (const char *, char *, int); #endif static int do_assignment_internal (const WORD_DESC *, int); -static char *string_extract_verbatim (char *, size_t, int *, char *, int); -static char *string_extract (char *, int *, char *, int); -static char *string_extract_double_quoted (char *, int *, int); -static inline char *string_extract_single_quoted (char *, int *, int); +static char *string_extract_verbatim (const char *, size_t, int *, char *, int); +static char *string_extract (const char *, int *, const char *, int); +static char *string_extract_double_quoted (const char *, int *, int); +static inline char *string_extract_single_quoted (const char *, int *, int); static inline int skip_single_quoted (const char *, size_t, int, int); -static int skip_double_quoted (char *, size_t, int, int); -static char *extract_delimited_string (char *, int *, char *, char *, char *, int); -static char *extract_heredoc_dolbrace_string (char *, int *, int, int); -static char *extract_dollar_brace_string (char *, int *, int, int); +static int skip_double_quoted (const char *, size_t, int, int); +static char *extract_delimited_string (const char *, int *, char *, char *, char *, int); +static char *extract_heredoc_dolbrace_string (const char *, int *, int, int); +static char *extract_dollar_brace_string (const char *, int *, int, int); static int skip_matched_pair (const char *, int, int, int, int); -static char *pos_params (char *, int, int, int, int); +static char *pos_params (const char *, int, int, int, int); -static unsigned char *mb_getcharlens (char *, int); +static unsigned char *mb_getcharlens (const char *, int); static char *remove_upattern (char *, char *, int); #if defined (HANDLE_MULTIBYTE) @@ -287,7 +287,7 @@ static int match_upattern (char *, char *, int, char **, char **); static int match_wpattern (wchar_t *, char **, size_t, wchar_t *, int, char **, char **); #endif static int match_pattern (char *, char *, int, char **, char **); -static int getpatspec (int, char *); +static int getpatspec (int, const char *); static char *getpattern (char *, int, int); static char *variable_remove_pattern (char *, char *, int, int); static char *list_remove_pattern (WORD_LIST *, char *, int, int, int); @@ -309,7 +309,7 @@ static char *parameter_list_transform (int, int, int); static char *array_transform (int, SHELL_VAR *, int, int); #endif static char *parameter_brace_transform (char *, char *, array_eltstate_t *, char *, int, int, int, int); -static int valid_parameter_transform (char *); +static int valid_parameter_transform (const char *); static char *process_substitute (char *, int); @@ -317,11 +317,11 @@ static char *optimize_cat_file (REDIRECT *, int, int, int *); static char *read_comsub (int, int, int, int *); #ifdef ARRAY_VARS -static arrayind_t array_length_reference (char *); +static arrayind_t array_length_reference (const char *); #endif -static int valid_brace_expansion_word (char *, int); -static int chk_atstar (char *, int, int, int *, int *); +static int valid_brace_expansion_word (const char *, int); +static int chk_atstar (const char *, int, int, int *, int *); static int chk_arithsub (const char *, int); static WORD_DESC *parameter_brace_expand_word (char *, int, int, int, array_eltstate_t *); @@ -330,16 +330,16 @@ static WORD_DESC *parameter_brace_expand_indir (char *, int, int, int, int *, in static WORD_DESC *parameter_brace_expand_rhs (char *, char *, int, int, int, int *, int *); static void parameter_brace_expand_error (char *, char *, int); -static int valid_length_expression (char *); +static int valid_length_expression (const char *); static intmax_t parameter_brace_expand_length (char *); static char *skiparith (char *, int); static int verify_substring_values (SHELL_VAR *, char *, char *, int, intmax_t *, intmax_t *); static int get_var_and_type (char *, char *, array_eltstate_t *, int, int, SHELL_VAR **, char **); -static char *mb_substring (char *, int, int); +static char *mb_subfstring (const char *, int, int); static char *parameter_brace_substring (char *, char *, array_eltstate_t *, char *, int, int, int); -static int shouldexp_replacement (char *); +static int shouldexp_replacement (const char *); static char *pos_params_pat_subst (char *, char *, char *, int); @@ -636,7 +636,7 @@ quoted_strchr (char *s, int c, int flags) /* Return 1 if CHARACTER appears in an unquoted portion of STRING. Return 0 otherwise. CHARACTER must be a single-byte character. */ static int -unquoted_member (int character, char *string) +unquoted_member (int character, const char *string) { size_t slen; int sindex, c; @@ -675,7 +675,7 @@ unquoted_member (int character, char *string) /* Return 1 if SUBSTR appears in an unquoted portion of STRING. */ static int -unquoted_substring (char *substr, char *string) +unquoted_substring (const char *substr, const char *string) { size_t slen; int sindex, c, sublen; @@ -776,7 +776,7 @@ sub_append_number (intmax_t number, char *target, size_t *indx, size_t *size) update SINDEX. If (flags & SX_REQMATCH) is non-zero, the string must contain a closing character from CHARLIST. */ static char * -string_extract (char *string, int *sindex, char *charlist, int flags) +string_extract (const char *string, int *sindex, const char *charlist, int flags) { register int c, i; int found; @@ -837,10 +837,10 @@ string_extract (char *string, int *sindex, char *charlist, int flags) Backslashes between the embedded double quotes are processed. If STRIPDQ is zero, an unquoted `"' terminates the string. */ static char * -string_extract_double_quoted (char *string, int *sindex, int flags) +string_extract_double_quoted (const char *string, int *sindex, int flags) { size_t slen; - char *send; + const char *send; int j, i, t; unsigned char c; char *temp, *ret; /* The new string we return. */ @@ -948,7 +948,7 @@ add_one_character: if (ret == 0 && no_longjmp_on_fatal_error) { free_ret = 0; - ret = string + i + 2; + ret = (char *)string + i + 2; } /* XXX - CHECK_STRING_OVERRUN here? */ @@ -998,7 +998,7 @@ add_one_character: /* This should really be another option to string_extract_double_quoted. */ static int -skip_double_quoted (char *string, size_t slen, int sind, int flags) +skip_double_quoted (const char *string, size_t slen, int sind, int flags) { int c, i; char *ret; @@ -1069,7 +1069,7 @@ skip_double_quoted (char *string, size_t slen, int sind, int flags) the closing single quote. ALLOWESC allows the single quote to be quoted by a backslash; it's not used yet. */ static inline char * -string_extract_single_quoted (char *string, int *sindex, int allowesc) +string_extract_single_quoted (const char *string, int *sindex, int allowesc) { register int i; size_t slen; @@ -1130,7 +1130,7 @@ skip_single_quoted (const char *string, size_t slen, int sind, int flags) /* Just like string_extract, but doesn't hack backslashes or any of that other stuff. Obeys CTLESC quoting. Used to do splitting on $IFS. */ static char * -string_extract_verbatim (char *string, size_t slen, int *sindex, char *charlist, int flags) +string_extract_verbatim (const char *string, size_t slen, int *sindex, char *charlist, int flags) { register int i; #if defined (HANDLE_MULTIBYTE) @@ -1153,9 +1153,10 @@ string_extract_verbatim (char *string, size_t slen, int *sindex, char *charlist, *sindex */ if (*charlist == 0) { - temp = string + *sindex; - c = (*sindex == 0) ? slen : STRLEN (temp); - temp = savestring (temp); + const char *xtemp; + xtemp = string + *sindex; + c = (*sindex == 0) ? slen : STRLEN (xtemp); + temp = savestring (xtemp); *sindex += c; return temp; } @@ -1242,16 +1243,18 @@ string_extract_verbatim (char *string, size_t slen, int *sindex, char *charlist, Make (SINDEX) get the position of the matching ")". ) XFLAGS is additional flags to pass to other extraction functions. */ char * -extract_command_subst (char *string, int *sindex, int xflags) +extract_command_subst (const char *string, int *sindex, int xflags) { char *ret; + char *xstr; if (string[*sindex] == LPAREN || (xflags & SX_COMPLETE)) return (extract_delimited_string (string, sindex, "$(", "(", ")", xflags|SX_COMMAND)); /*)*/ else { xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0); - ret = xparse_dolparen (string, string+*sindex, sindex, xflags); + xstr = (char *)string + *sindex; + ret = xparse_dolparen (string, xstr, sindex, xflags); return ret; } } @@ -1260,7 +1263,7 @@ extract_command_subst (char *string, int *sindex, int xflags) Start extracting at (SINDEX) as if we had just seen "$[". Make (SINDEX) get the position of the matching "]". */ char * -extract_arithmetic_subst (char *string, int *sindex) +extract_arithmetic_subst (const char *string, int *sindex) { return (extract_delimited_string (string, sindex, "$[", "[", "]", 0)); /*]*/ } @@ -1270,14 +1273,17 @@ extract_arithmetic_subst (char *string, int *sindex) Start extracting at (SINDEX) as if we had just seen "<(". Make (SINDEX) get the position of the matching ")". */ /*))*/ char * -extract_process_subst (char *string, char *starter, int *sindex, int xflags) +extract_process_subst (const char *string, char *starter, int *sindex, int xflags) { #if 0 /* XXX - check xflags&SX_COMPLETE here? */ return (extract_delimited_string (string, sindex, starter, "(", ")", SX_COMMAND)); #else + char *xstr; + xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0); - return (xparse_dolparen (string, string+*sindex, sindex, xflags)); + xstr = (char *)string + *sindex; + return (xparse_dolparen (string, xstr, sindex, xflags)); #endif } #endif /* PROCESS_SUBSTITUTION */ @@ -1287,7 +1293,7 @@ extract_process_subst (char *string, char *starter, int *sindex, int xflags) each caller verifies that the last character in STRING is a right paren, we don't even need to call extract_delimited_string. */ char * -extract_array_assignment_list (char *string, int *sindex) +extract_array_assignment_list (const char *string, int *sindex) { int slen; char *ret; @@ -1312,7 +1318,7 @@ extract_array_assignment_list (char *string, int *sindex) contains a character string that can also match CLOSER and thus needs to be skipped. */ static char * -extract_delimited_string (char *string, int *sindex, char *opener, char *alt_opener, char *closer, int flags) +extract_delimited_string (const char *string, int *sindex, char *opener, char *alt_opener, char *closer, int flags) { int i, c, si; size_t slen; @@ -1480,12 +1486,13 @@ extract_delimited_string (char *string, int *sindex, char *opener, char *alt_ope This needs to match the logic in parse.y:parse_matched_pair so we get consistent behavior between here-documents and double-quoted strings. */ static char * -extract_heredoc_dolbrace_string (char *string, int *sindex, int quoted, int flags) +extract_heredoc_dolbrace_string (const char *string, int *sindex, int quoted, int flags) { register int i, c; size_t slen, tlen, result_index, result_size; int pass_character, nesting_level, si, dolbrace_state; - char *result, *t, *send; + char *result, *t; + const char *send; DECLARE_MBSTATE; pass_character = 0; @@ -1760,7 +1767,7 @@ static int dbstate[PARAMEXPNEST_MAX]; occurs inside double quotes. */ /* XXX -- this is very similar to extract_delimited_string -- XXX */ static char * -extract_dollar_brace_string (char *string, int *sindex, int quoted, int flags) +extract_dollar_brace_string (const char *string, int *sindex, int quoted, int flags) { register int i, c; size_t slen; @@ -2122,7 +2129,7 @@ skipsubscript (const char *string, int start, int flags) a lot of shell syntax. It's very similar to skip_double_quoted and other functions of that ilk. */ int -skip_to_delim (char *string, int start, char *delims, int flags) +skip_to_delim (const char *string, int start, const char *delims, int flags) { int i, pass_next, backq, dquote, si, c, oldjmp; int invert, skipquote, skipcmd, noprocsub, completeflag; @@ -2300,7 +2307,7 @@ skip_to_delim (char *string, int start, char *delims, int flags) down version of skip_to_delims. The essential difference is that this resets the quoting state when starting a command substitution */ int -skip_to_histexp (char *string, int start, char *delims, int flags) +skip_to_histexp (const char *string, int start, const char *delims, int flags) { int i, pass_next, backq, dquote, c, oldjmp; int histexp_comsub, histexp_backq, old_dquote; @@ -2539,7 +2546,7 @@ unclosed_pair (char *string, int eindex, char *openstr) the index of the word containing SENTINEL. Non-whitespace chars in DELIMS delimit separate fields. This is used by programmable completion. */ WORD_LIST * -split_at_delims (char *string, int slen, const char *delims, int sentinel, int flags, int *nwp, int *cwp) +split_at_delims (const char *string, int slen, const char *delims, int sentinel, int flags, int *nwp, int *cwp) { int ts, te, i, nw, cw, ifs_split, dflags; char *token, *d, *d2; @@ -2702,7 +2709,7 @@ split_at_delims (char *string, int slen, const char *delims, int sentinel, int f /* UNUSED */ /* Extract the name of the variable to bind to from the assignment string. */ char * -assignment_name (char *string) +assignment_name (const char *string) { int offset; char *temp; @@ -3364,7 +3371,7 @@ list_string_with_quotes (char *string) #if defined (ARRAY_VARS) static SHELL_VAR * -do_compound_assignment (char *name, char *value, int flags) +do_compound_assignment (const char *name, char *value, int flags) { SHELL_VAR *v; int mklocal, mkassoc, mkglobal, chklocal; @@ -3412,7 +3419,7 @@ do_compound_assignment (char *name, char *value, int flags) return (v); /* XXX */ } /* sanity check */ - newname = (v == 0) ? nameref_transform_name (name, flags) : name; + newname = (v == 0) ? nameref_transform_name (name, flags) : (char *)name; list = expand_compound_array_assignment (v, value, flags); if (v == 0 && mkassoc) v = make_new_assoc_variable (newname); @@ -3578,7 +3585,7 @@ do_assignment (char *string) } int -do_word_assignment (WORD_DESC *word, int flags) +do_word_assignment (const WORD_DESC *word, int flags) { return do_assignment_internal (word, 1); } @@ -3660,7 +3667,7 @@ string_rest_of_args (int dollar_star) Q_HERE_DOCUMENT or Q_DOUBLE_QUOTES, this returns a quoted list, otherwise no quoting chars are added. */ static char * -pos_params (char *string, int start, int end, int quoted, int pflags) +pos_params (const char *string, int start, int end, int quoted, int pflags) { WORD_LIST *save, *params, *h, *t; char *ret; @@ -3806,7 +3813,7 @@ expand_assignment_string_to_string (char *string, int quoted) or a backslash into a backslash. The output of this function must eventually be processed by strcreplace(). */ static char * -quote_string_for_repl (char *string, int flags) +quote_string_for_repl (const char *string, int flags) { size_t slen; char *result, *t; @@ -3961,9 +3968,10 @@ expand_arith_string (char *string, int quoted) #if defined (COND_COMMAND) /* Just remove backslashes in STRING. Returns a new string. */ char * -remove_backslashes (char *string) +remove_backslashes (const char *string) { - char *r, *ret, *s; + char *r, *ret; + const char *s; r = ret = (char *)xmalloc (strlen (string) + 1); for (s = string; s && *s; ) @@ -4047,11 +4055,12 @@ cond_expand_word (WORD_DESC *w, int special) FLAGS argument is 1 if this function should treat CTLESC as a quote character (e.g., for here-documents) or not (e.g., for shell_expand_line). */ char * -expand_string_dollar_quote (char *string, int flags) +expand_string_dollar_quote (const char *string, int flags) { size_t slen, retind, retsize; int sindex, c, translen, peekc, news; - char *ret, *trans, *send, *t; + char *ret, *trans, *t; + const char *send; DECLARE_MBSTATE; slen = strlen (string); @@ -4215,7 +4224,7 @@ call_expand_word_internal (WORD_DESC *w, int q, int i, int *c, int *e) Since this does not perform word splitting, it leaves quoted nulls in the result. */ static WORD_LIST * -expand_string_internal (char *string, int quoted) +expand_string_internal (const char *string, int quoted) { WORD_DESC td; WORD_LIST *tresult; @@ -4238,7 +4247,7 @@ expand_string_internal (char *string, int quoted) remove_quoted_nulls () is in here because word splitting normally takes care of quote removal. */ WORD_LIST * -expand_string_unsplit (char *string, int quoted) +expand_string_unsplit (const char *string, int quoted) { WORD_LIST *value; @@ -4263,7 +4272,7 @@ expand_string_unsplit (char *string, int quoted) /* Expand the rhs of an assignment statement */ WORD_LIST * -expand_string_assignment (char *string, int quoted) +expand_string_assignment (const char *string, int quoted) { WORD_DESC td; WORD_LIST *value; @@ -4307,7 +4316,7 @@ expand_string_assignment (char *string, int quoted) passed string when an error occurs. Might want to trap other calls to jump_to_top_level here so we don't endlessly loop. */ WORD_LIST * -expand_prompt_string (char *string, int quoted, int wflags) +expand_prompt_string (const char *string, int quoted, int wflags) { WORD_LIST *value; WORD_DESC td; @@ -4346,7 +4355,7 @@ expand_prompt_string (char *string, int quoted, int wflags) things like ${1+"$@"}. This does parameter expansion, command substitution, arithmetic expansion, and word splitting. */ static WORD_LIST * -expand_string_leave_quoted (char *string, int quoted) +expand_string_leave_quoted (const char *string, int quoted) { WORD_LIST *tlist; WORD_LIST *tresult; @@ -4368,7 +4377,7 @@ expand_string_leave_quoted (char *string, int quoted) /* This does not perform word splitting or dequote the WORD_LIST it returns. */ static WORD_LIST * -expand_string_for_rhs (char *string, int quoted, int op, int pflags, int *dollar_at_p, int *expanded_p) +expand_string_for_rhs (const char *string, int quoted, int op, int pflags, int *dollar_at_p, int *expanded_p) { WORD_DESC td; WORD_LIST *tresult; @@ -4413,7 +4422,7 @@ expand_string_for_rhs (char *string, int quoted, int op, int pflags, int *dollar /* This does not perform word splitting or dequote the WORD_LIST it returns and it treats $* as if it were quoted. */ static WORD_LIST * -expand_string_for_pat (char *string, int quoted, int *dollar_at_p, int *expanded_p) +expand_string_for_pat (const char *string, int quoted, int *dollar_at_p, int *expanded_p) { WORD_DESC td; WORD_LIST *tresult; @@ -4439,7 +4448,7 @@ expand_string_for_pat (char *string, int quoted, int *dollar_at_p, int *expanded does parameter expansion, command substitution, arithmetic expansion, and word splitting. Dequote the resultant WORD_LIST before returning. */ WORD_LIST * -expand_string (char *string, int quoted) +expand_string (const char *string, int quoted) { WORD_LIST *result; @@ -4575,7 +4584,7 @@ quote_rhs (const char *string) static WORD_LIST * list_quote_escapes (WORD_LIST *list) { - register WORD_LIST *w; + WORD_LIST *w; char *t; for (w = list; w; w = w->next) @@ -4680,11 +4689,12 @@ make_quoted_char (int c) the W_HASQUOTEDNULL flag needs to be set in any resultant WORD_DESC where this value is the word. */ char * -quote_string (char *string) +quote_string (const char *string) { register char *t; size_t slen; - char *result, *send; + char *result; + const char *send; if (*string == 0) { @@ -4713,11 +4723,12 @@ quote_string (char *string) /* De-quote quoted characters in STRING. */ char * -dequote_string (char *string) +dequote_string (const char *string) { register char *s, *t; size_t slen; - char *result, *send; + char *result; + const char *send; DECLARE_MBSTATE; if (string[0] == CTLESC && string[1] == 0) @@ -4747,7 +4758,7 @@ dequote_string (char *string) return (strcpy (result, string)); send = string + slen; - s = string; + s = (char *)string; while (*s) { if (*s == CTLESC) @@ -4767,7 +4778,7 @@ dequote_string (char *string) static WORD_LIST * quote_list (WORD_LIST *list) { - register WORD_LIST *w; + WORD_LIST *w; char *t; for (w = list; w; w = w->next) @@ -4785,7 +4796,7 @@ quote_list (WORD_LIST *list) WORD_DESC * dequote_word (WORD_DESC *word) { - register char *s; + char *s; s = dequote_string (word->word); if (QUOTED_NULL (word->word)) @@ -4800,8 +4811,8 @@ dequote_word (WORD_DESC *word) WORD_LIST * dequote_list (WORD_LIST *list) { - register char *s; - register WORD_LIST *tlist; + char *s; + WORD_LIST *tlist; for (tlist = list; tlist; tlist = tlist->next) { @@ -4835,12 +4846,13 @@ remove_quoted_escapes (char *string) added to protect them from word splitting, but we need to remove them if no word splitting takes place. This returns newly-allocated memory, so callers can use it to replace savestring(). */ -char * -remove_quoted_ifs (char *string) +static char * +remove_quoted_ifs (const char *string) { register size_t slen; register int i, j; - char *ret, *send; + char *ret; + const char *send; DECLARE_MBSTATE; slen = strlen (string); @@ -4936,7 +4948,7 @@ word_list_remove_quoted_nulls (WORD_LIST *list) #if defined (HANDLE_MULTIBYTE) # ifdef INCLUDE_UNUSED static unsigned char * -mb_getcharlens (char *string, int len) +mb_getcharlens (const char *string, int len) { int i, offset, last; unsigned char *ret; @@ -4975,9 +4987,9 @@ mb_getcharlens (char *string, int len) static char * remove_upattern (char *param, char *pattern, int op) { - register size_t len; - register char *end; - register char *p, *ret, c; + size_t len; + char *end, *p; + char *ret, c; len = STRLEN (param); end = param + len; @@ -5515,7 +5527,7 @@ match_pattern (char *string, char *pat, int mtype, char **sp, char **ep) } static int -getpatspec (int c, char *value) +getpatspec (int c, const char *value) { if (c == '#') return ((*value == '#') ? RP_LONG_LEFT : RP_SHORT_LEFT); @@ -6986,7 +6998,7 @@ command_substitute (char *string, int quoted, int flags) #if defined (ARRAY_VARS) static arrayind_t -array_length_reference (char *s) +array_length_reference (const char *s) { int len; arrayind_t ind; @@ -7066,7 +7078,7 @@ array_length_reference (char *s) #endif /* ARRAY_VARS */ static int -valid_brace_expansion_word (char *name, int var_is_special) +valid_brace_expansion_word (const char *name, int var_is_special) { if (DIGIT (*name) && all_digits (name)) return 1; @@ -7083,7 +7095,7 @@ valid_brace_expansion_word (char *name, int var_is_special) } static int -chk_atstar (char *name, int quoted, int pflags, int *quoted_dollar_atp, int *contains_dollar_at) +chk_atstar (const char *name, int quoted, int pflags, int *quoted_dollar_atp, int *contains_dollar_at) { char *temp1; @@ -7712,7 +7724,7 @@ parameter_brace_expand_error (char *name, char *value, int check_null) /* Return 1 if NAME is something for which parameter_brace_expand_length is OK to do. */ static int -valid_length_expression (char *name) +valid_length_expression (const char *name) { return (name[1] == '\0' || /* ${#} */ ((sh_syntaxtab[(unsigned char) name[1]] & CSPECVAR) && name[2] == '\0') || /* special param */ @@ -8356,7 +8368,7 @@ array_transform (int xc, SHELL_VAR *var, int starsub, int quoted) #endif /* ARRAY_VARS */ static inline int -valid_parameter_transform (char *xform) +valid_parameter_transform (const char *xform) { if (xform[1]) return 0; @@ -8480,7 +8492,7 @@ parameter_brace_transform (char *varname, char *value, array_eltstate_t *estatep multibyte character) positions that require calculation. Used by the ${param:offset[:length]} expansion. */ static char * -mb_substring (char *string, int s, int e) +mb_substring (const char *string, int s, int e) { char *tt; int start, stop, i; @@ -8610,7 +8622,7 @@ parameter_brace_substring (char *varname, char *value, array_eltstate_t *estatep /****************************************************************/ static int -shouldexp_replacement (char *s) +shouldexp_replacement (const char *s) { size_t slen; int sindex, c; @@ -10486,7 +10498,7 @@ static char abstab[256] = { '\1' }; /* Run an array subscript through the appropriate word expansions. */ char * -expand_subscript_string (char *string, int quoted) +expand_subscript_string (const char *string, int quoted) { WORD_DESC td; WORD_LIST *tlist; @@ -10526,7 +10538,7 @@ expand_subscript_string (char *string, int quoted) only expand it once, we quote the characters that would start another expansion and the bracket characters that are special to array subscripts. */ static char * -expand_array_subscript (char *string, int *sindex, int quoted, int flags) +expand_array_subscript (const char *string, int *sindex, int quoted, int flags) { char *ret, *exp, *t; size_t slen; @@ -11575,10 +11587,11 @@ set_word_flags: /* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the backslash quoting rules for within double quotes or a here document. */ char * -string_quote_removal (char *string, int quoted) +string_quote_removal (const char *string, int quoted) { size_t slen; - char *r, *result_string, *temp, *send; + char *r, *result_string, *temp; + const char *send; int sindex, tindex, dquote; unsigned char c; DECLARE_MBSTATE; diff --git a/subst.h b/subst.h index 9c9194ea..a59d20ec 100644 --- a/subst.h +++ b/subst.h @@ -1,6 +1,6 @@ /* subst.h -- Names of externally visible functions in subst.c. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -84,22 +84,22 @@ extern void unquote_bang (char *); Start extracting at (SINDEX) as if we had just seen "$(". Make (SINDEX) get the position just after the matching ")". XFLAGS is additional flags to pass to other extraction functions, */ -extern char *extract_command_subst (char *, int *, int); +extern char *extract_command_subst (const char *, int *, int); /* Extract the $[ construct in STRING, and return a new string. Start extracting at (SINDEX) as if we had just seen "$[". Make (SINDEX) get the position just after the matching "]". */ -extern char *extract_arithmetic_subst (char *, int *); +extern char *extract_arithmetic_subst (const char *, int *); #if defined (PROCESS_SUBSTITUTION) /* Extract the <( or >( construct in STRING, and return a new string. Start extracting at (SINDEX) as if we had just seen "<(". Make (SINDEX) get the position just after the matching ")". */ -extern char *extract_process_subst (char *, char *, int *, int); +extern char *extract_process_subst (const char *, char *, int *, int); #endif /* PROCESS_SUBSTITUTION */ /* Extract the name of the variable to bind to from the assignment string. */ -extern char *assignment_name (char *); +extern char *assignment_name (const char *); /* Return a single string of all the words present in LIST, separating each word with SEP. */ @@ -140,7 +140,7 @@ extern char *strip_trailing_ifs_whitespace (char *, char *, int); splitting on the result of expansion. */ extern int do_assignment (char *); extern int do_assignment_no_expand (char *); -extern int do_word_assignment (WORD_DESC *, int); +extern int do_word_assignment (const WORD_DESC *, int); /* Append SOURCE to TARGET at INDEX. SIZE is the current amount of space allocated to TARGET. SOURCE can be NULL, in which @@ -165,20 +165,20 @@ extern char *string_rest_of_args (int); returning it, but do not perform word splitting. The call to remove_quoted_nulls () is made here because word splitting normally takes care of quote removal. */ -extern WORD_LIST *expand_string_unsplit (char *, int); +extern WORD_LIST *expand_string_unsplit (const char *, int); /* Expand the rhs of an assignment statement. */ -extern WORD_LIST *expand_string_assignment (char *, int); +extern WORD_LIST *expand_string_assignment (const char *, int); /* Expand a prompt string. */ -extern WORD_LIST *expand_prompt_string (char *, int, int); +extern WORD_LIST *expand_prompt_string (const char *, int, int); /* Expand STRING just as if you were expanding a word. This also returns a list of words. Note that filename globbing is *NOT* done for word or string expansion, just when the shell is expanding a command. This does parameter expansion, command substitution, arithmetic expansion, and word splitting. Dequote the resultant WORD_LIST before returning. */ -extern WORD_LIST *expand_string (char *, int); +extern WORD_LIST *expand_string (const char *, int); /* Convenience functions that expand strings to strings, taking care of converting the WORD_LIST * returned by the expand_string* functions @@ -186,16 +186,16 @@ extern WORD_LIST *expand_string (char *, int); extern char *expand_string_to_string (char *, int); extern char *expand_string_unsplit_to_string (char *, int); extern char *expand_assignment_string_to_string (char *, int); -extern char *expand_subscript_string (char *, int); +extern char *expand_subscript_string (const char *, int); /* Expand an arithmetic expression string */ extern char *expand_arith_string (char *, int); /* Expand $'...' and $"..." in a string for code paths that do not. */ -extern char *expand_string_dollar_quote (char *, int); +extern char *expand_string_dollar_quote (const char *, int); /* De-quote quoted characters in STRING. */ -extern char *dequote_string (char *); +extern char *dequote_string (const char *); /* De-quote CTLESC-escaped CTLESC or CTLNUL characters in STRING. */ extern char *dequote_escapes (const char *); @@ -220,7 +220,7 @@ extern WORD_LIST *expand_word_leave_quoted (WORD_DESC *, int); extern char *get_dollar_var_value (intmax_t); /* Quote a string to protect it from word splitting. */ -extern char *quote_string (char *); +extern char *quote_string (const char *); /* Quote escape characters (characters special to internals of expansion) in a string. */ @@ -234,7 +234,7 @@ extern char *remove_quoted_nulls (char *); /* Perform quote removal on STRING. If QUOTED > 0, assume we are obeying the backslash quoting rules for within double quotes. */ -extern char *string_quote_removal (char *, int); +extern char *string_quote_removal (const char *, int); /* Perform quote removal on word WORD. This allocates and returns a new WORD_DESC *. */ @@ -295,11 +295,11 @@ extern void reap_procsubs (void); extern WORD_LIST *list_string_with_quotes (char *); #if defined (ARRAY_VARS) -extern char *extract_array_assignment_list (char *, int *); +extern char *extract_array_assignment_list (const char *, int *); #endif #if defined (COND_COMMAND) -extern char *remove_backslashes (char *); +extern char *remove_backslashes (const char *); extern char *cond_expand_word (WORD_DESC *, int); #endif @@ -317,16 +317,16 @@ extern char *cond_expand_word (WORD_DESC *, int); #define SD_ARITHEXP 0x400 /* skip_to_delim during arithmetic expansion */ #define SD_NOERROR 0x800 /* don't print error messages */ -extern int skip_to_delim (char *, int, char *, int); +extern int skip_to_delim (const char *, int, const char *, int); #if defined (BANG_HISTORY) -extern int skip_to_histexp (char *, int, char *, int); +extern int skip_to_histexp (const char *, int, const char *, int); #endif #if defined (READLINE) extern int char_is_quoted (char *, int); extern int unclosed_pair (char *, int, char *); -extern WORD_LIST *split_at_delims (char *, int, const char *, int, int, int *, int *); +extern WORD_LIST *split_at_delims (const char *, int, const char *, int, int, int *, int *); #endif /* Variables used to keep track of the characters in IFS. */ diff --git a/test.c b/test.c index 5098e325..26ef95f2 100644 --- a/test.c +++ b/test.c @@ -2,7 +2,7 @@ /* Modified to run with the GNU shell Apr 25, 1988 by bfox. */ -/* 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. @@ -125,7 +125,7 @@ static int term (void); static int and (void); static int or (void); -static int filecomp (char *, char *, int); +static int filecomp (const char *, const char *, int); static int arithcomp (char *, char *, int, int); static int patcomp (char *, char *, int); @@ -286,7 +286,7 @@ term (void) } static int -stat_mtime (char *fn, struct stat *st, struct timespec *ts) +stat_mtime (const char *fn, struct stat *st, struct timespec *ts) { int r; @@ -298,7 +298,7 @@ stat_mtime (char *fn, struct stat *st, struct timespec *ts) } static int -filecomp (char *s, char *t, int op) +filecomp (const char *s, const char *t, int op) { struct stat st1, st2; struct timespec ts1, ts2; diff --git a/trap.c b/trap.c index 3dc47635..637c8237 100644 --- a/trap.c +++ b/trap.c @@ -1,7 +1,7 @@ /* trap.c -- Not the trap command, but useful functions for manipulating those objects. The trap command is in builtins/trap.def. */ -/* 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. @@ -85,7 +85,7 @@ static void restore_signal (int); static void reset_or_restore_signal_handlers (sh_resetsig_func_t *); static void reinit_trap (int); -static void trap_if_untrapped (int, char *); +static void trap_if_untrapped (int, const char *); /* Variables used here but defined in other files. */ @@ -232,7 +232,7 @@ signal_name (int sig) then (int)2 is returned. Return NO_SIG if STRING doesn't contain a valid signal descriptor. */ int -decode_signal (char *string, int flags) +decode_signal (const char *string, int flags) { intmax_t sig; char *name; @@ -639,7 +639,7 @@ check_signals_and_traps (void) #ifdef INCLUDE_UNUSED /* Make COMMAND_STRING be executed when SIGCHLD is caught. */ void -set_sigchld_trap (char *command_string) +set_sigchld_trap (const char *command_string) { set_signal (SIGCHLD, command_string); } @@ -651,7 +651,7 @@ set_sigchld_trap (char *command_string) reset the disposition to the default and not have the original signal accidentally restored, undoing the user's command. */ void -maybe_set_sigchld_trap (char *command_string) +maybe_set_sigchld_trap (const char *command_string) { if ((sigmodes[SIGCHLD] & SIG_TRAPPED) == 0 && trap_list[SIGCHLD] == (char *)IMPOSSIBLE_TRAP_HANDLER) set_signal (SIGCHLD, command_string); @@ -685,14 +685,14 @@ queue_sigchld_trap (int nchild) /* Set a trap for SIG only if SIG is not already trapped. */ static inline void -trap_if_untrapped (int sig, char *command) +trap_if_untrapped (int sig, const char *command) { if ((sigmodes[sig] & SIG_TRAPPED) == 0) set_signal (sig, command); } void -set_debug_trap (char *command) +set_debug_trap (const char *command) { set_signal (DEBUG_TRAP, command); } @@ -704,38 +704,38 @@ set_debug_trap (char *command) SIG_TRAPPED will be set and we don't bother restoring the original trap string. This is used by both functions and the source builtin. */ void -maybe_set_debug_trap (char *command) +maybe_set_debug_trap (const char *command) { trap_if_untrapped (DEBUG_TRAP, command); } void -set_error_trap (char *command) +set_error_trap (const char *command) { set_signal (ERROR_TRAP, command); } void -maybe_set_error_trap (char *command) +maybe_set_error_trap (const char *command) { trap_if_untrapped (ERROR_TRAP, command); } void -set_return_trap (char *command) +set_return_trap (const char *command) { set_signal (RETURN_TRAP, command); } void -maybe_set_return_trap (char *command) +maybe_set_return_trap (const char *command) { trap_if_untrapped (RETURN_TRAP, command); } #ifdef INCLUDE_UNUSED void -set_sigint_trap (char *command) +set_sigint_trap (const char *command) { set_signal (SIGINT, command); } @@ -780,7 +780,7 @@ trap_to_sighandler (int sig) /* Set SIG to call STRING as a command. */ void -set_signal (int sig, char *string) +set_signal (int sig, const char *string) { sigset_t set, oset; diff --git a/trap.h b/trap.h index 3a0035f2..8ecf5dc1 100644 --- a/trap.h +++ b/trap.h @@ -1,6 +1,6 @@ /* trap.h -- data structures used in the trap mechanism. */ -/* Copyright (C) 1993-2022 Free Software Foundation, Inc. +/* Copyright (C) 1993-2023 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -73,20 +73,20 @@ extern void initialize_traps (void); extern void run_pending_traps (void); extern void queue_sigchld_trap (int); -extern void maybe_set_sigchld_trap (char *); +extern void maybe_set_sigchld_trap (const char *); extern void set_impossible_sigchld_trap (void); -extern void set_sigchld_trap (char *); +extern void set_sigchld_trap (const char *); -extern void set_debug_trap (char *); -extern void set_error_trap (char *); -extern void set_return_trap (char *); +extern void set_debug_trap (const char *); +extern void set_error_trap (const char *); +extern void set_return_trap (const char *); -extern void maybe_set_debug_trap (char *); -extern void maybe_set_error_trap (char *); -extern void maybe_set_return_trap (char *); +extern void maybe_set_debug_trap (const char *); +extern void maybe_set_error_trap (const char *); +extern void maybe_set_return_trap (const char *); -extern void set_sigint_trap (char *); -extern void set_signal (int, char *); +extern void set_sigint_trap (const char *); +extern void set_signal (int, const char *); extern void restore_default_signal (int); extern void ignore_signal (int); @@ -106,7 +106,7 @@ extern void get_all_original_signals (void); extern char *signal_name (int); -extern int decode_signal (char *, int); +extern int decode_signal (const char *, int); extern void run_interrupt_trap (int); extern int maybe_call_trap_handler (int); extern int signal_is_special (int); diff --git a/variables.c b/variables.c index 04dbaedb..24f3ef8c 100644 --- a/variables.c +++ b/variables.c @@ -1,6 +1,6 @@ /* variables.c -- Functions for hacking shell variables. */ -/* 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. @@ -259,11 +259,11 @@ static SHELL_VAR *get_bashargcv (SHELL_VAR *); # endif static SHELL_VAR *build_hashcmd (SHELL_VAR *); static SHELL_VAR *get_hashcmd (SHELL_VAR *); -static SHELL_VAR *assign_hashcmd (SHELL_VAR *, char *, arrayind_t, char *); +static SHELL_VAR *assign_hashcmd (SHELL_VAR *, char *, arrayind_t, char *); # if defined (ALIAS) static SHELL_VAR *build_aliasvar (SHELL_VAR *); static SHELL_VAR *get_aliasvar (SHELL_VAR *); -static SHELL_VAR *assign_aliasvar (SHELL_VAR *, char *, arrayind_t, char *); +static SHELL_VAR *assign_aliasvar (SHELL_VAR *, char *, arrayind_t, char *); # endif #endif @@ -272,14 +272,14 @@ static SHELL_VAR *init_funcname_var (void); static void initialize_dynamic_variables (void); -static SHELL_VAR *bind_invalid_envvar (const char *, char *, int); +static SHELL_VAR *bind_invalid_envvar (const char *, const char *, int); static int var_sametype (SHELL_VAR *, SHELL_VAR *); static SHELL_VAR *hash_lookup (const char *, HASH_TABLE *); static SHELL_VAR *new_shell_variable (const char *); static SHELL_VAR *make_new_variable (const char *, HASH_TABLE *); -static SHELL_VAR *bind_variable_internal (const char *, char *, HASH_TABLE *, int, int); +static SHELL_VAR *bind_variable_internal (const char *, const char *, HASH_TABLE *, int, int); static void dispose_variable_value (SHELL_VAR *); static void free_variable_hash_data (PTR_T); @@ -311,7 +311,7 @@ static SHELL_VAR *find_nameref_at_context (SHELL_VAR *, VAR_CONTEXT *); static SHELL_VAR *find_variable_nameref_context (SHELL_VAR *, VAR_CONTEXT *, VAR_CONTEXT **); static SHELL_VAR *find_variable_last_nameref_context (SHELL_VAR *, VAR_CONTEXT *, VAR_CONTEXT **); -static SHELL_VAR *bind_tempenv_variable (const char *, char *); +static SHELL_VAR *bind_tempenv_variable (const char *, const char *); static void push_posix_temp_var (PTR_T); static void push_temp_var (PTR_T); static void propagate_temp_var (PTR_T); @@ -2215,7 +2215,7 @@ find_variable_nameref_for_assignment (const char *name, int flags) function, but dealing strictly with names. This takes assignment flags so it can deal with the various assignment modes used by `declare'. */ char * -nameref_transform_name (char *name, int flags) +nameref_transform_name (const char *name, int flags) { SHELL_VAR *v; char *newname; @@ -2234,7 +2234,7 @@ nameref_transform_name (char *name, int flags) : find_global_variable_last_nameref (name, 1); if (v && nameref_p (v) && valid_nameref_value (nameref_cell (v), 1)) return nameref_cell (v); - return name; + return (char *)name; } /* Find a variable, forcing a search of the temporary environment first */ @@ -2522,7 +2522,7 @@ validate_inherited_value (SHELL_VAR *var, int type) /* Set NAME to VALUE if NAME has no value. */ SHELL_VAR * -set_if_not (char *name, char *value) +set_if_not (const char *name, const char *value) { SHELL_VAR *v; @@ -2736,7 +2736,7 @@ make_new_variable (const char *name, HASH_TABLE *table) #if defined (ARRAY_VARS) SHELL_VAR * -make_new_array_variable (char *name) +make_new_array_variable (const char *name) { SHELL_VAR *entry; ARRAY *array; @@ -2750,7 +2750,7 @@ make_new_array_variable (char *name) } SHELL_VAR * -make_local_array_variable (char *name, int flags) +make_local_array_variable (const char *name, int flags) { SHELL_VAR *var; ARRAY *array; @@ -2789,7 +2789,7 @@ make_local_array_variable (char *name, int flags) } SHELL_VAR * -make_new_assoc_variable (char *name) +make_new_assoc_variable (const char *name) { SHELL_VAR *entry; HASH_TABLE *hash; @@ -2803,7 +2803,7 @@ make_new_assoc_variable (char *name) } SHELL_VAR * -make_local_assoc_variable (char *name, int flags) +make_local_assoc_variable (const char *name, int flags) { SHELL_VAR *var; HASH_TABLE *hash; @@ -2843,7 +2843,7 @@ make_local_assoc_variable (char *name, int flags) #endif char * -make_variable_value (SHELL_VAR *var, char *value, int flags) +make_variable_value (SHELL_VAR *var, const char *value, int flags) { char *retval, *oval; intmax_t lval, rval; @@ -2949,7 +2949,7 @@ make_value: /* If we can optimize appending to string variables, say so */ static int -can_optimize_assignment (SHELL_VAR *entry, char *value, int aflags) +can_optimize_assignment (SHELL_VAR *entry, const char *value, int aflags) { if ((aflags & ASS_APPEND) == 0) return 0; @@ -2966,7 +2966,7 @@ can_optimize_assignment (SHELL_VAR *entry, char *value, int aflags) /* right now we optimize appends to string variables */ static SHELL_VAR * -optimized_assignment (SHELL_VAR *entry, char *value, int aflags) +optimized_assignment (SHELL_VAR *entry, const char *value, int aflags) { size_t len, vlen; char *v, *new; @@ -2991,7 +2991,7 @@ optimized_assignment (SHELL_VAR *entry, char *value, int aflags) temporary environment (but usually is not). HFLAGS controls how NAME is looked up in TABLE; AFLAGS controls how VALUE is assigned */ static SHELL_VAR * -bind_variable_internal (const char *name, char *value, HASH_TABLE *table, int hflags, int aflags) +bind_variable_internal (const char *name, const char *value, HASH_TABLE *table, int hflags, int aflags) { char *newval, *tname; SHELL_VAR *entry, *tentry; @@ -3075,7 +3075,7 @@ bind_variable_internal (const char *name, char *value, HASH_TABLE *table, int hf } INVALIDATE_EXPORTSTR (entry); - newval = (aflags & ASS_APPEND) ? make_variable_value (entry, value, aflags) : value; + newval = (aflags & ASS_APPEND) ? make_variable_value (entry, value, aflags) : (char *)value; if (assoc_p (entry)) entry = (*(entry->assign_func)) (entry, newval, -1, savestring ("0")); else if (array_p (entry)) @@ -3162,7 +3162,7 @@ assign_value: first, then we bind into shell_variables. */ SHELL_VAR * -bind_variable (const char *name, char *value, int flags) +bind_variable (const char *name, const char *value, int flags) { SHELL_VAR *v, *nv; VAR_CONTEXT *vc, *nvc; @@ -3233,7 +3233,7 @@ bind_variable (const char *name, char *value, int flags) } SHELL_VAR * -bind_global_variable (const char *name, char *value, int flags) +bind_global_variable (const char *name, const char *value, int flags) { if (shell_variables == 0) create_variable_tables (); @@ -3243,7 +3243,7 @@ bind_global_variable (const char *name, char *value, int flags) } static SHELL_VAR * -bind_invalid_envvar (const char *name, char *value, int aflags) +bind_invalid_envvar (const char *name, const char *value, int aflags) { if (invalid_env == 0) invalid_env = hash_create (64); /* XXX */ @@ -3322,7 +3322,7 @@ bind_variable_value (SHELL_VAR *var, char *value, int aflags) variable we set here, then turn it back on after binding as necessary. */ SHELL_VAR * -bind_int_variable (char *lhs, char *rhs, int flags) +bind_int_variable (const char *lhs, const char *rhs, int flags) { register SHELL_VAR *v; int isint, isarr, implicitarray, vflags, avflags; @@ -3386,7 +3386,7 @@ bind_int_variable (char *lhs, char *rhs, int flags) } SHELL_VAR * -bind_var_to_int (char *var, intmax_t val, int flags) +bind_var_to_int (const char *var, intmax_t val, int flags) { char ibuf[INT_STRLEN_BOUND (intmax_t) + 1], *p; @@ -3476,7 +3476,7 @@ bind_function_def (const char *name, FUNCTION_DEF *value, int flags) responsible for moving the main temporary env to one of the other temporary environments. The expansion code in subst.c calls this. */ int -assign_in_env (WORD_DESC *word, int flags) +assign_in_env (const WORD_DESC *word, int flags) { int offset, aflags; char *name, *temp, *value, *newname; @@ -4362,7 +4362,7 @@ all_variables_matching_prefix (const char *prefix) /* Make variable NAME have VALUE in the temporary environment. */ static SHELL_VAR * -bind_tempenv_variable (const char *name, char *value) +bind_tempenv_variable (const char *name, const char *value) { SHELL_VAR *var; @@ -5728,7 +5728,7 @@ find_special_var (const char *name) /* The variable in NAME has just had its state changed. Check to see if it is one of the special ones where something special happens. */ void -stupidly_hack_special_variables (char *name) +stupidly_hack_special_variables (const char *name) { static int sv_sorted = 0; int i; @@ -5742,7 +5742,7 @@ stupidly_hack_special_variables (char *name) i = find_special_var (name); if (i != -1) - (*(special_vars[i].function)) (name); + (*(special_vars[i].function)) ((char *)name); } /* Special variables that need hooks to be run when they are unset as part @@ -5758,7 +5758,7 @@ reinit_special_variables (void) } void -sv_ifs (char *name) +sv_ifs (const char *name) { SHELL_VAR *v; @@ -5768,7 +5768,7 @@ sv_ifs (char *name) /* What to do just after the PATH variable has changed. */ void -sv_path (char *name) +sv_path (const char *name) { /* hash -r */ phash_flush (); @@ -5778,7 +5778,7 @@ sv_path (char *name) is the name of the variable. This is called with NAME set to one of MAIL, MAILCHECK, or MAILPATH. */ void -sv_mail (char *name) +sv_mail (const char *name) { /* If the time interval for checking the files has changed, then reset the mail timer. Otherwise, one of the pathname vars @@ -5794,7 +5794,7 @@ sv_mail (char *name) } void -sv_funcnest (char *name) +sv_funcnest (const char *name) { SHELL_VAR *v; intmax_t num; @@ -5810,14 +5810,14 @@ sv_funcnest (char *name) /* What to do when EXECIGNORE changes. */ void -sv_execignore (char *name) +sv_execignore (const char *name) { setup_exec_ignore (name); } /* What to do when GLOBIGNORE changes. */ void -sv_globignore (char *name) +sv_globignore (const char *name) { if (privileged_mode == 0) setup_glob_ignore (name); @@ -5825,7 +5825,7 @@ sv_globignore (char *name) #if defined (READLINE) void -sv_comp_wordbreaks (char *name) +sv_comp_wordbreaks (const char *name) { SHELL_VAR *sv; @@ -5838,14 +5838,14 @@ sv_comp_wordbreaks (char *name) If we are an interactive shell, then try to reset the terminal information in readline. */ void -sv_terminal (char *name) +sv_terminal (const char *name) { if (interactive_shell && no_line_editing == 0) rl_reset_terminal (get_string_value ("TERM")); } void -sv_hostfile (char *name) +sv_hostfile (const char *name) { SHELL_VAR *v; @@ -5861,7 +5861,7 @@ sv_hostfile (char *name) found in the initial environment) to override the terminal size reported by the kernel. */ void -sv_winsize (char *name) +sv_winsize (const char *name) { SHELL_VAR *v; intmax_t xd; @@ -5892,7 +5892,7 @@ sv_winsize (char *name) /* Update the value of HOME in the export environment so tilde expansion will work on cygwin. */ #if defined (__CYGWIN__) -sv_home (char *name) +sv_home (const char *name) { array_needs_making = 1; maybe_make_export_env (); @@ -5907,7 +5907,7 @@ sv_home (char *name) numeric, truncate the history file to hold no more than that many lines. */ void -sv_histsize (char *name) +sv_histsize (const char *name) { char *temp; intmax_t num; @@ -5946,14 +5946,14 @@ sv_histsize (char *name) /* What to do after the HISTIGNORE variable changes. */ void -sv_histignore (char *name) +sv_histignore (const char *name) { setup_history_ignore (name); } /* What to do after the HISTCONTROL variable changes. */ void -sv_history_control (char *name) +sv_history_control (const char *name) { char *temp; char *val; @@ -5984,7 +5984,7 @@ sv_history_control (char *name) #if defined (BANG_HISTORY) /* Setting/unsetting of the history expansion character. */ void -sv_histchars (char *name) +sv_histchars (const char *name) { char *temp; @@ -6009,7 +6009,7 @@ sv_histchars (char *name) #endif /* BANG_HISTORY */ void -sv_histtimefmt (char *name) +sv_histtimefmt (const char *name) { SHELL_VAR *v; @@ -6024,7 +6024,7 @@ sv_histtimefmt (char *name) #if defined (HAVE_TZSET) void -sv_tz (char *name) +sv_tz (const char *name) { SHELL_VAR *v; @@ -6046,7 +6046,7 @@ sv_tz (char *name) of times we actually ignore the EOF. The default is small, (smaller than csh, anyway). */ void -sv_ignoreeof (char *name) +sv_ignoreeof (const char *name) { SHELL_VAR *tmp_var; char *temp; @@ -6062,7 +6062,7 @@ sv_ignoreeof (char *name) } void -sv_optind (char *name) +sv_optind (const char *name) { SHELL_VAR *var; char *tt; @@ -6089,7 +6089,7 @@ sv_optind (char *name) } void -sv_opterr (char *name) +sv_opterr (const char *name) { char *tt; @@ -6098,7 +6098,7 @@ sv_opterr (char *name) } void -sv_strict_posix (char *name) +sv_strict_posix (const char *name) { SHELL_VAR *var; @@ -6113,7 +6113,7 @@ sv_strict_posix (char *name) } void -sv_locale (char *name) +sv_locale (const char *name) { char *v; int r; @@ -6265,7 +6265,7 @@ set_pipestatus_from_exit (int s) } void -sv_xtracefd (char *name) +sv_xtracefd (const char *name) { SHELL_VAR *v; char *t, *e; @@ -6301,7 +6301,7 @@ sv_xtracefd (char *name) #define MIN_COMPAT_LEVEL 31 void -sv_shcompat (char *name) +sv_shcompat (const char *name) { SHELL_VAR *v; char *val; @@ -6353,7 +6353,7 @@ compat_error: #if defined (JOB_CONTROL) void -sv_childmax (char *name) +sv_childmax (const char *name) { char *tt; int s; diff --git a/variables.h b/variables.h index 38c8720f..63779fd7 100644 --- a/variables.h +++ b/variables.h @@ -1,6 +1,6 @@ /* variables.h -- data structures for shell variables. */ -/* 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. @@ -259,7 +259,7 @@ extern void initialize_shell_variables (char **, int); extern int validate_inherited_value (SHELL_VAR *, int); -extern SHELL_VAR *set_if_not (char *, char *); +extern SHELL_VAR *set_if_not (const char *, const char *); extern void sh_set_lines_and_columns (int, int); extern void set_pwd (void); @@ -286,11 +286,11 @@ extern SHELL_VAR *find_shell_variable (const char *); extern SHELL_VAR *find_tempenv_variable (const char *); extern SHELL_VAR *find_variable_no_invisible (const char *); extern SHELL_VAR *find_variable_for_assignment (const char *); -extern char *nameref_transform_name (char *, int); +extern char *nameref_transform_name (const char *, int); extern SHELL_VAR *copy_variable (SHELL_VAR *); extern SHELL_VAR *make_local_variable (const char *, int); -extern SHELL_VAR *bind_variable (const char *, char *, int); -extern SHELL_VAR *bind_global_variable (const char *, char *, int); +extern SHELL_VAR *bind_variable (const char *, const char *, int); +extern SHELL_VAR *bind_global_variable (const char *, const char *, int); extern SHELL_VAR *bind_function (const char *, COMMAND *); extern void bind_function_def (const char *, FUNCTION_DEF *, int); @@ -316,13 +316,13 @@ extern char **add_or_supercede_exported_var (char *, int); extern char *get_variable_value (SHELL_VAR *); extern char *get_string_value (const char *); extern char *sh_get_env_value (const char *); -extern char *make_variable_value (SHELL_VAR *, char *, int); +extern char *make_variable_value (SHELL_VAR *, const char *, int); extern SHELL_VAR *bind_variable_value (SHELL_VAR *, char *, int); -extern SHELL_VAR *bind_int_variable (char *, char *, int); -extern SHELL_VAR *bind_var_to_int (char *, intmax_t, int); +extern SHELL_VAR *bind_int_variable (const char *, const char *, int); +extern SHELL_VAR *bind_var_to_int (const char *, intmax_t, int); -extern int assign_in_env (WORD_DESC *, int); +extern int assign_in_env (const WORD_DESC *, int); extern int unbind_variable (const char *); extern int check_unbind_variable (const char *); @@ -391,11 +391,11 @@ extern void print_var_value (SHELL_VAR *, int); extern void print_var_function (SHELL_VAR *); #if defined (ARRAY_VARS) -extern SHELL_VAR *make_new_array_variable (char *); -extern SHELL_VAR *make_local_array_variable (char *, int); +extern SHELL_VAR *make_new_array_variable (const char *); +extern SHELL_VAR *make_local_array_variable (const char *, int); -extern SHELL_VAR *make_new_assoc_variable (char *); -extern SHELL_VAR *make_local_assoc_variable (char *, int); +extern SHELL_VAR *make_new_assoc_variable (const char *); +extern SHELL_VAR *make_local_assoc_variable (const char *, int); extern void set_pipestatus_array (int *, int); extern ARRAY *save_pipestatus_array (void); @@ -406,7 +406,7 @@ extern void set_pipestatus_from_exit (int); /* The variable in NAME has just had its state changed. Check to see if it is one of the special ones where something special happens. */ -extern void stupidly_hack_special_variables (char *); +extern void stupidly_hack_special_variables (const char *); /* Reinitialize some special variables that have external effects upon unset when the shell reinitializes itself. */ @@ -416,47 +416,47 @@ extern int get_random_number (void); /* The `special variable' functions that get called when a particular variable is set. */ -extern void sv_ifs (char *); -extern void sv_path (char *); -extern void sv_mail (char *); -extern void sv_funcnest (char *); -extern void sv_execignore (char *); -extern void sv_globignore (char *); -extern void sv_ignoreeof (char *); -extern void sv_strict_posix (char *); -extern void sv_optind (char *); -extern void sv_opterr (char *); -extern void sv_locale (char *); -extern void sv_xtracefd (char *); -extern void sv_shcompat (char *); +extern void sv_ifs (const char *); +extern void sv_path (const char *); +extern void sv_mail (const char *); +extern void sv_funcnest (const char *); +extern void sv_execignore (const char *); +extern void sv_globignore (const char *); +extern void sv_ignoreeof (const char *); +extern void sv_strict_posix (const char *); +extern void sv_optind (const char *); +extern void sv_opterr (const char *); +extern void sv_locale (const char *); +extern void sv_xtracefd (const char *); +extern void sv_shcompat (const char *); #if defined (READLINE) -extern void sv_comp_wordbreaks (char *); -extern void sv_terminal (char *); -extern void sv_hostfile (char *); -extern void sv_winsize (char *); +extern void sv_comp_wordbreaks (const char *); +extern void sv_terminal (const char *); +extern void sv_hostfile (const char *); +extern void sv_winsize (const char *); #endif #if defined (__CYGWIN__) -extern void sv_home (char *); +extern void sv_home (const char *); #endif #if defined (HISTORY) -extern void sv_histsize (char *); -extern void sv_histignore (char *); -extern void sv_history_control (char *); +extern void sv_histsize (const char *); +extern void sv_histignore (const char *); +extern void sv_history_control (const char *); # if defined (BANG_HISTORY) -extern void sv_histchars (char *); +extern void sv_histchars (const char *); # endif -extern void sv_histtimefmt (char *); +extern void sv_histtimefmt (const char *); #endif /* HISTORY */ #if defined (HAVE_TZSET) -extern void sv_tz (char *); +extern void sv_tz (const char *); #endif #if defined (JOB_CONTROL) -extern void sv_childmax (char *); +extern void sv_childmax (const char *); #endif #endif /* !_VARIABLES_H_ */