Exemplo n.º 1
0
unsigned int p00_rename(const char *src_name, const char *dst_name,
                        const char *path)
{
    char *p00_src, *p00_dst, rname[20];
    int type;
    struct rawfile_info_s *rawfile;
    unsigned int rc;

    p00_dst = p00_file_find(dst_name, path);

    if (p00_dst != NULL) {
        lib_free(p00_dst);
        return FILEIO_FILE_EXISTS;
    }

    p00_src = p00_file_find(src_name, path);

    if (p00_src == NULL)
        return FILEIO_FILE_NOT_FOUND;

    type = p00_check_name(p00_src);

    if (type < 0)
        return FILEIO_FILE_NOT_FOUND;

    rawfile = rawfile_open(p00_src, path, FILEIO_COMMAND_APPEND);

    if (rawfile == NULL) {
        lib_free(p00_src);
        return FILEIO_FILE_NOT_FOUND;
    }

    memset(rname, 0, sizeof(rname));
    strncpy(rname, dst_name, 16);

    if (p00_write_header(rawfile, (BYTE *)rname, 0) < 0) {
        rawfile_destroy(rawfile);
        lib_free(p00_src);
        return FILEIO_FILE_NOT_FOUND;
    }

    rawfile_destroy(rawfile);

    p00_dst = p00_file_create(dst_name, path, type);

    if (p00_dst == NULL) {
        lib_free(p00_src);
        return FILEIO_FILE_NOT_FOUND;
    }

    rc = rawfile_rename(p00_src, p00_dst, path);

    lib_free(p00_src);
    lib_free(p00_dst);

    return rc;
}
Exemplo n.º 2
0
static char *p00_file_find(const char *file_name, const char *path)
{
    struct ioutil_dir_s *ioutil_dir;
    struct rawfile_info_s *rawfile;
    BYTE p00_header_file_name[P00_HDR_CBMNAME_LEN];
    char *name, *alloc_name = NULL;
    int rc;

    ioutil_dir = ioutil_opendir(path);

    if (ioutil_dir == NULL)
        return NULL;

    while (1) {
        name = ioutil_readdir(ioutil_dir);

        if (name == NULL)
            break;

        if (p00_check_name(name) < 0)
            continue;

        rawfile = rawfile_open(name, path, FILEIO_COMMAND_READ);
        if (rawfile == NULL)
            continue;

        rc = p00_read_header(rawfile, (BYTE *)p00_header_file_name, NULL);

        if (rc >= 0) {
            BYTE *cname;
            unsigned int equal;

            p00_pad_a0(p00_header_file_name);
            cname = cbmdos_dir_slot_create(file_name, strlen(file_name));
            equal = cbmdos_parse_wildcard_compare(cname, p00_header_file_name);
            lib_free(cname);

            if (equal > 0)
                alloc_name = lib_stralloc(name);
            else
                rc = -1;
        }

        rawfile_destroy(rawfile);

        if (rc >= 0)
            break;
    }

    ioutil_closedir(ioutil_dir);

    return alloc_name;
}
Exemplo n.º 3
0
fileio_info_t *cbmfile_open(const char *file_name, const char *path,
                            unsigned int command, unsigned int type)
{
    BYTE *cbm_name;
    fileio_info_t *info;
    struct rawfile_info_s *rawfile;
    char *fsname, *rname;

    fsname = lib_stralloc(file_name);

    if (!(command & FILEIO_COMMAND_FSNAME)) {
        charset_petconvstring((BYTE *)fsname, 1);
    }

    if (cbmdos_parse_wildcard_check(fsname, (unsigned int)strlen(fsname))) {
        rname = cbmfile_find_file(fsname, path);
        lib_free(fsname);
        if (rname == NULL) {
            return NULL;
        }
    } else {
        rname = fsname;
    }

    rawfile = rawfile_open(rname, path, command & FILEIO_COMMAND_MASK);

    lib_free(rname);

    if (rawfile == NULL) {
        return NULL;
    }

    cbm_name = (BYTE *)lib_stralloc(file_name);

    if (command & FILEIO_COMMAND_FSNAME) {
        charset_petconvstring(cbm_name, 0);
    }

    info = lib_malloc(sizeof(fileio_info_t));
    info->name = cbm_name;
    info->length = (unsigned int)strlen((char *)cbm_name);
    info->type = type;
    info->format = FILEIO_FORMAT_RAW;
    info->rawfile = rawfile;

    return info;
}
Exemplo n.º 4
0
fileio_info_t *p00_open(const char *file_name, const char *path,
                        unsigned int command, unsigned int open_type)
{
    char rname[20]; /* FIXME */
    fileio_info_t *info;
    struct rawfile_info_s *rawfile;
    char *fname = NULL;
    int type;

    if (command & FILEIO_COMMAND_FSNAME) {
        fname = lib_stralloc(file_name);
    } else {
        switch (command & FILEIO_COMMAND_MASK) {
        case FILEIO_COMMAND_READ:
        case FILEIO_COMMAND_APPEND:
        case FILEIO_COMMAND_APPEND_READ:
            fname = p00_file_find(file_name, path);
            break;
        case FILEIO_COMMAND_WRITE:
            fname = p00_file_create(file_name, path, open_type);
            break;
        }
    }

    if (fname == NULL)
        return NULL;

    type = p00_check_name(fname);

    rawfile = rawfile_open(fname, path, command & FILEIO_COMMAND_MASK);
    lib_free(fname);

    if (rawfile == NULL)
        return NULL;

    switch (command & FILEIO_COMMAND_MASK) {
    case FILEIO_COMMAND_READ:
        if (type < 0 || p00_read_header(rawfile, (BYTE *)rname, NULL) < 0) {
            rawfile_destroy(rawfile);
            return NULL;
        }
        break;
    case FILEIO_COMMAND_APPEND:
    case FILEIO_COMMAND_APPEND_READ:
        if (type < 0 || p00_read_header(rawfile, (BYTE *)rname, NULL) < 0) {
            rawfile_destroy(rawfile);
            return NULL;
        }
        /*
                if (fseek((FILE *)(rawfile->fd), 0, SEEK_END) != 0)
                    rawfile_destroy(rawfile);
                    return NULL;
        */
        break;
    case FILEIO_COMMAND_WRITE:
        memset(rname, 0, sizeof(rname));
        strncpy(rname, file_name, 16);
        if (p00_write_header(rawfile, (BYTE *)rname, 0) < 0) {
            rawfile_destroy(rawfile);
            return NULL;
        }
        break;
    }

    info = (fileio_info_t *)lib_malloc(sizeof(fileio_info_t));
    info->name = (BYTE *)lib_stralloc(rname);
    info->length = (unsigned int)strlen((char *)(info->name));
    info->type = (unsigned int)type;
    info->format = FILEIO_FORMAT_P00;
    info->rawfile = rawfile;

    return info;
}