Example #1
0
bffilebuf::bffilebuf(const FileName &filename, ios::openmode mode) :
	in(0), out(0), readbuf(0), writebuf(0), remaining(0), num(0)
{
	if (mode & ios::in) {
		remaining = FileWriter::getFileSize(filename) - strlen(BF_FILE_IDENTIFICATOR) - 1;
		in = new FileUtils::paloifstream(filename.fullPath().c_str());
		string ident;
		getline(*in, ident);
		if (ident == BF_FILE_IDENTIFICATOR) {
			readbuf = new unsigned char[BUF_SIZE];
			setg((char *)readbuf, (char *)readbuf, (char *)readbuf);
		} else {
			delete in;
			in = 0;
		}
	}
	if (mode & ios::out) {
		size_t s = FileWriter::getFileSize(filename);
		out = new FileUtils::paloofstream(filename.fullPath().c_str(), mode);
		if (!(s && (mode & ios::app))) {
			*out << BF_FILE_IDENTIFICATOR << endl;
		}
		writebuf = new unsigned char[BUF_SIZE];
		setp((char *)writebuf, (char *)(writebuf + BUF_SIZE - 1));
	}
	memcpy(ivec, &initivec, 8);
	BF_set_key(&key, (int)passphrase.size(), (const unsigned char *)passphrase.c_str());
}
Example #2
0
bool FileUtils::isReadable(const FileName& fileName) {
  FILE* file = fopen(fileName.fullPath().c_str(), "r");

  if (file == 0) {
    return false;
  } else {
    fclose(file);
    return true;
  }
}
Example #3
0
bool FileUtils::rename(const FileName& oldName, const FileName& newName) {
  int result = std::rename(oldName.fullPath().c_str(),
                           newName.fullPath().c_str());
  return (result != 0) ? false : true;
}
Example #4
0
bool FileUtils::remove(const FileName& fileName) {
  int result = std::remove(fileName.fullPath().c_str());
  return (result != 0) ? false : true;
}