jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { short tmpRef, vRefNum; long dirID; FInfo finderInfo; FSSpec theSpec; Str255 fName; OSErr osErr; long gestaltResponse = 0; /* Check that FSSpec calls are available. */ osErr = Gestalt( gestaltFSAttr, &gestaltResponse ); if ( ( osErr != noErr ) || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required"); /* TO DO: add a proper error message to jerror.h. */ /* Check that FindFolder is available. */ osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse ); if ( ( osErr != noErr ) || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required."); /* TO DO: add a proper error message to jerror.h. */ osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder, &vRefNum, &dirID ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, "- temporary items folder unavailable"); /* TO DO: Try putting the temp files somewhere else. */ /* Keep generating file names till we find one that's not in use */ for (;;) { next_file_num++; /* advance counter */ sprintf(info->temp_name, TEMP_FILE_NAME, next_file_num); strcpy ( (Ptr)fName+1, info->temp_name ); *fName = strlen (info->temp_name); osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec ); if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr ) break; } osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) ); if ( osErr != noErr ) ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); info->tempSpec = theSpec; info->read_backing_store = read_backing_store; info->write_backing_store = write_backing_store; info->close_backing_store = close_backing_store; TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); }
close_backing_store (j_common_ptr cinfo, backing_store_ptr info) { fclose(info->temp_file); /* close the file */ unlink(info->temp_name); /* delete the file */ /* If your system doesn't have unlink(), use remove() instead. * remove() is the ANSI-standard name for this function, but if * your system was ANSI you'd be using jmemansi.c, right? */ TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); }
close_file_store (j_common_ptr cinfo, backing_store_ptr info) { jdos_close(info->handle.file_handle); /* close the file */ remove(info->temp_name); /* delete the file */ /* If your system doesn't have remove(), try unlink() instead. * remove() is the ANSI-standard name for this function, but * unlink() was more common in pre-ANSI systems. */ TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); }
GLOBAL void jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { select_file_name(info->temp_name); if((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL) ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); info->read_backing_store = read_backing_store; info->write_backing_store = write_backing_store; info->close_backing_store = close_backing_store; TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); }
open_file_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { short handle; select_file_name(info->temp_name); if (jdos_open((short far *) & handle, (char far *) info->temp_name)) { /* might as well exit since jpeg_open_backing_store will fail anyway */ ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); return FALSE; } info->handle.file_handle = handle; info->read_backing_store = read_file_store; info->write_backing_store = write_file_store; info->close_backing_store = close_file_store; TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); return TRUE; /* succeeded */ }