size_t BLI_filepathsize(const char *path) { int size, file = open(path, O_BINARY|O_RDONLY); if (file == -1) return -1; size = BLI_filesize(file); close(file); return size; }
unsigned short imb_update_iff(int file, int code) { int buf[2], filelen, skip; uchar nop; if (file<=0) return (FALSE); filelen = BLI_filesize(file)-8; /* calc filelength */ lseek(file,0L,2); /* seek end */ if (filelen & 1){ /* make length 'even' */ switch(code){ case BODY: nop = IFFNOP; break; } if (write(file,&nop,1)!=1) return (FALSE); filelen++; } lseek(file,4L,0); buf[0] = BIG_LONG(filelen); if (write(file, buf, 4) != 4) return (FALSE); if (code == 0) return (TRUE); filelen-=4; lseek(file,4L,1); while (filelen>0){ /* seek BODY */ read(file, buf, 8); filelen -= 8; if (buf[0] == code) break; skip = (BIG_LONG(buf[1]) + 1) & ~1; filelen -= skip; lseek(file, skip, 1); } if (filelen <= 0) { printf("update_iff: couldn't find chunk\n"); return (FALSE); } lseek(file, -4L, 1); buf[0] = BIG_LONG(filelen); if (write(file, buf, 4)!=4) return (FALSE); return (TRUE); }
PackedFile *newPackedFile(ReportList *reports, const char *filename) { PackedFile *pf = NULL; int file, filelen; char name[FILE_MAXDIR+FILE_MAXFILE]; void *data; /* render result has no filename and can be ignored * any other files with no name can be ignored too */ if(filename[0]=='\0') return NULL; //XXX waitcursor(1); // convert relative filenames to absolute filenames strcpy(name, filename); BLI_path_abs(name, G.main->name); // open the file // and create a PackedFile structure file= open(name, O_BINARY|O_RDONLY); if (file <= 0) { BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path not found: \"%s\"", name); } else { filelen = BLI_filesize(file); if (filelen == 0) { // MEM_mallocN complains about MEM_mallocN(0, "bla"); // we don't care.... data = MEM_mallocN(1, "packFile"); } else { data = MEM_mallocN(filelen, "packFile"); } if (read(file, data, filelen) == filelen) { pf = newPackedFileMemory(data, filelen); } close(file); } //XXX waitcursor(0); return (pf); }
BlendFileData *BLO_read_runtime(char *path, ReportList *reports) { BlendFileData *bfd= NULL; size_t actualsize; int fd, datastart; char buf[8]; fd= open(path, O_BINARY|O_RDONLY, 0); if(fd==-1) { BKE_reportf(reports, RPT_ERROR, "Unable to open \"%s\": %s.", path, strerror(errno)); goto cleanup; } actualsize= BLI_filesize(fd); lseek(fd, -12, SEEK_END); datastart= handle_read_msb_int(fd); if(datastart==-1) { BKE_reportf(reports, RPT_ERROR, "Unable to read \"%s\" (problem seeking)", path); goto cleanup; } else if(read(fd, buf, 8)!=8) { BKE_reportf(reports, RPT_ERROR, "Unable to read \"%s\" (truncated header)", path); goto cleanup; } else if(memcmp(buf, "BRUNTIME", 8)!=0) { BKE_reportf(reports, RPT_ERROR, "Unable to read \"%s\" (not a blend file)", path); goto cleanup; } else { //printf("starting to read runtime from %s at datastart %d\n", path, datastart); lseek(fd, datastart, SEEK_SET); bfd = blo_read_blendafterruntime(fd, path, actualsize-datastart, reports); fd= -1; // file was closed in blo_read_blendafterruntime() } cleanup: if(fd!=-1) close(fd); return bfd; }
struct ImBuf *IMB_loadifffile(int file, int flags) { struct ImBuf *ibuf; int size, *mem; if (file == -1) return (0); size = BLI_filesize(file); mem= (int *)mmap(0,size,PROT_READ,MAP_SHARED,file,0); if (mem==(int *)-1) { printf("Couldn't get mapping\n"); return (0); } ibuf = IMB_ibImageFromMemory(mem, size, flags); if (munmap( (void *) mem, size)) { printf("Couldn't unmap file.\n"); } return(ibuf); }
ImBuf *IMB_loadifffile(int file, int flags) { ImBuf *ibuf; unsigned char *mem; size_t size; if(file == -1) return NULL; size= BLI_filesize(file); mem= mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); if(mem==(unsigned char*)-1) { fprintf(stderr, "Couldn't get mapping\n"); return NULL; } ibuf= IMB_ibImageFromMemory(mem, size, flags); if(munmap(mem, size)) fprintf(stderr, "Couldn't unmap file.\n"); return ibuf; }
static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect) { ImFileType *type; unsigned char *mem; size_t size; if(file == -1) return; size= BLI_filesize(file); mem= mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); if(mem==(unsigned char*)-1) { fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename); return; } for(type=IMB_FILE_TYPES; type->is_a; type++) if(type->load_tile && type->ftype(type, ibuf)) type->load_tile(ibuf, mem, size, tx, ty, rect); if(munmap(mem, size)) fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename); }