static Tox *load_toxic(char *data_path) { struct Tox_Options tox_opts; init_tox_options(&tox_opts); TOX_ERR_NEW new_err; Tox *m = load_tox(data_path, &tox_opts, &new_err); if (new_err == TOX_ERR_NEW_PORT_ALLOC && tox_opts.ipv6_enabled) { queue_init_message("Falling back to ipv4"); tox_opts.ipv6_enabled = false; m = load_tox(data_path, &tox_opts, &new_err); } if (!m) exit_toxic_err("tox_new returned fatal error", new_err); if (new_err != TOX_ERR_NEW_OK) queue_init_message("tox_new returned non-fatal error %d", new_err); init_tox_callbacks(m); load_friendlist(m); load_blocklist(BLOCK_FILE); if (tox_self_get_name_size(m) == 0) tox_self_set_name(m, (uint8_t *) "Toxic User", strlen("Toxic User"), NULL); return m; }
static void load_data(Tox *m, char *path) { if (arg_opts.ignore_data_file) return; FILE *fd; if ((fd = fopen(path, "rb")) != NULL) { fseek(fd, 0, SEEK_END); int len = ftell(fd); fseek(fd, 0, SEEK_SET); char *buf = malloc(len); if (buf == NULL) { fclose(fd); exit_toxic_err("failed in load_data", FATALERR_MEMORY); } if (fread(buf, len, 1, fd) != 1) { free(buf); fclose(fd); exit_toxic_err("failed in load_data", FATALERR_FREAD); } tox_load(m, (uint8_t *) buf, len); load_friendlist(m); load_blocklist(BLOCK_FILE); free(buf); fclose(fd); } else { if (store_data(m, path) != 0) exit_toxic_err("failed in load_data", FATALERR_STORE_DATA); } }