void os_config_write_uint(const char *section, const char *name, unsigned int value) { Profile *p = profile_read(Osreg_config_file_name); #ifdef WIN32 // When there is no config file then it shouldn't be created because that would "hide" all previous settings // Instead fall back to writing the settings to the config file if (p == nullptr) { registry_write_uint(section, name, value); return; } #endif if (section == NULL) section = DEFAULT_SECTION; char buf[21]; snprintf(buf, 20, "%u", value); p = profile_update(p, section, name, buf); profile_save(p, Osreg_config_file_name); profile_free(p); }
void profile_db_close(profile_db *pdb) { if(pdb) { if(pdb->flags & PDB_CHANGED) { char *buf = NULL; size_t buf_alloc = 0; size_t profile_size; u_long tmp; _lseek(pdb->fd, 0, SEEK_SET); tmp = htonl(pdb->profiles.used); _write(pdb->fd, &tmp, sizeof(tmp)); for(size_t i = 0; i < pdb->profiles.used; i++) { if(!pdb->profiles.array[i]) continue; profile_size = profile_get_size(pdb->profiles.array[i]); if(profile_size == 0) continue; if(profile_size > buf_alloc) { if(buf) free(buf); buf = (char *)malloc(buf_alloc = profile_size); } memset(buf, '?', profile_size); tmp = htonl(profile_size); _write(pdb->fd, &tmp, sizeof(tmp)); profile_save(pdb->profiles.array[i], buf, buf_alloc); _write(pdb->fd, buf, profile_size); } if(buf) free(buf); } for(size_t i = 0; i < pdb->profiles.used; i++) { if(pdb->profiles.array[i]) profile_destroy(pdb->profiles.array[i]); } if(pdb->profiles.array) free(pdb->profiles.array); if(pdb->fd != -1) _close(pdb->fd); free(pdb); } }
void profile_db_close(profile_db *pdb) { if(pdb) { if(pdb->flags & PDB_CHANGED) { char *buf = NULL; size_t buf_alloc = 0; size_t profile_size; u_long tmp; short shortTmp; lseek(pdb->fd, 0, SEEK_SET); // { write header (pdb signature, major version, minor version) tmp = htonl(0x20050901UL); // some pdb signature write(pdb->fd, &tmp, sizeof(tmp)); shortTmp = htons(0x0001); // major version write(pdb->fd, &shortTmp, sizeof(shortTmp)); shortTmp = htons(0x0000); // minor version write(pdb->fd, &shortTmp, sizeof(shortTmp)); // } tmp = htonl(pdb->profiles.used); write(pdb->fd, &tmp, sizeof(tmp)); for(size_t i = 0; i < pdb->profiles.used; i++) { if(!pdb->profiles.array[i]) continue; profile_size = profile_get_size(pdb->profiles.array[i]); if(profile_size == 0) continue; if(profile_size > buf_alloc) { if(buf) free(buf); buf = (char *)malloc(buf_alloc = profile_size); } memset(buf, '?', profile_size); tmp = htonl(profile_size); write(pdb->fd, &tmp, sizeof(tmp)); profile_save(pdb->profiles.array[i], buf, buf_alloc); write(pdb->fd, buf, profile_size); } if(buf) free(buf); } for(size_t i = 0; i < pdb->profiles.used; i++) { if(pdb->profiles.array[i]) profile_destroy(pdb->profiles.array[i]); } if(pdb->profiles.array) free(pdb->profiles.array); close(pdb->fd); free(pdb); } }