wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2010 |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 6 | * Andreas Heppel <aheppel@sysgo.de> |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 7 | * |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
| 29 | #include <environment.h> |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 30 | #include <linux/stddef.h> |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 31 | #include <search.h> |
| 32 | #include <errno.h> |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 33 | #include <malloc.h> |
| 34 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 37 | /************************************************************************ |
| 38 | * Default settings to be used when no valid environment is found |
| 39 | */ |
| 40 | #define XMK_STR(x) #x |
| 41 | #define MK_STR(x) XMK_STR(x) |
| 42 | |
Mike Frysinger | 018f0c8 | 2011-04-23 23:43:21 +0000 | [diff] [blame] | 43 | const uchar default_environment[] = { |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 44 | #ifdef CONFIG_BOOTARGS |
| 45 | "bootargs=" CONFIG_BOOTARGS "\0" |
| 46 | #endif |
| 47 | #ifdef CONFIG_BOOTCOMMAND |
| 48 | "bootcmd=" CONFIG_BOOTCOMMAND "\0" |
| 49 | #endif |
| 50 | #ifdef CONFIG_RAMBOOTCOMMAND |
| 51 | "ramboot=" CONFIG_RAMBOOTCOMMAND "\0" |
| 52 | #endif |
| 53 | #ifdef CONFIG_NFSBOOTCOMMAND |
| 54 | "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0" |
| 55 | #endif |
| 56 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
| 57 | "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0" |
| 58 | #endif |
| 59 | #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0) |
| 60 | "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0" |
| 61 | #endif |
| 62 | #ifdef CONFIG_LOADS_ECHO |
| 63 | "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0" |
| 64 | #endif |
| 65 | #ifdef CONFIG_ETHADDR |
| 66 | "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0" |
| 67 | #endif |
| 68 | #ifdef CONFIG_ETH1ADDR |
| 69 | "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0" |
| 70 | #endif |
| 71 | #ifdef CONFIG_ETH2ADDR |
| 72 | "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0" |
| 73 | #endif |
wdenk | cd91445 | 2004-05-29 16:53:29 +0000 | [diff] [blame] | 74 | #ifdef CONFIG_ETH3ADDR |
| 75 | "eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0" |
| 76 | #endif |
richardretanubun | e5167f1 | 2008-09-29 18:28:23 -0400 | [diff] [blame] | 77 | #ifdef CONFIG_ETH4ADDR |
| 78 | "eth4addr=" MK_STR(CONFIG_ETH4ADDR) "\0" |
| 79 | #endif |
| 80 | #ifdef CONFIG_ETH5ADDR |
| 81 | "eth5addr=" MK_STR(CONFIG_ETH5ADDR) "\0" |
| 82 | #endif |
Benoît Thébaudeau | 8cdea94 | 2012-08-10 07:45:31 +0000 | [diff] [blame] | 83 | #ifdef CONFIG_ETHPRIME |
| 84 | "ethprime=" CONFIG_ETHPRIME "\0" |
| 85 | #endif |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 86 | #ifdef CONFIG_IPADDR |
| 87 | "ipaddr=" MK_STR(CONFIG_IPADDR) "\0" |
| 88 | #endif |
| 89 | #ifdef CONFIG_SERVERIP |
| 90 | "serverip=" MK_STR(CONFIG_SERVERIP) "\0" |
| 91 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | #ifdef CONFIG_SYS_AUTOLOAD |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 93 | "autoload=" CONFIG_SYS_AUTOLOAD "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 94 | #endif |
| 95 | #ifdef CONFIG_PREBOOT |
| 96 | "preboot=" CONFIG_PREBOOT "\0" |
| 97 | #endif |
| 98 | #ifdef CONFIG_ROOTPATH |
Joe Hershberger | 257ff78 | 2011-10-13 13:03:47 +0000 | [diff] [blame] | 99 | "rootpath=" CONFIG_ROOTPATH "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 100 | #endif |
| 101 | #ifdef CONFIG_GATEWAYIP |
| 102 | "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0" |
| 103 | #endif |
| 104 | #ifdef CONFIG_NETMASK |
| 105 | "netmask=" MK_STR(CONFIG_NETMASK) "\0" |
| 106 | #endif |
| 107 | #ifdef CONFIG_HOSTNAME |
| 108 | "hostname=" MK_STR(CONFIG_HOSTNAME) "\0" |
| 109 | #endif |
| 110 | #ifdef CONFIG_BOOTFILE |
Joe Hershberger | e4da248 | 2011-10-13 13:03:48 +0000 | [diff] [blame] | 111 | "bootfile=" CONFIG_BOOTFILE "\0" |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 112 | #endif |
| 113 | #ifdef CONFIG_LOADADDR |
| 114 | "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0" |
| 115 | #endif |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 116 | #ifdef CONFIG_CLOCKS_IN_MHZ |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 117 | "clocks_in_mhz=1\0" |
| 118 | #endif |
stroese | f5dd410 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 119 | #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0) |
| 120 | "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0" |
| 121 | #endif |
Stephen Warren | 1465d5f | 2012-05-22 09:21:54 +0000 | [diff] [blame] | 122 | #ifdef CONFIG_ENV_VARS_UBOOT_CONFIG |
| 123 | "arch=" CONFIG_SYS_ARCH "\0" |
| 124 | "cpu=" CONFIG_SYS_CPU "\0" |
| 125 | "board=" CONFIG_SYS_BOARD "\0" |
| 126 | #ifdef CONFIG_SYS_VENDOR |
| 127 | "vendor=" CONFIG_SYS_VENDOR "\0" |
| 128 | #endif |
| 129 | #ifdef CONFIG_SYS_SOC |
| 130 | "soc=" CONFIG_SYS_SOC "\0" |
| 131 | #endif |
| 132 | #endif |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 133 | #ifdef CONFIG_EXTRA_ENV_SETTINGS |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 134 | CONFIG_EXTRA_ENV_SETTINGS |
| 135 | #endif |
| 136 | "\0" |
| 137 | }; |
| 138 | |
Gerlando Falauto | d392595 | 2012-08-24 00:11:39 +0000 | [diff] [blame] | 139 | struct hsearch_data env_htab = { |
| 140 | .apply = env_check_apply, |
| 141 | }; |
Mike Frysinger | 92d7a99 | 2010-12-08 06:26:04 -0500 | [diff] [blame] | 142 | |
Igor Grinberg | 76c02dc | 2011-12-26 03:33:10 +0000 | [diff] [blame] | 143 | static uchar __env_get_char_spec(int index) |
| 144 | { |
| 145 | return *((uchar *)(gd->env_addr + index)); |
| 146 | } |
| 147 | uchar env_get_char_spec(int) |
| 148 | __attribute__((weak, alias("__env_get_char_spec"))); |
| 149 | |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 150 | static uchar env_get_char_init(int index) |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 151 | { |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 152 | /* if crc was bad, use the default environment */ |
| 153 | if (gd->env_valid) |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 154 | return env_get_char_spec(index); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 155 | else |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 156 | return default_environment[index]; |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 159 | uchar env_get_char_memory(int index) |
wdenk | bb444c9 | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 160 | { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 161 | return *env_get_addr(index); |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 164 | uchar env_get_char(int index) |
Joakim Tjernlund | 304b359 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 165 | { |
Joakim Tjernlund | 304b359 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 166 | /* if relocated to RAM */ |
| 167 | if (gd->flags & GD_FLG_RELOC) |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 168 | return env_get_char_memory(index); |
Joakim Tjernlund | 304b359 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 169 | else |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 170 | return env_get_char_init(index); |
Joakim Tjernlund | 304b359 | 2008-07-06 12:30:09 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 173 | const uchar *env_get_addr(int index) |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 174 | { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 175 | if (gd->env_valid) |
| 176 | return (uchar *)(gd->env_addr + index); |
| 177 | else |
| 178 | return &default_environment[index]; |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 181 | void set_default_env(const char *s) |
Harald Welte | 72eb50a | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 182 | { |
Gerlando Falauto | fe9f49d | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 183 | /* |
| 184 | * By default, do not apply changes as they will eventually |
| 185 | * be applied by someone else |
| 186 | */ |
| 187 | int do_apply = 0; |
Harald Welte | 72eb50a | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 188 | if (sizeof(default_environment) > ENV_SIZE) { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 189 | puts("*** Error - default environment is too large\n\n"); |
Harald Welte | 72eb50a | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 193 | if (s) { |
| 194 | if (*s == '!') { |
| 195 | printf("*** Warning - %s, " |
| 196 | "using default environment\n\n", |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 197 | s + 1); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 198 | } else { |
Gerlando Falauto | fe9f49d | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 199 | /* |
| 200 | * This set_to_default was explicitly asked for |
| 201 | * by the user, as opposed to being a recovery |
| 202 | * mechanism. Therefore we check every single |
| 203 | * variable and apply changes to the system |
| 204 | * right away (e.g. baudrate, console). |
| 205 | */ |
| 206 | do_apply = 1; |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 207 | puts(s); |
| 208 | } |
| 209 | } else { |
| 210 | puts("Using default environment\n\n"); |
| 211 | } |
| 212 | |
Mike Frysinger | 92d7a99 | 2010-12-08 06:26:04 -0500 | [diff] [blame] | 213 | if (himport_r(&env_htab, (char *)default_environment, |
Gerlando Falauto | 9b0e1ff | 2012-08-24 00:11:38 +0000 | [diff] [blame] | 214 | sizeof(default_environment), '\0', 0, |
Gerlando Falauto | fe9f49d | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 215 | 0, NULL, do_apply) == 0) |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 216 | error("Environment import failed: errno = %d\n", errno); |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 217 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 218 | gd->flags |= GD_FLG_ENV_READY; |
Harald Welte | 72eb50a | 2008-07-07 15:40:39 +0800 | [diff] [blame] | 219 | } |
| 220 | |
Gerlando Falauto | fe9f49d | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 221 | |
| 222 | /* [re]set individual variables to their value in the default environment */ |
| 223 | int set_default_vars(int nvars, char * const vars[]) |
| 224 | { |
| 225 | /* |
| 226 | * Special use-case: import from default environment |
| 227 | * (and use \0 as a separator) |
| 228 | */ |
| 229 | return himport_r(&env_htab, (const char *)default_environment, |
| 230 | sizeof(default_environment), '\0', H_NOCLEAR, |
| 231 | nvars, vars, 1 /* do_apply */); |
| 232 | } |
| 233 | |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 234 | #ifndef CONFIG_SPL_BUILD |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 235 | /* |
| 236 | * Check if CRC is valid and (if yes) import the environment. |
| 237 | * Note that "buf" may or may not be aligned. |
| 238 | */ |
| 239 | int env_import(const char *buf, int check) |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 240 | { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 241 | env_t *ep = (env_t *)buf; |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 242 | |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 243 | if (check) { |
| 244 | uint32_t crc; |
| 245 | |
| 246 | memcpy(&crc, &ep->crc, sizeof(crc)); |
| 247 | |
| 248 | if (crc32(0, ep->data, ENV_SIZE) != crc) { |
| 249 | set_default_env("!bad CRC"); |
| 250 | return 0; |
| 251 | } |
| 252 | } |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 253 | |
Gerlando Falauto | 9b0e1ff | 2012-08-24 00:11:38 +0000 | [diff] [blame] | 254 | if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0, |
Gerlando Falauto | d392595 | 2012-08-24 00:11:39 +0000 | [diff] [blame] | 255 | 0, NULL, 0 /* do_apply */)) { |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 256 | gd->flags |= GD_FLG_ENV_READY; |
| 257 | return 1; |
| 258 | } |
| 259 | |
| 260 | error("Cannot import environment: errno = %d\n", errno); |
| 261 | |
| 262 | set_default_env("!import failed"); |
| 263 | |
| 264 | return 0; |
| 265 | } |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 266 | #endif |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 267 | |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 268 | void env_relocate(void) |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 269 | { |
Wolfgang Denk | d0813e5 | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 270 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
Heiko Schocher | faa0d2e | 2010-10-05 14:17:00 +0200 | [diff] [blame] | 271 | env_reloc(); |
| 272 | #endif |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 273 | if (gd->env_valid == 0) { |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 274 | #if defined(CONFIG_ENV_IS_NOWHERE) || defined(CONFIG_SPL_BUILD) |
| 275 | /* Environment not changable */ |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 276 | set_default_env(NULL); |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 277 | #else |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 278 | bootstage_error(BOOTSTAGE_ID_NET_CHECKSUM); |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 279 | set_default_env("!bad CRC"); |
Lei Wen | e0909be | 2010-10-10 12:36:40 +0800 | [diff] [blame] | 280 | #endif |
Wolfgang Denk | 460a9ff | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 281 | } else { |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 282 | env_relocate_spec(); |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 283 | } |
wdenk | 05706fd | 2002-09-28 17:48:27 +0000 | [diff] [blame] | 284 | } |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 285 | |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 286 | #if defined(CONFIG_AUTO_COMPLETE) && !defined(CONFIG_SPL_BUILD) |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 287 | int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf) |
| 288 | { |
Mike Frysinger | 8d88232 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 289 | ENTRY *match; |
| 290 | int found, idx; |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 291 | |
Mike Frysinger | 8d88232 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 292 | idx = 0; |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 293 | found = 0; |
| 294 | cmdv[0] = NULL; |
| 295 | |
Mike Frysinger | 8d88232 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 296 | while ((idx = hmatch_r(var, idx, &match, &env_htab))) { |
| 297 | int vallen = strlen(match->key) + 1; |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 298 | |
Mike Frysinger | 8d88232 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 299 | if (found >= maxv - 2 || bufsz < vallen) |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 300 | break; |
Mike Frysinger | 8d88232 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 301 | |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 302 | cmdv[found++] = buf; |
Mike Frysinger | 8d88232 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 303 | memcpy(buf, match->key, vallen); |
| 304 | buf += vallen; |
| 305 | bufsz -= vallen; |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Mike Frysinger | 8d88232 | 2010-12-17 16:51:59 -0500 | [diff] [blame] | 308 | qsort(cmdv, found, sizeof(cmdv[0]), strcmp_compar); |
| 309 | |
| 310 | if (idx) |
| 311 | cmdv[found++] = "..."; |
Igor Grinberg | 3e77359 | 2011-11-07 01:14:11 +0000 | [diff] [blame] | 312 | |
wdenk | 3902d70 | 2004-04-15 18:22:41 +0000 | [diff] [blame] | 313 | cmdv[found] = NULL; |
| 314 | return found; |
| 315 | } |
| 316 | #endif |