[locale,keyboard] use new JSON config reader

This commit is contained in:
akallabeth
2025-05-26 18:09:59 +02:00
parent 022871969c
commit 7877f32cbc

View File

@@ -924,7 +924,7 @@ static BOOL load_layout_file(void)
if (!fp)
goto end;
(void)fprintf(fp, "%s", str);
fclose(fp);
(void)fclose(fp);
}
end:
free(str);
@@ -1006,54 +1006,9 @@ static void clear_layout_tables(void)
static WINPR_JSON* load_layouts_from_file(const char* filename)
{
INT64 jstrlen = 0;
char* jstr = NULL;
WINPR_JSON* json = NULL;
FILE* fp = winpr_fopen(filename, "r");
if (!fp)
{
WLog_WARN(TAG, "resource file '%s' does not exist or is not readable", filename);
return NULL;
}
if (_fseeki64(fp, 0, SEEK_END) < 0)
{
WLog_WARN(TAG, "resource file '%s' seek failed", filename);
goto end;
}
jstrlen = _ftelli64(fp);
if (jstrlen < 0)
{
WLog_WARN(TAG, "resource file '%s' invalid length %" PRId64, filename, jstrlen);
goto end;
}
if (_fseeki64(fp, 0, SEEK_SET) < 0)
{
WLog_WARN(TAG, "resource file '%s' seek failed", filename);
goto end;
}
jstr = calloc((size_t)jstrlen + 1, sizeof(char));
if (!jstr)
{
WLog_WARN(TAG, "resource file '%s' failed to allocate buffer of size %" PRId64, filename,
jstrlen);
goto end;
}
if (fread(jstr, (size_t)jstrlen, sizeof(char), fp) != 1)
{
WLog_WARN(TAG, "resource file '%s' failed to read buffer of size %" PRId64, filename,
jstrlen);
goto end;
}
json = WINPR_JSON_ParseWithLength(jstr, (size_t)jstrlen);
WINPR_JSON* json = WINPR_JSON_ParseFromFile(filename);
if (!json)
WLog_WARN(TAG, "resource file '%s' is not a valid JSON file", filename);
end:
fclose(fp);
free(jstr);
return json;
}