all repos — mgba @ 0ef07f7c26d440aa216925b1d6ad4886fa3fde50

mGBA Game Boy Advance Emulator

Util: Configuration should use FILE instead of fds to be more portable
Jeffrey Pfau jeffrey@endrift.com
Mon, 10 Nov 2014 23:45:29 -0800
commit

0ef07f7c26d440aa216925b1d6ad4886fa3fde50

parent

fba659daa1db9beca099ff06d573ef3ff1f6ae1c

1 files changed, 13 insertions(+), 13 deletions(-)

jump to
M src/util/configuration.csrc/util/configuration.c

@@ -24,13 +24,13 @@ return 1;

} static void _keyHandler(const char* key, void* value, void* user) { - dprintf((int) user, "%s=%s\n", key, value); + fprintf(user, "%s=%s\n", key, (const char*) value); } static void _sectionHandler(const char* key, void* section, void* user) { - dprintf((int) user, "[%s]\n", key); + fprintf(user, "[%s]\n", key); HashTableEnumerate(section, _keyHandler, user); - dprintf((int) user, "\n"); + fprintf(user, "\n"); } void ConfigurationInit(struct Configuration* configuration) {

@@ -96,29 +96,29 @@ return ini_parse(path, _iniRead, configuration) == 0;

} bool ConfigurationWrite(const struct Configuration* configuration, const char* path) { - int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd < 0) { + FILE* file = fopen(path, "w"); + if (!file) { return false; } - HashTableEnumerate(&configuration->root, _keyHandler, (void*) fd); - HashTableEnumerate(&configuration->sections, _sectionHandler, (void*) fd); - close(fd); + HashTableEnumerate(&configuration->root, _keyHandler, file); + HashTableEnumerate(&configuration->sections, _sectionHandler, file); + fclose(file); return true; } bool ConfigurationWriteSection(const struct Configuration* configuration, const char* path, const char* section) { const struct Table* currentSection = &configuration->root; - int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd < 0) { + FILE* file = fopen(path, "w"); + if (!file) { return false; } if (section) { currentSection = HashTableLookup(&configuration->sections, section); - dprintf(fd, "[%s]\n", section); + fprintf(file, "[%s]\n", section); } if (currentSection) { - HashTableEnumerate(currentSection, _sectionHandler, (void*) fd); + HashTableEnumerate(currentSection, _sectionHandler, file); } - close(fd); + fclose(file); return true; }