From: Denis Vlasenko Date: Tue, 30 Jan 2007 22:44:07 +0000 (-0000) Subject: lash: -Wwrite-strings fixes X-Git-Tag: 1_5_1~236 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=71d8abf30cee76141fbb86f5e80f97de284041a6;p=oweals%2Fbusybox.git lash: -Wwrite-strings fixes --- diff --git a/shell/lash.c b/shell/lash.c index 90bd16885..51ad3cc06 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -90,8 +90,8 @@ struct job { }; struct built_in_command { - char *cmd; /* name */ - char *descr; /* description */ + const char *cmd; /* name */ + const char *descr; /* description */ 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 * can change global variables in the parent shell process but they will not * 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}, {"cd", "Change working directory", builtin_cd}, {"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 unsigned int last_jobid; static int shell_terminal; -static char *PS1; -static char *PS2 = "> "; +static const char *PS1; +static const char *PS2 = "> "; #ifdef DEBUG_SHELL @@ -303,17 +303,17 @@ static int builtin_fg_bg(struct child_prog *child) /* built-in 'help' handler */ 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" "-------------------\n"); for (x = bltins; x->cmd; x++) { - if (x->descr==NULL) + if (x->descr == NULL) continue; printf("%s\t%s\n", x->cmd, x->descr); } for (x = bltins_forking; x->cmd; x++) { - if (x->descr==NULL) + if (x->descr == NULL) continue; 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) { struct job *job; - char *status_string; + const char *status_string; for (job = child->family->job_list->head; job; job = job->next) { if (job->running_progs == job->stopped_progs) @@ -622,20 +622,22 @@ static inline void cmdedit_set_initial_prompt(void) #endif } -static inline void setup_prompt_string(char **prompt_str) +static inline const char* setup_prompt_string(void) { #if !ENABLE_FEATURE_EDITING_FANCY_PROMPT /* Set up the prompt */ if (shell_context == 0) { - free(PS1); - PS1=xmalloc(strlen(cwd)+4); - sprintf(PS1, "%s %c ", cwd, ( geteuid() != 0 ) ? '$': '#'); - *prompt_str = PS1; + char *ns; + free((char*)PS1); + ns = xmalloc(strlen(cwd)+4); + sprintf(ns, "%s %c ", cwd, (geteuid() != 0) ? '$': '#'); + PS1 = ns; + return ns; } else { - *prompt_str = PS2; + return PS2; } #else - *prompt_str = (shell_context==0)? PS1 : PS2; + return (shell_context==0)? PS1 : PS2; #endif } @@ -645,7 +647,7 @@ static line_input_t *line_input_state; static int get_command(FILE * source, char *command) { - char *prompt_str; + const char *prompt_str; if (source == NULL) { if (local_pending_command) { @@ -659,7 +661,7 @@ static int get_command(FILE * source, char *command) } if (source == stdin) { - setup_prompt_string(&prompt_str); + prompt_str = setup_prompt_string(); #if ENABLE_FEATURE_EDITING /* @@ -797,7 +799,7 @@ static int expand_arguments(char *command) break; case '!': if (last_bg_pid==-1) - *(var)='\0'; + *var = '\0'; else var = itoa(last_bg_pid); break; @@ -853,7 +855,7 @@ static int expand_arguments(char *command) } if (var == NULL) { /* Seems we got an un-expandable variable. So delete it. */ - var = ""; + var = (char*)""; } { int subst_len = strlen(var); @@ -1128,7 +1130,7 @@ empty_command_in_pipe: */ 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. * 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 nextin, nextout; int pipefds[2]; /* pipefd[0] is for reading */ - struct built_in_command *x; + const struct built_in_command *x; struct child_prog *child; nextin = 0, nextout = 1;