You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2023/07/28 16:13:52 UTC
[mynewt-core] branch config_conf_float created (now 5f58e32dd)
This is an automated email from the ASF dual-hosted git repository.
wes3 pushed a change to branch config_conf_float
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
at 5f58e32dd sys/config: Add CONF_FLOAT to config
This branch includes the following new commits:
new 5f58e32dd sys/config: Add CONF_FLOAT to config
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[mynewt-core] 01/01: sys/config: Add CONF_FLOAT to config
Posted by we...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wes3 pushed a commit to branch config_conf_float
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 5f58e32dd5cb72c486f634e92dc6e4f1c66e225f
Author: Will San Filippo <wi...@juul.com>
AuthorDate: Fri Jul 28 12:11:02 2023 -0400
sys/config: Add CONF_FLOAT to config
CONF_FLOAT was defined as a type but not implemented. This change
adds CONF_FLOAT.
---
libc/baselibc/include/stdlib.h | 1 +
sys/config/src/config.c | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/libc/baselibc/include/stdlib.h b/libc/baselibc/include/stdlib.h
index d80a0f8a5..071342735 100644
--- a/libc/baselibc/include/stdlib.h
+++ b/libc/baselibc/include/stdlib.h
@@ -57,6 +57,7 @@ __extern long strtol(const char *, char **, int);
__extern long long strtoll(const char *, char **, int);
__extern unsigned long strtoul(const char *, char **, int);
__extern unsigned long long strtoull(const char *, char **, int);
+__extern float strtof(const char *, char **);
typedef int (*__comparefunc_t) (const void *, const void *);
__extern void *bsearch(const void *, const void *, size_t, size_t,
diff --git a/sys/config/src/config.c b/sys/config/src/config.c
index a1b08e07a..cb35d56b0 100644
--- a/sys/config/src/config.c
+++ b/sys/config/src/config.c
@@ -19,6 +19,8 @@
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <float.h>
#include "os/mynewt.h"
#include "base64/base64.h"
@@ -154,6 +156,7 @@ conf_value_from_str(char *val_str, enum conf_type type, void *vp, int maxlen)
{
int64_t val;
uint64_t uval;
+ float fval;
char *eptr;
if (!val_str) {
@@ -220,6 +223,16 @@ conf_value_from_str(char *val_str, enum conf_type type, void *vp, int maxlen)
*(uint64_t *)vp = uval;
}
break;
+ case CONF_FLOAT:
+ fval = strtof(val_str, &eptr);
+ if (*eptr != '\0') {
+ goto err;
+ }
+ if ((fval < FLT_MIN) || (fval > FLT_MAX)) {
+ goto err;
+ }
+ *(float *)vp = fval;
+ break;
case CONF_STRING:
val = strlen(val_str);
if (val + 1 > maxlen) {
@@ -256,6 +269,7 @@ conf_str_from_value(enum conf_type type, void *vp, char *buf, int buf_len)
{
int64_t val;
uint64_t uval;
+ float fval;
if (type == CONF_STRING) {
return vp;
@@ -294,6 +308,10 @@ conf_str_from_value(enum conf_type type, void *vp, char *buf, int buf_len)
}
snprintf(buf, buf_len, "%llu", uval);
return buf;
+ case CONF_FLOAT:
+ fval = *(float *)vp;
+ snprintf(buf, buf_len, "%f", fval);
+ return buf;
default:
return NULL;
}