diff liboctave/file-ops.cc @ 3710:9a77deefb8c9

[project @ 2000-08-02 20:47:44 by jwe]
author jwe
date Wed, 02 Aug 2000 20:47:46 +0000
parents 5eef8a2294bd
children 7c8e3c42ed04
line wrap: on
line diff
--- a/liboctave/file-ops.cc	Wed Aug 02 02:23:30 2000 +0000
+++ b/liboctave/file-ops.cc	Wed Aug 02 20:47:46 2000 +0000
@@ -42,6 +42,7 @@
 #include "file-ops.h"
 #include "oct-env.h"
 #include "oct-passwd.h"
+#include "pathlen.h"
 #include "statdefs.h"
 #include "str-vec.h"
 
@@ -110,6 +111,110 @@
   return status;
 }
 
+// I don't know how to emulate this on systems that don't provide it.
+
+int
+file_ops::link (const std::string& old_name, const std::string& new_name)
+{
+  std::string msg;
+  return link (old_name, new_name, msg);
+}
+
+int
+file_ops::link (const std::string& old_name,
+		const std::string& new_name, std::string& msg)
+{
+  msg = std::string ();
+
+  int status = -1;
+
+#if defined (HAVE_LINK)
+  status = ::link (old_name.c_str (), new_name.c_str ());
+
+  if (status < 0)
+    {
+      using namespace std;
+      msg = ::strerror (errno);
+    }
+#else
+  msg = NOT_SUPPORTED ("link");
+#endif
+
+  return status;
+}
+
+// I don't know how to emulate this on systems that don't provide it.
+
+int
+file_ops::symlink (const std::string& old_name, const std::string& new_name)
+{
+  std::string msg;
+  return symlink (old_name, new_name, msg);
+}
+
+int
+file_ops::symlink (const std::string& old_name,
+		   const std::string& new_name, std::string& msg)
+{
+  msg = std::string ();
+
+  int status = -1;
+
+#if defined (HAVE_SYMLINK)
+  status = ::symlink (old_name.c_str (), new_name.c_str ());
+
+  if (status < 0)
+    {
+      using namespace std;
+      msg = ::strerror (errno);
+    }
+#else
+  msg = NOT_SUPPORTED ("symlink");
+#endif
+
+  return status;
+}
+
+// We provide a replacement for rename().
+
+int
+file_ops::readlink (const std::string& path, std::string& result)
+{
+  std::string msg;
+  return readlink (path, result, msg);
+}
+
+int
+file_ops::readlink (const std::string& path, std::string& result,
+		    std::string& msg)
+{
+  int status = -1;
+
+  msg = std::string ();
+
+  char buf[MAXPATHLEN+1];
+
+#if defined (HAVE_READLINK)
+  status = ::readlink (path.c_str (), buf, MAXPATHLEN);
+
+  if (status < 0)
+    {
+      using namespace std;
+      msg = ::strerror (errno);
+    }
+  else
+    {
+      buf[status] = '\0';
+      result = string (buf);
+      status = 0;
+    }
+#else
+  msg = NOT_SUPPORTED ("rename");
+#endif
+
+  return status;
+}
+
 // We provide a replacement for rename().
 
 int