t_offset sim_fsize_ex (FILE *fp) { t_offset pos, sz; if (fp == NULL) return 0; pos = sim_ftell (fp); sim_fseek (fp, 0, SEEK_END); sz = sim_ftell (fp); sim_fseeko (fp, pos, SEEK_SET); return sz; }
/* Utility function to set the image type for a unit to the correct value. * Prints an error message in case a CPT image is presented and returns * SCPE_OPENERR in this case. Otherwise the return value is SCPE_OK */ t_stat assignDiskType(UNIT *uptr) { t_stat result = SCPE_OK; char header[4]; t_offset pos = sim_ftell(uptr->fileref); sim_fseek(uptr->fileref, (t_addr)0, SEEK_SET); if (fgets(header, 4, uptr->fileref) == NULL) uptr->u3 = IMAGE_TYPE_DSK; else if (strncmp(header, "IMD", 3) == 0) uptr->u3 = IMAGE_TYPE_IMD; else if(strncmp(header, "CPT", 3) == 0) { sim_printf("CPT images not yet supported.\n"); uptr->u3 = IMAGE_TYPE_CPT; result = SCPE_OPENERR; } else uptr->u3 = IMAGE_TYPE_DSK; sim_fseeko(uptr->fileref, pos, SEEK_SET); return result; }