env: Rename setenv() to env_set()

We are now using an env_ prefix for environment functions. Rename setenv()
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 05e19f8..7af9bfe 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -49,15 +49,15 @@
 /*
  * Get a value from the fdt and format it to be set in the environment
  */
-static int fdt_value_setenv(const void *nodep, int len, const char *var)
+static int fdt_value_env_set(const void *nodep, int len, const char *var)
 {
 	if (is_printable_string(nodep, len))
-		setenv(var, (void *)nodep);
+		env_set(var, (void *)nodep);
 	else if (len == 4) {
 		char buf[11];
 
 		sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep));
-		setenv(var, buf);
+		env_set(var, buf);
 	} else if (len%4 == 0 && len <= 20) {
 		/* Needed to print things like sha1 hashes. */
 		char buf[41];
@@ -66,7 +66,7 @@
 		for (i = 0; i < len; i += sizeof(unsigned int))
 			sprintf(buf + (i * 2), "%08x",
 				*(unsigned int *)(nodep + i));
-		setenv(var, buf);
+		env_set(var, buf);
 	} else {
 		printf("error: unprintable value\n");
 		return 1;
@@ -358,10 +358,12 @@
 				if (curDepth == startDepth + 1)
 					curIndex++;
 				if (subcmd[0] == 'n' && curIndex == reqIndex) {
-					const char *nodeName = fdt_get_name(
-					    working_fdt, nextNodeOffset, NULL);
+					const char *node_name;
 
-					setenv(var, (char *)nodeName);
+					node_name = fdt_get_name(working_fdt,
+								 nextNodeOffset,
+								 NULL);
+					env_set(var, node_name);
 					return 0;
 				}
 				nextNodeOffset = fdt_next_node(
@@ -382,13 +384,14 @@
 				working_fdt, nodeoffset, prop, &len);
 			if (len == 0) {
 				/* no property value */
-				setenv(var, "");
+				env_set(var, "");
 				return 0;
 			} else if (nodep && len > 0) {
 				if (subcmd[0] == 'v') {
 					int ret;
 
-					ret = fdt_value_setenv(nodep, len, var);
+					ret = fdt_value_env_set(nodep, len,
+								var);
 					if (ret != 0)
 						return ret;
 				} else if (subcmd[0] == 'a') {
@@ -396,13 +399,13 @@
 					char buf[11];
 
 					sprintf(buf, "0x%p", nodep);
-					setenv(var, buf);
+					env_set(var, buf);
 				} else if (subcmd[0] == 's') {
 					/* Get size */
 					char buf[11];
 
 					sprintf(buf, "0x%08X", len);
-					setenv(var, buf);
+					env_set(var, buf);
 				} else
 					return CMD_RET_USAGE;
 				return 0;
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 6f08f61..fbfbe7b 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -60,7 +60,7 @@
 #ifdef CONFIG_RANDOM_UUID
 		debug("%s unset. ", str);
 		gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_GUID);
-		setenv(s, uuid_str);
+		env_set(s, uuid_str);
 
 		e = getenv(s);
 		if (e) {
@@ -626,7 +626,7 @@
 		return CMD_RET_FAILURE;
 
 	if (namestr)
-		setenv(namestr, disk_guid);
+		env_set(namestr, disk_guid);
 	else
 		printf("%s\n", disk_guid);
 
diff --git a/cmd/ini.c b/cmd/ini.c
index 727fd1c..449f6e9 100644
--- a/cmd/ini.c
+++ b/cmd/ini.c
@@ -219,7 +219,7 @@
 		for (i = 0; i < strlen(value); i++)
 			value[i] = tolower(value[i]);
 #endif
-		setenv(name, value);
+		env_set(name, value);
 		printf("ini: Imported %s as %s\n", name, value);
 	}
 
diff --git a/cmd/md5sum.c b/cmd/md5sum.c
index 23bb81e..1b2352e 100644
--- a/cmd/md5sum.c
+++ b/cmd/md5sum.c
@@ -35,7 +35,7 @@
 			sprintf(str_ptr, "%02x", sum[i]);
 			str_ptr += 2;
 		}
-		setenv(dest, str_output);
+		env_set(dest, str_output);
 	}
 }
 
diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 683c48b..a243350 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -246,12 +246,12 @@
 		}
 
 		part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
-		setenv("mtddevname", part->name);
+		env_set("mtddevname", part->name);
 
 		debug("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name);
 	} else {
-		setenv("mtddevnum", NULL);
-		setenv("mtddevname", NULL);
+		env_set("mtddevnum", NULL);
+		env_set("mtddevname", NULL);
 
 		debug("=> mtddevnum NULL\n=> mtddevname NULL\n");
 	}
@@ -270,12 +270,12 @@
 		sprintf(buf, "%s%d,%d", MTD_DEV_TYPE(current_mtd_dev->id->type),
 					current_mtd_dev->id->num, current_mtd_partnum);
 
-		setenv("partition", buf);
+		env_set("partition", buf);
 		strncpy(last_partition, buf, 16);
 
 		debug("=> partition %s\n", buf);
 	} else {
-		setenv("partition", NULL);
+		env_set("partition", NULL);
 		last_partition[0] = '\0';
 
 		debug("=> partition NULL\n");
@@ -1213,9 +1213,9 @@
 	ret = generate_mtdparts(buf, buflen);
 
 	if ((buf[0] != '\0') && (ret == 0))
-		setenv("mtdparts", buf);
+		env_set("mtdparts", buf);
 	else
-		setenv("mtdparts", NULL);
+		env_set("mtdparts", NULL);
 
 	return ret;
 }
@@ -1764,7 +1764,7 @@
 		if (mtdids_default) {
 			debug("mtdids variable not defined, using default\n");
 			ids = mtdids_default;
-			setenv("mtdids", (char *)ids);
+			env_set("mtdids", (char *)ids);
 		} else {
 			printf("mtdids not defined, no default present\n");
 			return 1;
@@ -1780,7 +1780,7 @@
 	if (!parts) {
 		if (mtdparts_default && use_defaults) {
 			parts = mtdparts_default;
-			if (setenv("mtdparts", (char *)parts) == 0)
+			if (env_set("mtdparts", (char *)parts) == 0)
 				use_defaults = 0;
 		} else
 			printf("mtdparts variable not set, see 'help mtdparts'\n");
@@ -1956,9 +1956,9 @@
 {
 	if (argc == 2) {
 		if (strcmp(argv[1], "default") == 0) {
-			setenv("mtdids", NULL);
-			setenv("mtdparts", NULL);
-			setenv("partition", NULL);
+			env_set("mtdids", NULL);
+			env_set("mtdparts", NULL);
+			env_set("partition", NULL);
 			use_defaults = 1;
 
 			mtdparts_init();
@@ -1967,7 +1967,7 @@
 			/* this may be the first run, initialize lists if needed */
 			mtdparts_init();
 
-			setenv("mtdparts", NULL);
+			env_set("mtdparts", NULL);
 
 			/* mtd_devices_init() calls current_save() */
 			return mtd_devices_init();
diff --git a/cmd/net.c b/cmd/net.c
index 5e91d3a..ae8eeb7 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -116,23 +116,23 @@
 
 	if (net_gateway.s_addr) {
 		ip_to_string(net_gateway, tmp);
-		setenv("gatewayip", tmp);
+		env_set("gatewayip", tmp);
 	}
 
 	if (net_netmask.s_addr) {
 		ip_to_string(net_netmask, tmp);
-		setenv("netmask", tmp);
+		env_set("netmask", tmp);
 	}
 
 	if (net_hostname[0])
-		setenv("hostname", net_hostname);
+		env_set("hostname", net_hostname);
 
 	if (net_root_path[0])
-		setenv("rootpath", net_root_path);
+		env_set("rootpath", net_root_path);
 
 	if (net_ip.s_addr) {
 		ip_to_string(net_ip, tmp);
-		setenv("ipaddr", tmp);
+		env_set("ipaddr", tmp);
 	}
 #if !defined(CONFIG_BOOTP_SERVERIP)
 	/*
@@ -141,32 +141,32 @@
 	 */
 	if (net_server_ip.s_addr) {
 		ip_to_string(net_server_ip, tmp);
-		setenv("serverip", tmp);
+		env_set("serverip", tmp);
 	}
 #endif
 	if (net_dns_server.s_addr) {
 		ip_to_string(net_dns_server, tmp);
-		setenv("dnsip", tmp);
+		env_set("dnsip", tmp);
 	}
 #if defined(CONFIG_BOOTP_DNS2)
 	if (net_dns_server2.s_addr) {
 		ip_to_string(net_dns_server2, tmp);
-		setenv("dnsip2", tmp);
+		env_set("dnsip2", tmp);
 	}
 #endif
 	if (net_nis_domain[0])
-		setenv("domain", net_nis_domain);
+		env_set("domain", net_nis_domain);
 
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
 	if (net_ntp_time_offset) {
 		sprintf(tmp, "%d", net_ntp_time_offset);
-		setenv("timeoffset", tmp);
+		env_set("timeoffset", tmp);
 	}
 #endif
 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
 	if (net_ntp_server.s_addr) {
 		ip_to_string(net_ntp_server, tmp);
-		setenv("ntpserverip", tmp);
+		env_set("ntpserverip", tmp);
 	}
 #endif
 }
@@ -291,14 +291,14 @@
 		printf("CDP offered appliance VLAN %d\n",
 		       ntohs(cdp_appliance_vlan));
 		vlan_to_string(cdp_appliance_vlan, tmp);
-		setenv("vlan", tmp);
+		env_set("vlan", tmp);
 		net_our_vlan = cdp_appliance_vlan;
 	}
 
 	if (cdp_native_vlan != htons(-1)) {
 		printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan));
 		vlan_to_string(cdp_native_vlan, tmp);
-		setenv("nvlan", tmp);
+		env_set("nvlan", tmp);
 		net_native_vlan = cdp_native_vlan;
 	}
 }
@@ -423,14 +423,14 @@
 
 	net_gateway.s_addr = 0;
 	ip_to_string(net_gateway, tmp);
-	setenv("gatewayip", tmp);
+	env_set("gatewayip", tmp);
 
 	ip_to_string(net_netmask, tmp);
-	setenv("netmask", tmp);
+	env_set("netmask", tmp);
 
 	ip_to_string(net_ip, tmp);
-	setenv("ipaddr", tmp);
-	setenv("llipaddr", tmp); /* store this for next time */
+	env_set("ipaddr", tmp);
+	env_set("llipaddr", tmp); /* store this for next time */
 
 	return CMD_RET_SUCCESS;
 }
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 4431ef6..1b1e966 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -283,7 +283,7 @@
 	return 0;
 }
 
-int setenv(const char *varname, const char *varvalue)
+int env_set(const char *varname, const char *varvalue)
 {
 	const char * const argv[4] = { "setenv", varname, varvalue, NULL };
 
@@ -309,7 +309,7 @@
 	/* TODO: this should be unsigned */
 	char *str = simple_itoa(value);
 
-	return setenv(varname, str);
+	return env_set(varname, str);
 }
 
 /**
@@ -324,7 +324,7 @@
 	char str[17];
 
 	sprintf(str, "%lx", value);
-	return setenv(varname, str);
+	return env_set(varname, str);
 }
 
 ulong getenv_hex(const char *varname, ulong default_val)
@@ -931,7 +931,7 @@
 			return 1;
 		}
 		sprintf(buf, "%zX", (size_t)len);
-		setenv("filesize", buf);
+		env_set("filesize", buf);
 
 		return 0;
 	}
diff --git a/cmd/part.c b/cmd/part.c
index 8ba0598..746bf40 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -38,7 +38,7 @@
 		return 1;
 
 	if (argc > 2)
-		setenv(argv[2], info.uuid);
+		env_set(argv[2], info.uuid);
 	else
 		printf("%s\n", info.uuid);
 
@@ -99,7 +99,7 @@
 			sprintf(t, "%s%x", str[0] ? " " : "", p);
 			strcat(str, t);
 		}
-		setenv(var, str);
+		env_set(var, str);
 		return 0;
 	}
 
@@ -135,7 +135,7 @@
 	snprintf(buf, sizeof(buf), LBAF, info.start);
 
 	if (argc > 3)
-		setenv(argv[3], buf);
+		env_set(argv[3], buf);
 	else
 		printf("%s\n", buf);
 
@@ -169,7 +169,7 @@
 	snprintf(buf, sizeof(buf), LBAF, info.size);
 
 	if (argc > 3)
-		setenv(argv[3], buf);
+		env_set(argv[3], buf);
 	else
 		printf("%s\n", buf);
 
diff --git a/cmd/pxe.c b/cmd/pxe.c
index 0a07f14..357b969 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -591,7 +591,7 @@
 		char bootargs[CONFIG_SYS_CBSIZE];
 
 		cli_simple_process_macros(label->append, bootargs);
-		setenv("bootargs", bootargs);
+		env_set("bootargs", bootargs);
 	}
 
 	debug("running: %s\n", localcmd);
@@ -695,7 +695,7 @@
 		strcat(bootargs, mac_str);
 
 		cli_simple_process_macros(bootargs, finalbootargs);
-		setenv("bootargs", finalbootargs);
+		env_set("bootargs", finalbootargs);
 		printf("append: %s\n", finalbootargs);
 	}
 
@@ -1674,7 +1674,7 @@
 		filename = getenv("bootfile");
 	else {
 		filename = argv[5];
-		setenv("bootfile", filename);
+		env_set("bootfile", filename);
 	}
 
 	if (strstr(argv[3], "ext2"))
diff --git a/cmd/qfw.c b/cmd/qfw.c
index 12436ec..9b12ab4 100644
--- a/cmd/qfw.c
+++ b/cmd/qfw.c
@@ -55,7 +55,7 @@
 		 * when invoking qemu), do not update bootargs
 		 */
 		if (*data_addr != '\0') {
-			if (setenv("bootargs", data_addr) < 0)
+			if (env_set("bootargs", data_addr) < 0)
 				printf("warning: unable to change bootargs\n");
 		}
 	}
diff --git a/cmd/setexpr.c b/cmd/setexpr.c
index e7194fc..e9058c4 100644
--- a/cmd/setexpr.c
+++ b/cmd/setexpr.c
@@ -282,11 +282,11 @@
 		if (!global)
 			break;
 	}
-	debug("## FINAL (now setenv()) :  %s\n", data);
+	debug("## FINAL (now env_set()) :  %s\n", data);
 
 	printf("%s=%s\n", name, data);
 
-	return setenv(name, data);
+	return env_set(name, data);
 }
 #endif