From patchwork Fri Jul 29 12:42:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wolfgang Denk X-Patchwork-Id: 107388 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E3C9BB6F62 for ; Fri, 29 Jul 2011 22:42:39 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 37D5828084; Fri, 29 Jul 2011 14:42:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5ar+rYqDaHQd; Fri, 29 Jul 2011 14:42:35 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3546028089; Fri, 29 Jul 2011 14:42:32 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9890928089 for ; Fri, 29 Jul 2011 14:42:27 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GiHCJNs5npqF for ; Fri, 29 Jul 2011 14:42:26 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by theia.denx.de (Postfix) with ESMTP id 5AD7428084 for ; Fri, 29 Jul 2011 14:42:24 +0200 (CEST) Received: from frontend1.mail.m-online.net (unknown [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 81C6E1C1DA1C; Fri, 29 Jul 2011 14:42:24 +0200 (CEST) X-Auth-Info: AEVtXra0uYFhbVlxp21UYt2UeSyRQDUA2E0CD5D9iUw= Received: from diddl.denx.de (host-80-81-18-216.customer.m-online.net [80.81.18.216]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA id 70B8D1C0014D; Fri, 29 Jul 2011 14:42:24 +0200 (CEST) Received: from gemini.denx.de (unknown [10.0.0.2]) by diddl.denx.de (Postfix) with ESMTP id 49A44C913109; Fri, 29 Jul 2011 14:42:24 +0200 (CEST) Received: by gemini.denx.de (Postfix, from userid 500) id 2AF9C1FB4B0; Fri, 29 Jul 2011 14:42:24 +0200 (CEST) From: Wolfgang Denk To: u-boot@lists.denx.de Date: Fri, 29 Jul 2011 14:42:18 +0200 Message-Id: <1311943338-23147-1-git-send-email-wd@denx.de> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1311869959-6085-1-git-send-email-andreas.devel@googlemail.com> References: <1311869959-6085-1-git-send-email-andreas.devel@googlemail.com> MIME-Version: 1.0 Subject: [U-Boot] =?iso8859-1?q?=5BPATCH=5D_Constify_getenv=28=29=2C_seten?= =?iso8859-1?q?v=28=29_and_hash_code_functions?= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This is needed to get rid of build warnings like main.c:311: warning: passing argument 2 of 'setenv' discards qualifiers from pointer target type which result from commit 09c2e90 "unify version_string". Signed-off-by: Wolfgang Denk Cc: Andreas Bießmann --- common/cmd_nvedit.c | 13 +++++++------ include/common.h | 8 ++++---- include/exports.h | 4 ++-- include/search.h | 2 +- lib/hashtable.c | 6 +++--- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index b2c88ba..e8b116d 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -367,13 +367,14 @@ int _do_env_set (int flag, int argc, char * const argv[]) return 0; } -int setenv(char *varname, char *varvalue) +int setenv(const char *varname, const char *varvalue) { - char * const argv[4] = { "setenv", varname, varvalue, NULL }; + const char * const argv[4] = { "setenv", varname, varvalue, NULL }; + if ((varvalue == NULL) || (varvalue[0] == '\0')) - return _do_env_set(0, 2, argv); + return _do_env_set(0, 2, (char * const *)argv); else - return _do_env_set(0, 3, argv); + return _do_env_set(0, 3, (char * const *)argv); } int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -482,7 +483,7 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * return address of storage for that variable, * or NULL if not found */ -char *getenv(char *name) +char *getenv(const char *name) { if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */ ENTRY e, *ep; @@ -507,7 +508,7 @@ char *getenv(char *name) /* * Look up variable from environment for restricted C runtime env. */ -int getenv_f(char *name, char *buf, unsigned len) +int getenv_f(const char *name, char *buf, unsigned len) { int i, nxt; diff --git a/include/common.h b/include/common.h index 1572791..b994e70 100644 --- a/include/common.h +++ b/include/common.h @@ -262,13 +262,13 @@ void doc_probe(unsigned long physadr); int env_init (void); void env_relocate (void); int envmatch (uchar *, int); -char *getenv (char *); -int getenv_f (char *name, char *buf, unsigned len); +char *getenv (const char *); +int getenv_f (const char *name, char *buf, unsigned len); int saveenv (void); #ifdef CONFIG_PPC /* ARM version to be fixed! */ -int inline setenv (char *, char *); +int inline setenv (const char *, const char *); #else -int setenv (char *, char *); +int setenv (const char *, const char *); #endif /* CONFIG_PPC */ #ifdef CONFIG_ARM # include diff --git a/include/exports.h b/include/exports.h index e14d727..9492566 100644 --- a/include/exports.h +++ b/include/exports.h @@ -21,8 +21,8 @@ unsigned long get_timer(unsigned long); int vprintf(const char *, va_list); unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base); int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); -char *getenv (char *name); -int setenv (char *varname, char *varvalue); +char *getenv (const char *name); +int setenv (const char *varname, const char *varvalue); long simple_strtol(const char *cp,char **endp,unsigned int base); int strcmp(const char * cs,const char * ct); int ustrtoul(const char *cp, char **endp, unsigned int base); diff --git a/include/search.h b/include/search.h index c827d4d..b4edd43 100644 --- a/include/search.h +++ b/include/search.h @@ -39,7 +39,7 @@ typedef enum { } ACTION; typedef struct entry { - char *key; + const char *key; char *data; } ENTRY; diff --git a/lib/hashtable.c b/lib/hashtable.c index 19d5b15..026dbca 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -155,7 +155,7 @@ void hdestroy_r(struct hsearch_data *htab) if (htab->table[i].used > 0) { ENTRY *ep = &htab->table[i].entry; - free(ep->key); + free((void *)ep->key); free(ep->data); } } @@ -416,7 +416,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab) /* free used ENTRY */ debug("hdelete: DELETING key \"%s\"\n", key); - free(ep->key); + free((void *)ep->key); free(ep->data); htab->table[idx].used = -1; @@ -564,7 +564,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, * export sorted list of result data */ for (i = 0, p = res; i < n; ++i) { - char *s; + const char *s; s = list[i]->key; while (*s)