Sha256: b4cd4db91fe9993e2cdc337c8ddaa978dab6baffe33d87b90b43834608ec36db
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
#include <stdlib.h> #include <hfs/hfsplus.h> static int flatFileRead(io_func* io, off_t location, size_t size, void *buffer) { FILE* file; file = (FILE*) io->data; if(size == 0) { return TRUE; } //printf("%d %d\n", location, size); fflush(stdout); if(fseeko(file, location, SEEK_SET) != 0) { perror("fseek"); return FALSE; } if(fread(buffer, size, 1, file) != 1) { perror("fread"); return FALSE; } else { return TRUE; } } static int flatFileWrite(io_func* io, off_t location, size_t size, void *buffer) { FILE* file; /*int i; printf("write: %lld %d - ", location, size); fflush(stdout); for(i = 0; i < size; i++) { printf("%x ", ((unsigned char*)buffer)[i]); fflush(stdout); } printf("\n"); fflush(stdout);*/ if(size == 0) { return TRUE; } file = (FILE*) io->data; if(fseeko(file, location, SEEK_SET) != 0) { perror("fseek"); return FALSE; } if(fwrite(buffer, size, 1, file) != 1) { perror("fwrite"); return FALSE; } else { return TRUE; } return TRUE; } static void closeFlatFile(io_func* io) { FILE* file; file = (FILE*) io->data; fclose(file); free(io); } io_func* openFlatFile(const char* fileName) { io_func* io; io = (io_func*) malloc(sizeof(io_func)); io->data = fopen(fileName, "rb+"); if(io->data == NULL) { perror("fopen"); return NULL; } io->read = &flatFileRead; io->write = &flatFileWrite; io->close = &closeFlatFile; return io; } io_func* openFlatFileRO(const char* fileName) { io_func* io; io = (io_func*) malloc(sizeof(io_func)); io->data = fopen(fileName, "rb"); if(io->data == NULL) { perror("fopen"); return NULL; } io->read = &flatFileRead; io->write = &flatFileWrite; io->close = &closeFlatFile; return io; }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shoes-3.0.1 | req/binject/ext/binject_c/flatfile.c |