static int IMB_ispic_name(const char *name) { ImFileType *type; struct stat st; int fp, buf[10]; if(UTIL_DEBUG) printf("IMB_ispic_name: loading %s\n", name); if(stat(name,&st) == -1) return FALSE; if(((st.st_mode) & S_IFMT) != S_IFREG) return FALSE; if((fp = open(name,O_BINARY|O_RDONLY)) < 0) return FALSE; if(read(fp, buf, 32) != 32) { close(fp); return FALSE; } close(fp); /* XXX move this exception */ if((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0) return JPG; for(type=IMB_FILE_TYPES; type->is_a; type++) if(type->is_a((uchar*)buf)) return type->filetype; return FALSE; }
int IMB_ispic(const char *name) { /* increased from 32 to 64 because of the bitmaps header size */ #define HEADER_SIZE 64 unsigned char buf[HEADER_SIZE]; ImFileType *type; struct stat st; int fp; if (UTIL_DEBUG) printf("IMB_ispic_name: loading %s\n", name); if (BLI_stat(name, &st) == -1) return FALSE; if (((st.st_mode) & S_IFMT) != S_IFREG) return FALSE; if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) < 0) return FALSE; memset(buf, 0, sizeof(buf)); if (read(fp, buf, HEADER_SIZE) <= 0) { close(fp); return FALSE; } close(fp); /* XXX move this exception */ if ((BIG_LONG(((int *)buf)[0]) & 0xfffffff0) == 0xffd8ffe0) return JPG; for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { if (type->is_a) { if (type->is_a(buf)) { return type->filetype; } } else if (type->is_a_filepath) { if (type->is_a_filepath(name)) { return type->filetype; } } } return FALSE; #undef HEADER_SIZE }