Beispiel #1
0
/* void openFiles()
 * Opens the files to run the program.
 */
void openFiles(char* outFile, File* out,
    char* primFile, FILE** prim, char* inFile, File* in,
    char* logFile, FILE** log, char* bedFile, FILE** bed,
    char* wasteFile, File* waste,
    char* corrFile, File* corr, int gz) {
  // open required files
  *prim = openRead(primFile);
  if (gz) {
    // gzip compressed files
    in->gzf = gzopen(inFile, "r");
    if (in->gzf == NULL)
      exit(error(inFile, ERROPEN));
    openGZWrite(outFile, out, gz);
  } else {
    in->f = openRead(inFile);
    out->f = openWrite(outFile);
  }

  // open optional files
  if (bedFile != NULL)
    *bed = openRead(bedFile);
  if (logFile != NULL)
    *log = openWrite(logFile);
  if (wasteFile != NULL)
    openGZWrite(wasteFile, waste, gz);
  if (corrFile != NULL)
    openGZWrite(corrFile, corr, gz);
}
Beispiel #2
0
  // @mfunc Open this <c OMFile>.
  //   @precondition <f !isOpen()>
  //   @precondition <f !isClosed()>
  //   @postcondition <f isOpen()>
void OMFile::open(void)
{
  TRACE("OMFile::open");
  PRECONDITION("Not already open", !isOpen());
  PRECONDITION("Never been opened", !isClosed());
  PRECONDITION("Valid mode", (_mode == readOnlyMode) ||
                             (_mode == writeOnlyMode) ||
                             (_mode == modifyMode));

  if (_isNew) { // new file - create
    ASSERT("Correct mode for new file", _mode != readOnlyMode);
    if (_mode == modifyMode) {
      createModify();
    } else { // _mode == writeOnly
      createWrite();
    }
  } else {      // existing file - open
    ASSERT("Correct mode for existing file", (_mode == readOnlyMode) ||
                                             (_mode == modifyMode));
    if (_mode == readOnlyMode) {
      openRead();
    } else { // _mode == modifyMode
      openModify();
    }
    ASSERT("No root object", _root == 0);
    _root = restoreRoot();
  }

  _isOpen = true;
  POSTCONDITION("Open", isOpen());
}
Beispiel #3
0
	bool getCRC32(const TCHAR* name, DWORD& CRC,const unsigned char* sideinfo, size_t size) {
		if (!name) return false;
		int hFile=openRead(name);
		if (hFile<0) return false;
		CRC32 *crc=new CRC32();
		const size_t BUFFERSIZE=4096;
		unsigned char *ucBuffer=new unsigned char[BUFFERSIZE];
		__int64 filesize=_lseeki64(hFile,0,SEEK_END);
		_lseeki64(hFile,0,SEEK_SET);
		CRC=0;
		while (filesize-BUFFERSIZE>0) {
			int rd=_read(hFile,ucBuffer,BUFFERSIZE);
			filesize-=BUFFERSIZE;
			CRC=crc->get(ucBuffer,BUFFERSIZE,CRC);
		};
		if (filesize>0) {
			int rd=_read(hFile,ucBuffer,(unsigned int)(filesize));
			CRC=crc->get(ucBuffer,(unsigned int)(filesize),CRC);
		}
		// Add sideinfo
		if (sideinfo && size) CRC=crc->get(sideinfo,size,CRC);
		_close(hFile);
		delete[] ucBuffer;
		delete crc;
		return true;
	}
Beispiel #4
0
MA_FILE * MA_fopen ( const char * filename, const char * mode ) {
	int modeFlags = getModeFlags(mode);
	LOG("fopen('%s', '%s')", filename, mode);
	if(!modeFlags) {
		LOG("no modeflags");
		return NULL;
	}
	if(storeExists(filename) || (modeFlags&MODE_WRITE)) {
		LOG("attempt openReadWrite");
		return openReadWrite(filename, modeFlags);
	} else {
		LOG("attempt openRead");
		return openRead(filename, modeFlags);
	}
}
Beispiel #5
0
bool KoStore::open( const QString & _name )
{
  // This also converts from relative to absolute, i.e. merges the currentPath()
  m_sName = toExternalNaming( _name );

  if ( m_bIsOpen )
  {
    kdWarning(s_area) << "KoStore: File is already opened" << endl;
    //return KIO::ERR_INTERNAL;
    return false;
  }

  if ( m_sName.length() > 512 )
  {
      kdError(s_area) << "KoStore: Filename " << m_sName << " is too long" << endl;
      //return KIO::ERR_MALFORMED_URL;
      return false;
  }

  if ( m_mode == Write )
  {
    kdDebug(s_area) << "KoStore: opening for writing '" << m_sName << "'" << endl;
    if ( m_strFiles.findIndex( m_sName ) != -1 ) // just check if it's there
    {
      kdWarning(s_area) << "KoStore: Duplicate filename " << m_sName << endl;
      //return KIO::ERR_FILE_ALREADY_EXIST;
      return false;
    }

    m_strFiles.append( m_sName );

    m_iSize = 0;
    if ( !openWrite( m_sName ) )
      return false;
  }
  else if ( m_mode == Read )
  {
    kdDebug(s_area) << "Opening for reading '" << m_sName << "'" << endl;
    if ( !openRead( m_sName ) )
      return false;
  }
  else
    //return KIO::ERR_UNSUPPORTED_ACTION;
    return false;

  m_bIsOpen = true;
  return true;
}
Beispiel #6
0
struct pipeline *pipelineOpen(char ***cmds, unsigned opts,
                              char *otherEndFile, char *stderrFile)
/* Create a pipeline from an array of commands.  See pipeline.h for
 * full documentation */
{
int otherEndFd;
int stderrFd = (stderrFile == NULL) ? STDERR_FILENO : openWrite(stderrFile);

checkOpts(opts);
if (opts & pipelineRead)
    otherEndFd = (otherEndFile == NULL) ? STDIN_FILENO : openRead(otherEndFile);
else
    otherEndFd = (otherEndFile == NULL) ? STDOUT_FILENO : openWrite(otherEndFile);
struct pipeline *pl = pipelineOpenFd(cmds, opts, otherEndFd, stderrFd);
safeClose(&otherEndFd);
if (stderrFile != NULL)
    safeClose(&stderrFd);
return pl;
}
Beispiel #7
0
bool KoStore::open(const QString & _name)
{
    Q_D(KoStore);
    // This also converts from relative to absolute, i.e. merges the currentPath()
    d->fileName = d->toExternalNaming(_name);

    if (d->isOpen) {
        kWarning(30002) << "Store is already opened, missing close";
        //return KIO::ERR_INTERNAL;
        return false;
    }

    if (d->fileName.length() > 512) {
        kError(30002) << "KoStore: Filename " << d->fileName << " is too long" << endl;
        //return KIO::ERR_MALFORMED_URL;
        return false;
    }

    if (d->mode == Write) {
        kDebug(30002) << "opening for writing" << d->fileName;
        if (d->filesList.contains(d->fileName)) {
            kWarning(30002) << "KoStore: Duplicate filename" << d->fileName;
            //return KIO::ERR_FILE_ALREADY_EXIST;
            return false;
        }

        d->filesList.append(d->fileName);

        d->size = 0;
        if (!openWrite(d->fileName))
            return false;
    } else if (d->mode == Read) {
        kDebug(30002) << "Opening for reading" << d->fileName;
        if (!openRead(d->fileName))
            return false;
    } else
        //return KIO::ERR_UNSUPPORTED_ACTION;
        return false;

    d->isOpen = true;
    return true;
}
Beispiel #8
0
void PlaybackFile::updateHeader() {
	if (_mode == kWrite) {
		_readStream = g_system->getSavefileManager()->openForLoading(_header.fileName);
	}
	_readStream->seek(0);
	skipHeader();
	String tmpFilename = "_" + _header.fileName;
	_writeStream = g_system->getSavefileManager()->openForSaving(tmpFilename);
	dumpHeaderToFile();
	uint32 readedSize = 0;
	do {
		readedSize = _readStream->read(_tmpBuffer, kRecordBuffSize);
		_writeStream->write(_tmpBuffer, readedSize);
	} while (readedSize != 0);
	delete _writeStream;
	_writeStream = NULL;
	delete _readStream;
	_readStream = NULL;
	g_system->getSavefileManager()->removeSavefile(_header.fileName);
	g_system->getSavefileManager()->renameSavefile(tmpFilename, _header.fileName);
	if (_mode == kRead) {
		openRead(_header.fileName);
	}
}
static inline ReadFile* openRead(const std::string& filename)
{ return openRead(filename.c_str()); }
Beispiel #10
0
bool SlotFileStatic::exists() const {
	Common::InSaveFile *in = openRead();
	bool result = (in != 0);
	delete in;
	return result;
}
Beispiel #11
0
bool SlotFileIndexed::exists(int slot) const {
	Common::InSaveFile *in = openRead(slot);
	bool result = (in != 0);
	delete in;
	return result;
}
Beispiel #12
0
axStatus	axFile::openRead	( const char*    filename ) {
	axTempStringW tmp;
	axStatus st = tmp.set( filename );	if( !st ) return st;
	return openRead( tmp );
}