Esempio n. 1
0
static int init_data_files(void)
{
    if (arg_opts.use_custom_data)
        return 0;

    char *user_config_dir = get_user_config_dir();
    int config_err = create_user_config_dirs(user_config_dir);

    if (DATA_FILE == NULL ) {
        if (config_err) {
            DATA_FILE = strdup(DATANAME);
            BLOCK_FILE = strdup(BLOCKNAME);

            if (DATA_FILE == NULL || BLOCK_FILE == NULL)
                exit_toxic_err("failed in load_data_structures", FATALERR_MEMORY);
        } else {
            DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(DATANAME) + 1);
            BLOCK_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(BLOCKNAME) + 1);

            if (DATA_FILE == NULL || BLOCK_FILE == NULL)
                exit_toxic_err("failed in load_data_structures", FATALERR_MEMORY);

            strcpy(DATA_FILE, user_config_dir);
            strcat(DATA_FILE, CONFIGDIR);
            strcat(DATA_FILE, DATANAME);

            strcpy(BLOCK_FILE, user_config_dir);
            strcat(BLOCK_FILE, CONFIGDIR);
            strcat(BLOCK_FILE, BLOCKNAME);
        }
    }

    free(user_config_dir);
    return config_err;
}
Esempio n. 2
0
/* Initializes the default config directory and data files used by toxic.
 *
 * Exits the process with an error on failure.
 */
static void init_default_data_files(void)
{
    if (arg_opts.use_custom_data)
        return;

    char *user_config_dir = get_user_config_dir();

    if (user_config_dir == NULL)
        exit_toxic_err("failed in init_default_data_files()", FATALERR_FILEOP);

    int config_err = create_user_config_dirs(user_config_dir);

    if (config_err == -1) {
        DATA_FILE = strdup(DATANAME);
        BLOCK_FILE = strdup(BLOCKNAME);

        if (DATA_FILE == NULL || BLOCK_FILE == NULL)
            exit_toxic_err("failed in init_default_data_files()", FATALERR_MEMORY);
    } else {
        DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(DATANAME) + 1);
        BLOCK_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(BLOCKNAME) + 1);

        if (DATA_FILE == NULL || BLOCK_FILE == NULL)
            exit_toxic_err("failed in init_default_data_files()", FATALERR_MEMORY);

        strcpy(DATA_FILE, user_config_dir);
        strcat(DATA_FILE, CONFIGDIR);
        strcat(DATA_FILE, DATANAME);

        strcpy(BLOCK_FILE, user_config_dir);
        strcat(BLOCK_FILE, CONFIGDIR);
        strcat(BLOCK_FILE, BLOCKNAME);
    }

    /* For backwards compatibility with old toxic profile names. TODO: remove this some day */
    if (rename_old_profile(user_config_dir) == -1)
        queue_init_message("Warning: Profile backwards compatibility failed.");

    free(user_config_dir);
}