diff options
author | Leo C | 2014-08-21 00:48:46 +0200 |
---|---|---|
committer | Leo C | 2014-08-21 00:48:46 +0200 |
commit | 69988dc1f60ce27d2192eb2aa579962f585fffc8 (patch) | |
tree | c0dd96fc58aebe4090d58bcba80efac1f7d7b91e /avr/env.c | |
parent | d0581f881c4072ef0ac453167a98dc3bc0d87d86 (diff) | |
download | z180-stamp-69988dc1f60ce27d2192eb2aa579962f585fffc8.zip |
printf() --> printf_P(PSTR())
Diffstat (limited to 'avr/env.c')
-rw-r--r-- | avr/env.c | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -103,6 +103,19 @@ uint16_t varname_get(char *buf, env_item_t *ep) static +uint16_t varval_getlen(uint16_t index) +{ + int i = 0; + char c; + + while ((c = env_get_char (index + i)) != '\0') { + i++; + }; + + return i; +} + +static uint16_t varval_get(char *buf, uint16_t index, int len) { int i = 0; @@ -403,13 +416,17 @@ env_item_t *envlist_get(const char *name, uint_fast8_t flag) if (ep != NULL && (flag & ENV_GET_VAL)) { if (ep->flags & EF_V_EEP) { char *vp; - uint_fast8_t len; - /* TODO: function that gets len of val, - to get rid of xrealloc */ - vp = xmalloc(CONFIG_SYS_CBSIZE); - len = varval_get(vp, ep->val.eep, CONFIG_SYS_CBSIZE); - ep->val.ram = xrealloc(vp, len + 1); - ep->flags &= ~EF_V_EEP; + int len; + len = varval_getlen(ep->val.eep); + if (len > CONFIG_SYS_CBSIZE) + len = CONFIG_SYS_CBSIZE; + vp = xmalloc(len + 1); + if (vp) { + varval_get(vp, ep->val.eep, len + 1); + ep->val.ram = vp; + ep->flags &= ~EF_V_EEP; + } else + printf_P(PSTR("Out of memory!\n")); } } |