Exemplo n.º 1
0
static TRASH_BUCKET *TRASH_CreateHomeBucket(void)
{
    TRASH_BUCKET *bucket;
    struct stat trash_stat;
    char *trash_path = NULL;
    
    bucket = SHAlloc(sizeof(TRASH_BUCKET));
    if (bucket == NULL)
    {
        errno = ENOMEM;
        goto error;
    }
    memset(bucket, 0, sizeof(*bucket));
    bucket->info_dir = init_home_dir("Trash/info/");
    if (bucket->info_dir == NULL) goto error;
    bucket->files_dir = init_home_dir("Trash/files/");
    if (bucket->files_dir == NULL) goto error;
    
    trash_path = XDG_BuildPath(XDG_DATA_HOME, "Trash/");
    if (stat(trash_path, &trash_stat) == -1)
        goto error;
    bucket->device = trash_stat.st_dev;
    SHFree(trash_path);
    return bucket;
error:
    SHFree(trash_path);
    if (bucket)
    {
        SHFree(bucket->info_dir);
        SHFree(bucket->files_dir);
    }
    SHFree(bucket);
    return NULL;
}
Exemplo n.º 2
0
Arquivo: cgdb.c Projeto: i4fumi/cgdb
int main(int argc, char *argv[])
{
/* Uncomment to debug and attach */
#if 0
    int c;

    read(0, &c, 1);
#endif

    parse_long_options(&argc, &argv);

    current_line = ibuf_init();

    cgdbrc_init();

    if (create_and_init_pair() == -1) {
        fprintf(stderr, "%s:%d Unable to create PTY pair", __FILE__, __LINE__);
        exit(-1);
    }

    /* First create tgdb, because it has the error log */
    if (start_gdb(argc, argv) == -1) {
        fprintf(stderr, "%s:%d Unable to invoke GDB", __FILE__, __LINE__);
        exit(-1);
    }

    /* From here on, the logger is initialized */

    /* Create the home directory */
    if (init_home_dir() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__,
                "Unable to create home dir ~/.cgdb");
        cleanup();
        exit(-1);
    }

    if (init_readline() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "Unable to init readline");
        cleanup();
        exit(-1);
    }

    if (tty_cbreak(STDIN_FILENO, &term_attributes) == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "tty_cbreak error");
        cleanup();
        exit(-1);
    }

    if (init_kui() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "init_kui error");
        cleanup();
        exit(-1);
    }

    /* Initialize the display */
    switch (if_init()) {
        case 1:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "Unable to initialize the curses library");
            cleanup();
            exit(-1);
        case 2:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "Unable to handle signal: SIGWINCH");
            cleanup();
            exit(-1);
        case 3:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "Unable to setup highlighting groups");
            cleanup();
            exit(-1);
        case 4:
            logger_write_pos(logger, __FILE__, __LINE__,
                    "New GDB window failed -- out of memory?");
            cleanup();
            exit(-1);
    }

    /* Initialize the pipe that is used for resize */
    if (init_resize_pipe() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "init_resize_pipe error");
        cleanup();
        exit(-1);
    }

    {
        char config_file[FSUTIL_PATH_MAX];
        FILE *config;

        fs_util_get_path(cgdb_home_dir, "cgdbrc", config_file);
        config = fopen(config_file, "r");
        if (config) {
            command_parse_file(config);
            fclose(config);
        }
    }

    /* Enter main loop */
    main_loop();

    /* Shut down curses and exit */
    cleanup();
    return 0;
}