Example #1
0
static void* dir_read(mount_t *mnt, const char *filename, int *size) {
    char buf[MAX_PATH];
    /* Make fullpath */
    int err = concat_path(buf, mnt->path, filename);
    if (err) {
        return NULL;
    }
    /* Open file */
    FILE *fp = fopen(buf, "rb");
    if (!fp) {
        return NULL;
    }
    /* Get size */
    fseek(fp, 0, SEEK_END);
    *size = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    /* Load data */
    void *p = dmt_malloc(*size);
    if (!p) {
        return NULL;
    }
    fread(p, 1, *size, fp);
    /* Close file and return data */
    fclose(fp);
    return p;
}
Example #2
0
void * mem_alloc(size_t size) {
    void *ptr = malloc(size);
    assert(ptr != NULL);
    ++g_mem_mem_allocs_count;
    return ptr;
    return dmt_malloc(size);
}
Example #3
0
static void* tar_read(mount_t *mnt, const char *filename, int *size) {
    mtar_t *tar = mnt->udata;
    int err;
    mtar_header_t h;

    /* Find and load header for file */
    err = tar_find(mnt, filename, &h);
    if (err) {
        return 0;
    }

    /* Allocate and read data, set size and return */
    char *p = dmt_malloc(h.size);
    err = mtar_read_data(tar, p, h.size);
    if (err) {
        dmt_free(p);
        return NULL;
    }
    *size = h.size;
    return p;
}