Angus Leeming <[EMAIL PROTECTED]> writes:

| Here's support/copy.C. Do we need to flush the ofstream? 

no

| Lars, what's the official take on this?
| Irrespective of the official take, does adding a 'flush()' help?

on a buggy stdlib.. yes perhaps.

|  bool lyx::copy(string const & from, string const & to)
|  {
|      ifstream ifs(from.c_str(), ios::binary);
|      if (!ifs)
|          return false;
|      ofstream ofs(to.c_str(),
|                   ios::binary | ios::out | ios::trunc);
|      if (!ofs)
|          return false;
|      ofs << ifs.rdbuf();
| +    flush(ofs);
|      if (ofs.good())
|          return true;
|      return false;
|  }

I have never seen this fail before. So before adding hacks to it I'd
like to know _why_ and _how_ it fails.

Should be easy to create a small test prog for this:

#include <fstream>
#include <iostream>
#include <string>

using std::string;
using std::ifstream;
using std::ofstream;

bool lyx::copy(string const & from, string const & to)
{
    ifstream ifs(from.c_str(), ios::binary);
    if (!ifs)
        return false;
    ofstream ofs(to.c_str(),
                 ios::binary | ios::out | ios::trunc);
    if (!ofs)
        return false;
    ofs << ifs.rdbuf();
    if (ofs.good())
        return true;
    return false;
}

int main(int argc, char * argv[]) 
{
        bool res = lyx::copy(argv[1], argv[2]);
        if (res)
           std::cout << "copy ok" << std::endl;
        else
           std::cout << "copy NOT ok" << std::endl;

        return !res;
}

and check the size after copy.
and then figure out if it always fails, or only in some circumstances.

-- 
        Lgb

Reply via email to