/* Buffer write. ** ------------ */ extern "C" int disk_stream_write (NET_StreamClass *stream, CONST char* s, int32 len) { int32 status; DataObject * data = (DataObject *)stream->data_object; if(!data || !data->fp || !len || !s) return(0); status = XP_FileWrite(s, len, data->fp); if(len != status) { if(errno == ENOSPC) return(MK_DISK_FULL); else return(-1); } data->cur_loc += len; float fPercent = 0.0f; if (data->content_length) fPercent = (float)data->cur_loc / (float)data->content_length; if (data->cur_loc) FE_SetProgressBarPercent(data->context, (int)(fPercent * 100)); return((int) status); }
void CStreamOutFile::Write( char *pBuffer, int32 iCount ){ if( m_status != EOS_NoError ){ return; } // this code doesn't work and it probably should be done at the other end // it is designed to fix CR's showing up in the text. int iWrote; if( !m_bBinary ){ int i = 0; int iLast = 0; int iWrite; while( i < iCount ){ if( pBuffer[i] == '\n' ){ iWrite = i - iLast; if( iWrite ){ iWrote = XP_FileWrite( &pBuffer[iLast], iWrite, m_outputFile ); if( iWrote != iWrite ){ m_status = EOS_DeviceFull; } } #ifdef XP_MAC iWrote = XP_FileWrite("\r", 1, m_outputFile ); #else iWrote = XP_FileWrite("\n", 1, m_outputFile ); #endif if( iWrote != 1 ){ m_status = EOS_DeviceFull; } iLast = i+1; } i++; } iWrite = i - iLast; if( iWrite ){ iWrote = XP_FileWrite( &pBuffer[iLast], iWrite, m_outputFile ); if( iWrote != iWrite ){ m_status = EOS_DeviceFull; } } return; } else { iWrote = XP_FileWrite( pBuffer, iCount, m_outputFile ); if( iWrote != iCount ){ m_status = EOS_DeviceFull; } } }
extern "C" void disk_stream_abort (NET_StreamClass *stream, int status) { DataObject * data = (DataObject *)stream->data_object; char * error_string = "<title>Error</title><H1>Error</h1>Unable to load requested item."; if (data->fp) XP_FileWrite(error_string, XP_STRLEN(error_string), data->fp); disk_stream_complete(stream); return; }