Skip to content

Commit

Permalink
port: use strto* when parsing config instead of ato*
Browse files Browse the repository at this point in the history
allows hex values
  • Loading branch information
fgsfdsfgs committed Dec 16, 2023
1 parent 581c63f commit cdd7d6e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions port/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ static inline f32 configClampFloat(f32 val, f32 min, f32 max)
return (val < min) ? min : ((val > max) ? max : val);
}


static inline struct configentry *configFindEntry(const char *key)
{
for (s32 i = 0; i < numSettings; ++i) {
Expand Down Expand Up @@ -150,21 +149,21 @@ static void configSetFromString(const char *key, const char *val)
u32 tmp_u32;
switch (cfg->type) {
case CFG_S32:
tmp_s32 = atoi(val);
tmp_s32 = strtol(val, NULL, 0);
if (cfg->min_s32 < cfg->max_s32) {
tmp_s32 = configClampInt(tmp_s32, cfg->min_s32, cfg->max_s32);
}
*(s32 *)cfg->ptr = tmp_s32;
break;
case CFG_F32:
tmp_f32 = atof(val);
tmp_f32 = strtof(val, NULL);
if (cfg->min_f32 < cfg->max_f32) {
tmp_f32 = configClampFloat(tmp_f32, cfg->min_f32, cfg->max_f32);
}
*(f32 *)cfg->ptr = tmp_f32;
break;
case CFG_U32:
tmp_u32 = atoll(val);
tmp_u32 = strtoul(val, NULL, 0);
if (cfg->min_u32 < cfg->max_u32) {
tmp_u32 = configClampUInt(tmp_u32, cfg->min_u32, cfg->max_u32);
}
Expand Down Expand Up @@ -197,7 +196,7 @@ static void configSaveEntry(struct configentry *cfg, FILE *f)
if (cfg->min_u32 < cfg->max_u32) {
*(u32*)cfg->ptr = configClampUInt(*(u32*)cfg->ptr, cfg->min_u32, cfg->max_u32);
}
fprintf(f, "%s=%u\n", cfg->key + cfg->seclen + 1, *(u32*)cfg->ptr);
fprintf(f, "%s=%u\n", cfg->key + cfg->seclen + 1, *(u32 *)cfg->ptr);
break;
case CFG_STR:
fprintf(f, "%s=%s\n", cfg->key + cfg->seclen + 1, (char *)cfg->ptr);
Expand Down

0 comments on commit cdd7d6e

Please sign in to comment.