svn commit: trunk/busybox/shell

vda at busybox.net vda at busybox.net
Tue Jan 30 22:44:07 UTC 2007


Author: vda
Date: 2007-01-30 14:44:07 -0800 (Tue, 30 Jan 2007)
New Revision: 17683

Log:
lash: -Wwrite-strings fixes


Modified:
   trunk/busybox/shell/lash.c


Changeset:
Modified: trunk/busybox/shell/lash.c
===================================================================
--- trunk/busybox/shell/lash.c	2007-01-30 22:32:09 UTC (rev 17682)
+++ trunk/busybox/shell/lash.c	2007-01-30 22:44:07 UTC (rev 17683)
@@ -90,8 +90,8 @@
 };
 
 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 @@
 /* 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_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 @@
 /* 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_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 @@
 #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 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 @@
 	}
 
 	if (source == stdin) {
-		setup_prompt_string(&prompt_str);
+		prompt_str = setup_prompt_string();
 
 #if ENABLE_FEATURE_EDITING
 		/*
@@ -797,7 +799,7 @@
 				break;
 			case '!':
 				if (last_bg_pid==-1)
-					*(var)='\0';
+					*var = '\0';
 				else
 					var = itoa(last_bg_pid);
 				break;
@@ -853,7 +855,7 @@
 		}
 		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 @@
  */
 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 @@
 	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;




More information about the busybox-cvs mailing list