]> git.lyx.org Git - lyx.git/blobdiff - src/support/copy.C
hopefully fix tex2lyx linking.
[lyx.git] / src / support / copy.C
index 7324d445681efc00ab011cf22b5a32e9714fb75f..ceb2db196800006519a88b3be374f39fa484eae9 100644 (file)
@@ -1,27 +1,72 @@
+/**
+ * \file copy.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
 #include <config.h>
 
 #include <fstream>
 
-//#include <stdio.h>
-
 #include "support/lyxlib.h"
-#include "LString.h"
-//#include "support/syscall.h"
-#include "support/filetools.h"
 
-bool lyx::copy(string const & from, string const & to)
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+
+namespace lyx {
+
+
+using std::ifstream;
+using std::ofstream;
+using std::ios;
+using std::string;
+
+
+bool lyx::support::chmod(string const & file, unsigned long int mode)
 {
-#if 0
-       string command = "cp " + QuoteName(from) + " " + QuoteName(to);
-       return Systemcalls().startscript(Systemcalls::System,
-                                        command) == 0;
+#ifdef HAVE_CHMOD
+       if (::chmod(file.c_str(), mode_t(mode)) != 0)
+               return false;
 #else
-       std::ifstream ifs(from.c_str());
-       if (!ifs) return false;
-       std::ofstream ofs(to.c_str(), std::ios::out|std::ios::trunc);
-       if (!ofs) return false;
-       ofs << ifs.rdbuf();
-       if (ofs.good()) return true;
-       return false;
+# 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)
+{
+       ifstream ifs(from.c_str(), ios::binary | ios::in);
+       if (!ifs)
+               return false;
+
+       if (mode != (unsigned long int)-1) {
+               ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
+               if (!ofs)
+                       return false;
+               ofs.close();
+               if (!support::chmod(to, mode))
+                       return false;
+       }
+
+       ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
+       if (!ofs)
+               return false;
+
+       ofs << ifs.rdbuf();
+       return ofs.good();
+}
+
+
+} // namespace lyx