changeset 1766:e8e76be43e79

[project @ 1996-01-23 03:33:34 by jwe]
author jwe
date Tue, 23 Jan 1996 03:34:14 +0000
parents a51354c34bea
children 6d9270b4fad8
files src/dirfns.cc src/file-io.cc src/oct-hist.cc src/octave.cc src/toplev.cc src/variables.cc
diffstat 6 files changed, 62 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/src/dirfns.cc
+++ b/src/dirfns.cc
@@ -53,6 +53,7 @@
 #include "defun.h"
 #include "dirfns.h"
 #include "error.h"
+#include "file-ops.h"
 #include "gripes.h"
 #include "help.h"
 #include "oct-obj.h"
@@ -60,7 +61,6 @@
 #include "pathlen.h"
 #include "procstream.h"
 #include "pt-plot.h"
-#include "statdefs.h"
 #include "sysdep.h"
 #include "sysdir.h"
 #include "toplev.h"
@@ -544,9 +544,7 @@
 	gripe_wrong_type_arg ("mkdir", args(0));
       else
 	{
-	  string tmp = oct_tilde_expand (dirname);
-
-	  int mkdir_retval = mkdir (tmp.c_str (), 0777);
+	  int mkdir_retval = xmkdir (oct_tilde_expand (dirname), 0777);
 
 	  if (mkdir_retval < 0)
 	    {
@@ -582,9 +580,7 @@
 	gripe_wrong_type_arg ("rmdir", args(0));
       else
 	{
-	  string tmp = oct_tilde_expand (dirname);
-
-	  int rmdir_retval = rmdir (tmp.c_str ());
+	  int rmdir_retval = xrmdir (oct_tilde_expand (dirname));
 
 	  if (rmdir_retval < 0)
 	    {
@@ -624,7 +620,7 @@
 
 	  if (error_state)
 	    gripe_wrong_type_arg ("rename", args(1));
-	  else if (rename (from.c_str (), to.c_str ()) < 0)
+	  else if (xrename (from, to) < 0)
 	    {
 	      status = -1;
 	      error ("%s", strerror (errno));
--- a/src/file-io.cc
+++ b/src/file-io.cc
@@ -59,6 +59,7 @@
 #include "error.h"
 #include "file-info.h"
 #include "file-io.h"
+#include "file-ops.h"
 #include "help.h"
 #include "input.h"
 #include "mappers.h"
@@ -66,14 +67,11 @@
 #include "oct-hist.h"
 #include "oct-obj.h"
 #include "pager.h"
-#include "statdefs.h"
 #include "sysdep.h"
 #include "syswait.h"
 #include "utils.h"
 #include "variables.h"
 
-extern "C" void mode_string ();
-
 // keeps a count of args sent to printf or scanf
 static int fmt_arg_count = 0;
 
@@ -195,20 +193,22 @@
 	{
 	  string name = arg.string_value ();
 
-	  struct stat buffer;
-	  int status = stat (name.c_str (), &buffer);
-
-	  if (status == 0)
+	  file_stat fs (name);
+
+	  if (fs)
 	    {
-	      if ((buffer.st_mode & S_IFREG) == S_IFREG)
+	      if (fs.is_reg ())
 		p = fopen_file_for_user (name, mode, warn_for);
 	      else
 		error ("%s: invalid file type", warn_for);
 	    }
-	  else if (status < 0 && *mode != 'r')
-	    p = fopen_file_for_user (name, mode, warn_for);
 	  else
-	    error ("%s: can't stat file `%s'", warn_for, name.c_str ());
+	    {
+	      if (*mode != 'r')
+		p = fopen_file_for_user (name, mode, warn_for);
+	      else
+		error ("%s: can't stat file `%s'", warn_for, name.c_str ());
+	    }
 	}
       else
 	error ("%s: invalid file specifier", warn_for);
@@ -489,9 +489,9 @@
       return retval;
     }
 
-  struct stat buffer;
-  if (stat (name.c_str (), &buffer) == 0
-      && (buffer.st_mode & S_IFDIR) == S_IFDIR)
+  file_stat fs (name);
+
+  if (fs && fs.is_dir ())
     {
       error ("fopen: can't open directory");
       return retval;
@@ -1960,9 +1960,9 @@
       return retval;
     }
 
-  struct stat buffer;
-  if (stat (name.c_str (), &buffer) == 0
-      && (buffer.st_mode & S_IFDIR) == S_IFDIR)
+  file_stat fs (name);
+
+  if (fs && fs.is_dir ())
     {
       error ("popen: can't open directory");
       return retval;
@@ -2345,7 +2345,7 @@
 
   long mode = (long) args(1).double_value ();
 
-  retval (0) = (double) mkfifo (name.c_str (), mode);
+  retval (0) = (double) xmkfifo (name, mode);
 
   return retval;
 }
@@ -2414,32 +2414,28 @@
 }
 
 static Octave_map
-mk_stat_map (struct stat& st)
+mk_stat_map (const file_stat& fs)
 {
   Octave_map m;
 
-  char mode_as_string[11];
-  mode_string (st.st_mode, mode_as_string);
-  mode_as_string[10] = '\0';
-
-  m["dev"] = (double) st.st_dev;
-  m["ino"] = (double) st.st_ino;
-  m["modestr"] = mode_as_string;
-  m["nlink"] = (double) st.st_nlink;
-  m["uid"] = (double) st.st_uid;
-  m["gid"] = (double) st.st_gid;
+  m["dev"] = (double) fs.dev ();
+  m["ino"] = (double) fs.ino ();
+  m["modestr"] = fs.mode_as_string ();
+  m["nlink"] = (double) fs.nlink ();
+  m["uid"] = (double) fs.uid ();
+  m["gid"] = (double) fs.gid ();
 #if defined (HAVE_ST_RDEV)
-  m["rdev"] = (double) st.st_rdev;
+  m["rdev"] = (double) fs.rdev ();
 #endif
-  m["size"] = (double) st.st_size;
-  m["atime"] = (double) st.st_atime;
-  m["mtime"] = (double) st.st_mtime;
-  m["ctime"] = (double) st.st_ctime;
+  m["size"] = (double) fs.size ();
+  m["atime"] = (double) fs.atime ();
+  m["mtime"] = (double) fs.mtime ();
+  m["ctime"] = (double) fs.ctime ();
 #if defined (HAVE_ST_BLKSIZE)
-  m["blksize"] = (double) st.st_blksize;
+  m["blksize"] = (double) fs.blksize ();
 #endif
 #if defined (HAVE_ST_BLOCKS)
-  m["blocks"] = (double) st.st_blocks;
+  m["blocks"] = (double) fs.blocks ();
 #endif
 
   return m;
@@ -2475,12 +2471,12 @@
 
       if (! error_state)
 	{
-	  struct stat buf;
-
-	  if (stat (fname.c_str (), &buf) < 0)
+	  file_stat fs (fname);
+
+	  if (fs)
+	    retval = tree_constant (mk_stat_map (fs));
+	  else
 	    retval = -1.0;
-	  else
-	    retval = tree_constant (mk_stat_map (buf));
 	}
     }
   else
@@ -2503,12 +2499,12 @@
 
       if (! error_state)
 	{
-	  struct stat buf;
-
-	  if (lstat (fname.c_str (), &buf) < 0)
+	  file_stat fs (fname);
+
+	  if (fs)
+	    retval = tree_constant (mk_stat_map (fs));
+	  else
 	    retval = -1.0;
-	  else
-	    retval = tree_constant (mk_stat_map (buf));
 	}
     }
   else
@@ -2582,9 +2578,7 @@
 	      int oct_mask = convert (mask, 8, 10);
 
 	      if (! error_state)
-#if defined (HAVE_UMASK)
-		status = convert (umask (oct_mask), 10, 8);
-#endif
+		status = convert (xumask (oct_mask), 10, 8);
 	    }
 	}
     }
--- a/src/oct-hist.cc
+++ b/src/oct-hist.cc
@@ -54,12 +54,12 @@
 
 #include "defun.h"
 #include "error.h"
+#include "file-ops.h"
 #include "input.h"
 #include "oct-hist.h"
 #include "oct-obj.h"
 #include "pager.h"
 #include "sighandlers.h"
-#include "statdefs.h"
 #include "sysdep.h"
 #include "toplev.h"
 #include "unwind-prot.h"
@@ -195,9 +195,9 @@
 		      {
 			// Create file if it doesn't already exist.
 
-			struct stat buf;
+			file_stat fs (file);
 
-			if (stat (file.c_str (), &buf) == -1)
+			if (! fs)
 			  {
 			    int tem;
 
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -55,6 +55,7 @@
 #include "dynamic-ld.h"
 #include "error.h"
 #include "file-io.h"
+#include "file-ops.h"
 #include "help.h"
 #include "input.h"
 #include "lex.h"
@@ -65,7 +66,6 @@
 #include "pathsearch.h"
 #include "procstream.h"
 #include "sighandlers.h"
-#include "statdefs.h"
 #include "sysdep.h"
 #include "pt-const.h"
 #include "pt-misc.h"
@@ -241,14 +241,15 @@
 
       // Names alone are not enough.
 
-      struct stat home_rc_statbuf;
-      stat (home_rc.c_str (), &home_rc_statbuf);
+      file_stat fs_home_rc (home_rc);
 
-      struct stat dot_rc_statbuf;
-      stat ("./.octaverc", &dot_rc_statbuf);
+      if (fs_home_rc)
+	{
+	  file_stat fs_dot_rc ("./.octaverc");
 
-      if (home_rc_statbuf.st_ino == dot_rc_statbuf.st_ino)
-	home_rc_already_executed = 1;
+	  if (fs_dot_rc && fs_home_rc.ino () == fs_dot_rc.ino ())
+	    home_rc_already_executed = 1;
+	}
     }
 
   if (! home_rc_already_executed)
--- a/src/toplev.cc
+++ b/src/toplev.cc
@@ -64,7 +64,6 @@
 #include "pt-misc.h"
 #include "pt-plot.h"
 #include "sighandlers.h"
-#include "statdefs.h"
 #include "sysdep.h"
 #include "toplev.h"
 #include "unwind-prot.h"
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -49,6 +49,7 @@
 #include "dirfns.h"
 #include "dynamic-ld.h"
 #include "error.h"
+#include "file-ops.h"
 #include "help.h"
 #include "input.h"
 #include "lex.h"
@@ -57,7 +58,6 @@
 #include "toplev.h"
 #include "pager.h"
 #include "parse.h"
-#include "statdefs.h"
 #include "symtab.h"
 #include "sysdep.h"
 #include "pt-const.h"
@@ -283,8 +283,9 @@
 	    }
 	  else
 	    {
-	      struct stat buf;
-	      if (stat (name.c_str (), &buf) == 0 && S_ISREG (buf.st_mode))
+	      file_stat fs (name);
+
+	      if (fs && fs.is_reg ())
 		retval = 2.0;
 	    }
 	}