Ignore:
Timestamp:
Aug 21, 2007, 9:56:06 AM (14 years ago)
Author:
Jari Häkkinen
Message:

Refs #251.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.6-stable/lib/utility.cc

    r430 r456  
    6161
    6262
     63  void copy_file(const std::string& source, const std::string& target)
     64  {
     65    std::ofstream o(target.c_str());
     66    std::ifstream i(source.c_str());
     67    while (i.good()) {
     68      char ch=i.get();
     69      if (i.good())
     70        o.put(ch);
     71      if (!o.good())
     72        throw std::runtime_error(std::string("copy_file: ") +
     73                                 "writing target file failed '" + target + "'");
     74    }
     75    if (!i.eof() && (i.bad() || i.fail()))  // fail on everything except eof
     76      throw std::runtime_error(std::string("copy_file: ") +
     77                               "error reading source file '" + source + "'");
     78    i.close(); o.close();
     79  }
     80
     81
    6382  std::string file_name(const std::string& full_path)
    6483  {
Note: See TracChangeset for help on using the changeset viewer.