Exemple #1
0
/* now define normal version */
int __cdecl _close (
	int fh
	)
{
	ParamBlockRec parm;
	OSErr osErr = 0;

	/* validate file handle */
	if ((unsigned)fh >= (unsigned)_nfile || !(_osfile[fh] & FOPEN))
		{
		/* bad file handle, set errno and abort */
		errno = EBADF;
		_macerrno = 0;
		return -1;
		}


	if (!(_osfile[fh] & FDEV))	 /*no need to close console*/
		{
		if (_osfhnd[fh] == -1 )
			{
			/*an open file with a -1 handle indicates a pseudo open
				for stdin, stdout, or stderr -- close with no error*/

			_osfhnd[fh] = 0;  /*only allowed to close once*/
			}
		else
			{
			parm.ioParam.ioRefNum = _osfhnd[fh];
			parm.ioParam.ioNamePtr = NULL;
			osErr = PBCloseSync(&parm);


			if (osErr)
				{
				_dosmaperr(osErr);
				return -1;
				}
			
			memset(&parm, 0, sizeof(ParamBlockRec));
			parm.ioParam.ioVRefNum = _osVRefNum[fh];
			osErr =  PBFlushVolSync(&parm);
			}
		}

	_osfile[fh] = 0;		/* clear file flags */
	if (osErr)
		{
		_dosmaperr(osErr);
		return -1;
		}
	return 0;			/* good return */
}
int fflush(FILE * file)
{
	fpos_t	position;                    /* mm 970708 */
	ParamBlockRec pb;
    OSErr error;
	
	if (!file)
		return(__flush_all());
	
	if (file->state.error || file->mode.file_kind == __closed_file)
		return(EOF);
	
	if (file->mode.io_mode == __read)		/* mm 980430 */
		return 0;							/* mm 980430 */
	
	if (file->state.io_state >= __rereading)
		file->state.io_state = __reading;
	
	if (file->state.io_state == __reading)
		file->buffer_len = 0;
	
	if (file->state.io_state != __writing)
	{
		file->state.io_state = __neutral;  /* mm 970905 */
		return(0);
	}
	
#ifndef _No_Disk_File_OS_Support
	if (file->mode.file_kind != __disk_file || (position = ftello(file)) < 0)
		position = 0;
#else
	position = 0;
#endif
	
	if (__flush_buffer(file, NULL))
	{
		set_error(file);
		return(EOF);
	}
	
	file->state.io_state = __neutral;
	file->position       = position;
	file->buffer_len     = 0;
	
	pb.ioParam.ioRefNum = file->handle;
    error = PBFlushFileSync(&pb);
	error = GetVRefNum(pb.ioParam.ioRefNum,&pb.volumeParam.ioVRefNum);
	pb.volumeParam.ioNamePtr = nil;
	error = PBFlushVolSync(&pb);


	return(0);
}
Exemple #3
0
int __cdecl _commit (
        int fh
        )
{
        ParamBlockRec parm;
        OSErr osErr = 0;

        if ((unsigned)fh >= (unsigned)_nfile || !(_osfile[fh] & FOPEN))
        {
                /* out of range -- return error */
                errno = EBADF;
                _macerrno = 0;
                return -1;
        }

        if (!(_osfile[fh] & FDEV))
        {
                memset(&parm, 0, sizeof(ParamBlockRec));
                parm.ioParam.ioRefNum = _osfhnd[fh];
                osErr = PBFlushFileSync(&parm);
                switch (osErr)
                {
                        case noErr:
                                memset(&parm, 0, sizeof(ParamBlockRec));
                                parm.ioParam.ioVRefNum = _osVRefNum[fh];
                                osErr =  PBFlushVolSync(&parm);
                                if (osErr)
                                {
                                        _dosmaperr(osErr);
                                        return -1;
                                }
                                return 0;

                        default:
                                errno = EIO;
                                return -1;
                }
        }
        return 0;
}
void MemoryCardDriverThreaded_MacOSX::Unmount( UsbStorageDevice *pDevice )
{
#if defined(SYNC_VOLUME_FULLSYNC) && defined(SYNC_VOLUME_WAIT)
	
	if( sync_volume_np( pDevice->sOsMountDir.c_str(), SYNC_VOLUME_FULLSYNC | SYNC_VOLUME_WAIT ) != 0 )
		LOG->Warn( "Failed to flush the memory card." );
#else
	ParamBlockRec pb;
	Str255 name; // A pascal string.
	const RString& base = Basename( pDevice->sOsMountDir );
	
	memset( &pb, 0, sizeof(pb) );
	name[0] = min( base.length(), size_t(255) );
	strncpy( (char *)&name[1], base, name[0] );
	pb.volumeParam.ioNamePtr = name;
	pb.volumeParam.ioVolIndex = -1; // Use ioNamePtr to find the volume.
	
	if( PBFlushVolSync(&pb) != noErr )
		LOG->Warn( "Failed to flush the memory card." );
	
#endif
}