lash: -Wwrite-strings fixes
This commit is contained in:
parent
bb81c5831a
commit
71d8abf30c
46
shell/lash.c
46
shell/lash.c
@ -90,8 +90,8 @@ struct job {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct built_in_command {
|
struct built_in_command {
|
||||||
char *cmd; /* name */
|
const char *cmd; /* name */
|
||||||
char *descr; /* description */
|
const char *descr; /* description */
|
||||||
int (*function) (struct child_prog *); /* function ptr */
|
int (*function) (struct child_prog *); /* function ptr */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ static int busy_loop(FILE * input);
|
|||||||
/* Table of built-in functions (these are non-forking builtins, meaning they
|
/* Table of built-in functions (these are non-forking builtins, meaning they
|
||||||
* can change global variables in the parent shell process but they will not
|
* can change global variables in the parent shell process but they will not
|
||||||
* work with pipes and redirects; 'unset foo | whatever' will not work) */
|
* work with pipes and redirects; 'unset foo | whatever' will not work) */
|
||||||
static struct built_in_command bltins[] = {
|
static const struct built_in_command bltins[] = {
|
||||||
{"bg", "Resume a job in the background", builtin_fg_bg},
|
{"bg", "Resume a job in the background", builtin_fg_bg},
|
||||||
{"cd", "Change working directory", builtin_cd},
|
{"cd", "Change working directory", builtin_cd},
|
||||||
{"exec", "Exec command, replacing this shell with the exec'd process", builtin_exec},
|
{"exec", "Exec command, replacing this shell with the exec'd process", builtin_exec},
|
||||||
@ -160,8 +160,8 @@ static int last_return_code;
|
|||||||
static int last_bg_pid;
|
static int last_bg_pid;
|
||||||
static unsigned int last_jobid;
|
static unsigned int last_jobid;
|
||||||
static int shell_terminal;
|
static int shell_terminal;
|
||||||
static char *PS1;
|
static const char *PS1;
|
||||||
static char *PS2 = "> ";
|
static const char *PS2 = "> ";
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_SHELL
|
#ifdef DEBUG_SHELL
|
||||||
@ -303,17 +303,17 @@ static int builtin_fg_bg(struct child_prog *child)
|
|||||||
/* built-in 'help' handler */
|
/* built-in 'help' handler */
|
||||||
static int builtin_help(struct child_prog ATTRIBUTE_UNUSED *dummy)
|
static int builtin_help(struct child_prog ATTRIBUTE_UNUSED *dummy)
|
||||||
{
|
{
|
||||||
struct built_in_command *x;
|
const struct built_in_command *x;
|
||||||
|
|
||||||
printf("\nBuilt-in commands:\n"
|
printf("\nBuilt-in commands:\n"
|
||||||
"-------------------\n");
|
"-------------------\n");
|
||||||
for (x = bltins; x->cmd; x++) {
|
for (x = bltins; x->cmd; x++) {
|
||||||
if (x->descr==NULL)
|
if (x->descr == NULL)
|
||||||
continue;
|
continue;
|
||||||
printf("%s\t%s\n", x->cmd, x->descr);
|
printf("%s\t%s\n", x->cmd, x->descr);
|
||||||
}
|
}
|
||||||
for (x = bltins_forking; x->cmd; x++) {
|
for (x = bltins_forking; x->cmd; x++) {
|
||||||
if (x->descr==NULL)
|
if (x->descr == NULL)
|
||||||
continue;
|
continue;
|
||||||
printf("%s\t%s\n", x->cmd, x->descr);
|
printf("%s\t%s\n", x->cmd, x->descr);
|
||||||
}
|
}
|
||||||
@ -325,7 +325,7 @@ static int builtin_help(struct child_prog ATTRIBUTE_UNUSED *dummy)
|
|||||||
static int builtin_jobs(struct child_prog *child)
|
static int builtin_jobs(struct child_prog *child)
|
||||||
{
|
{
|
||||||
struct job *job;
|
struct job *job;
|
||||||
char *status_string;
|
const char *status_string;
|
||||||
|
|
||||||
for (job = child->family->job_list->head; job; job = job->next) {
|
for (job = child->family->job_list->head; job; job = job->next) {
|
||||||
if (job->running_progs == job->stopped_progs)
|
if (job->running_progs == job->stopped_progs)
|
||||||
@ -622,20 +622,22 @@ static inline void cmdedit_set_initial_prompt(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void setup_prompt_string(char **prompt_str)
|
static inline const char* setup_prompt_string(void)
|
||||||
{
|
{
|
||||||
#if !ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
#if !ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
||||||
/* Set up the prompt */
|
/* Set up the prompt */
|
||||||
if (shell_context == 0) {
|
if (shell_context == 0) {
|
||||||
free(PS1);
|
char *ns;
|
||||||
PS1=xmalloc(strlen(cwd)+4);
|
free((char*)PS1);
|
||||||
sprintf(PS1, "%s %c ", cwd, ( geteuid() != 0 ) ? '$': '#');
|
ns = xmalloc(strlen(cwd)+4);
|
||||||
*prompt_str = PS1;
|
sprintf(ns, "%s %c ", cwd, (geteuid() != 0) ? '$': '#');
|
||||||
|
PS1 = ns;
|
||||||
|
return ns;
|
||||||
} else {
|
} else {
|
||||||
*prompt_str = PS2;
|
return PS2;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
*prompt_str = (shell_context==0)? PS1 : PS2;
|
return (shell_context==0)? PS1 : PS2;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -645,7 +647,7 @@ static line_input_t *line_input_state;
|
|||||||
|
|
||||||
static int get_command(FILE * source, char *command)
|
static int get_command(FILE * source, char *command)
|
||||||
{
|
{
|
||||||
char *prompt_str;
|
const char *prompt_str;
|
||||||
|
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
if (local_pending_command) {
|
if (local_pending_command) {
|
||||||
@ -659,7 +661,7 @@ static int get_command(FILE * source, char *command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (source == stdin) {
|
if (source == stdin) {
|
||||||
setup_prompt_string(&prompt_str);
|
prompt_str = setup_prompt_string();
|
||||||
|
|
||||||
#if ENABLE_FEATURE_EDITING
|
#if ENABLE_FEATURE_EDITING
|
||||||
/*
|
/*
|
||||||
@ -797,7 +799,7 @@ static int expand_arguments(char *command)
|
|||||||
break;
|
break;
|
||||||
case '!':
|
case '!':
|
||||||
if (last_bg_pid==-1)
|
if (last_bg_pid==-1)
|
||||||
*(var)='\0';
|
*var = '\0';
|
||||||
else
|
else
|
||||||
var = itoa(last_bg_pid);
|
var = itoa(last_bg_pid);
|
||||||
break;
|
break;
|
||||||
@ -853,7 +855,7 @@ static int expand_arguments(char *command)
|
|||||||
}
|
}
|
||||||
if (var == NULL) {
|
if (var == NULL) {
|
||||||
/* Seems we got an un-expandable variable. So delete it. */
|
/* Seems we got an un-expandable variable. So delete it. */
|
||||||
var = "";
|
var = (char*)"";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int subst_len = strlen(var);
|
int subst_len = strlen(var);
|
||||||
@ -1128,7 +1130,7 @@ empty_command_in_pipe:
|
|||||||
*/
|
*/
|
||||||
static int pseudo_exec(struct child_prog *child)
|
static int pseudo_exec(struct child_prog *child)
|
||||||
{
|
{
|
||||||
struct built_in_command *x;
|
const struct built_in_command *x;
|
||||||
|
|
||||||
/* Check if the command matches any of the non-forking builtins.
|
/* Check if the command matches any of the non-forking builtins.
|
||||||
* Depending on context, this might be redundant. But it's
|
* Depending on context, this might be redundant. But it's
|
||||||
@ -1227,7 +1229,7 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2])
|
|||||||
int i;
|
int i;
|
||||||
int nextin, nextout;
|
int nextin, nextout;
|
||||||
int pipefds[2]; /* pipefd[0] is for reading */
|
int pipefds[2]; /* pipefd[0] is for reading */
|
||||||
struct built_in_command *x;
|
const struct built_in_command *x;
|
||||||
struct child_prog *child;
|
struct child_prog *child;
|
||||||
|
|
||||||
nextin = 0, nextout = 1;
|
nextin = 0, nextout = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user