2003-06-18 09:56:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file copy.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2003-07-28 22:37:28 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-06-18 09:56:10 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-06-18 09:56:10 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#include <fstream>
|
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
|
# include <sys/stat.h>
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::ifstream;
|
|
|
|
|
using std::ofstream;
|
|
|
|
|
using std::ios;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
bool lyx::support::chmod(string const & file, unsigned long int mode)
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_CHMOD
|
|
|
|
|
if (::chmod(file.c_str(), mode_t(mode)) != 0)
|
|
|
|
|
return false;
|
|
|
|
|
#else
|
|
|
|
|
# ifdef WITH_WARNINGS
|
|
|
|
|
# warning "File permissions are ignored on this system."
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool lyx::support::copy(string const & from, string const & to, unsigned long int mode)
|
2000-09-05 13:16:19 +00:00
|
|
|
|
{
|
2005-02-17 17:53:33 +00:00
|
|
|
|
ifstream ifs(from.c_str(), ios::binary | ios::in);
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!ifs)
|
|
|
|
|
return false;
|
2005-02-17 17:53:33 +00:00
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
if (mode != (unsigned long int)-1) {
|
|
|
|
|
ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
|
|
|
|
|
if (!ofs)
|
|
|
|
|
return false;
|
|
|
|
|
ofs.close();
|
|
|
|
|
if (!chmod(to, mode_t(mode)))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 17:53:33 +00:00
|
|
|
|
ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!ofs)
|
|
|
|
|
return false;
|
2005-02-17 17:53:33 +00:00
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
ofs << ifs.rdbuf();
|
2005-02-17 17:53:33 +00:00
|
|
|
|
return ofs.good();
|
2000-09-05 13:16:19 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|