You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Float parsing uses system configuration and will print out and load floats as locale aware. In our usecase, we use libcyaml as confiuration schema and is unacceptable to have floats in locale format, as it prehibits compatibility of configuration values cross-machines.
The text was updated successfully, but these errors were encountered:
Why not just create wrappers that set and restore the locale around cyaml load/save calls?
For example something like this (untested):
boolmy_yaml_loader(
constchar*path,
my_data_t**data_out)
{
char*old_locale, *saved_locale;
unsignedsequence_count;
boolret= false;
my_data_t*data;
cyaml_err_terr;
/* Get the name of the current locale. */old_locale=setlocale (LC_ALL, NULL);
/* Copy the name so it won’t be clobbered by setlocale. */saved_locale=strdup(old_locale);
if (saved_locale==NULL) {
fprintf(stderr, "Out of memory\n");
return false;
}
/* Now change the locale to the one we want for loading. */setlocale (LC_ALL, "C");
/* Do the load. */err=cyaml_load_file(path, config, schema, &data, &sequence_count);
if (err!=CYAML_OK) {
fprintf(stderr, "Error loading %s: %s\n",
path, cyaml_strerror(err));
goto restore;
}
*data_out=data;
ret= true;
restore:
/* Restore the original locale. */setlocale (LC_ALL, saved_locale);
free(saved_locale);
returnret;
}
Hi.
Float parsing uses system configuration and will print out and load floats as locale aware. In our usecase, we use libcyaml as confiuration schema and is unacceptable to have floats in locale format, as it prehibits compatibility of configuration values cross-machines.
The text was updated successfully, but these errors were encountered: