Logo Search packages:      
Sourcecode: catcodec version File versions  Download package

void FileWriter::Close (  )

Close the output, i.e. commit the file to disk. If this is not done, the file with not be written to disk.

Definition at line 164 of file io.cpp.

References file, filename, and filename_new.

Referenced by main().

{
      /* First close the .new file */
      fclose(this->file);
      this->file = NULL;

      /* Then remove the existing .bak file */
      string filename_bak = this->filename + ".bak";
      if (unlink(filename_bak.c_str()) != 0 && errno != ENOENT) {
            fprintf(stderr, "Warning: could not remove %s (%s)\n", filename_bak.c_str(), strerror(errno));
      }

      /* Then move the existing file to .bak */
      if (rename(this->filename.c_str(), filename_bak.c_str()) != 0 && errno != ENOENT) {
            fprintf(stderr, "Warning: could not rename %s to %s (%s)\n", this->filename.c_str(), filename_bak.c_str(), strerror(errno));
      }

      /* And finally move the .new file to the actual wanted filename */
      if (rename(this->filename_new.c_str(), this->filename.c_str()) != 0) {
            fprintf(stderr, "Warning: could not rename %s to %s (%s)\n", this->filename_new.c_str(), this->filename.c_str(), strerror(errno));
            throw "Could not close " + this->filename;
      }
}

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index