# HG changeset patch # User jwe # Date 965249266 0 # Node ID 9a77deefb8c9199ad42990fec88301b1b5f3c150 # Parent c73bea82af94d7af031ca116685ca2bb6dd06fa4 [project @ 2000-08-02 20:47:44 by jwe] diff -r c73bea82af94 -r 9a77deefb8c9 configure.in --- a/configure.in Wed Aug 02 02:23:30 2000 +0000 +++ b/configure.in Wed Aug 02 20:47:46 2000 +0000 @@ -21,7 +21,7 @@ ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA ### 02111-1307, USA. -AC_REVISION($Revision: 1.333 $) +AC_REVISION($Revision: 1.334 $) AC_PREREQ(2.9) AC_INIT(src/octave.cc) AC_CONFIG_HEADER(config.h) @@ -908,15 +908,15 @@ ### Checks for functions and variables. -AC_CHECK_FUNCS(atexit bcopy bzero dup2 endgrent endpwent execvp fcntl \ - fork getcwd getegid geteuid getgid getgrent getgrgid getgrnam \ - gethostname getpgrp getpid getppid getpwent getpwnam getpwuid \ - gettimeofday getuid getwd localtime_r lstat memmove mkdir mkfifo \ - on_exit pipe poll putenv rename rindex rmdir select setgrent \ - setpwent setvbuf sigaction sigpending sigprocmask sigsuspend \ - stat strcasecmp strdup strerror strftime stricmp strncasecmp \ - strnicmp strptime tempnam umask unlink usleep vfprintf vsprintf \ - vsnprintf waitpid) +AC_CHECK_FUNCS(atexit bcopy bzero dup2 endgrent endpwent execvp \ + fcntl fork getcwd getegid geteuid getgid getgrent getgrgid \ + getgrnam gethostname getpgrp getpid getppid getpwent getpwnam \ + getpwuid gettimeofday getuid getwd link localtime_r lstat \ + memmove mkdir mkfifo on_exit pipe poll putenv readlink rename \ + rindex rmdir select setgrent setpwent setvbuf sigaction sigpending \ + sigprocmask sigsuspend stat strcasecmp strdup strerror strftime \ + stricmp strncasecmp strnicmp strptime symlink tempnam umask unlink \ + usleep vfprintf vsprintf vsnprintf waitpid) OCTAVE_SMART_PUTENV diff -r c73bea82af94 -r 9a77deefb8c9 doc/interpreter/system.txi --- a/doc/interpreter/system.txi Wed Aug 02 02:23:30 2000 +0000 +++ b/doc/interpreter/system.txi Wed Aug 02 20:47:46 2000 +0000 @@ -117,6 +117,10 @@ @DOCSTRING(rename) +@DOCSTRING(link) + +@DOCSTRING(symlink) + @DOCSTRING(unlink) @DOCSTRING(readdir) diff -r c73bea82af94 -r 9a77deefb8c9 liboctave/ChangeLog --- a/liboctave/ChangeLog Wed Aug 02 02:23:30 2000 +0000 +++ b/liboctave/ChangeLog Wed Aug 02 20:47:46 2000 +0000 @@ -1,3 +1,8 @@ +2000-08-02 John W. Eaton + + * file-ops.cc (file_ops::link, file_ops::symlink, + file_ops::readlink): New functions. + 2000-08-01 John W. Eaton * Array2-idx.h (Array2::index (idx_vector&)): If a scalar is diff -r c73bea82af94 -r 9a77deefb8c9 liboctave/file-ops.cc --- 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 diff -r c73bea82af94 -r 9a77deefb8c9 liboctave/file-ops.h --- a/liboctave/file-ops.h Wed Aug 02 02:23:30 2000 +0000 +++ b/liboctave/file-ops.h Wed Aug 02 20:47:46 2000 +0000 @@ -40,6 +40,15 @@ static int mkfifo (const std::string&, mode_t); static int mkfifo (const std::string&, mode_t, std::string&); + static int link (const std::string&, const std::string&); + static int link (const std::string&, const std::string&, std::string&); + + static int symlink (const std::string&, const std::string&); + static int symlink (const std::string&, const std::string&, std::string&); + + static int readlink (const std::string&, std::string&); + static int readlink (const std::string&, std::string&, std::string&); + static int rename (const std::string&, const std::string&); static int rename (const std::string&, const std::string&, std::string&); @@ -47,7 +56,8 @@ static int rmdir (const std::string&, std::string&); static std::string tempnam (const std::string&, const std::string&); - static std::string tempnam (const std::string&, const std::string&, std::string&); + static std::string tempnam (const std::string&, const std::string&, + std::string&); typedef std::string (*tilde_expansion_hook) (const std::string&); diff -r c73bea82af94 -r 9a77deefb8c9 src/ChangeLog --- a/src/ChangeLog Wed Aug 02 02:23:30 2000 +0000 +++ b/src/ChangeLog Wed Aug 02 20:47:46 2000 +0000 @@ -1,3 +1,7 @@ +2000-08-02 John W. Eaton + + * dirfns.cc (Flink, Fsymlink, Freadlink): New functions. + 2000-08-01 John W. Eaton * load-save.cc (Vsave_header_format_string): New variable. diff -r c73bea82af94 -r 9a77deefb8c9 src/dirfns.cc --- a/src/dirfns.cc Wed Aug 02 02:23:30 2000 +0000 +++ b/src/dirfns.cc Wed Aug 02 20:47:46 2000 +0000 @@ -366,6 +366,142 @@ return retval; } +DEFUN (link, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\ +Create a new link (also known as a hard link) to an existing file.\n\ +\n\ +If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ +Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ +system-dependent error message.\n\ +@end deftypefn") +{ + octave_value_list retval; + + retval(1) = std::string (); + retval(0) = -1.0; + + if (args.length () == 2) + { + std::string from = args(0).string_value (); + + if (error_state) + gripe_wrong_type_arg ("link", args(0)); + else + { + std::string to = args(1).string_value (); + + if (error_state) + gripe_wrong_type_arg ("link", args(1)); + else + { + std::string msg; + + int status = file_ops::link (from, to, msg); + + retval(0) = static_cast (status); + + if (status < 0) + retval(1) = msg; + } + } + } + else + print_usage ("link"); + + return retval; +} + +DEFUN (symlink, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\ +Create a symbolic link @var{new} which contains the string @var{old}.\n\ +\n\ +If successful, @var{err} is 0 and @var{msg} is an empty string.\n\ +Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ +system-dependent error message.\n\ +@end deftypefn") +{ + octave_value_list retval; + + retval(1) = std::string (); + retval(0) = -1.0; + + if (args.length () == 2) + { + std::string from = args(0).string_value (); + + if (error_state) + gripe_wrong_type_arg ("symlink", args(0)); + else + { + std::string to = args(1).string_value (); + + if (error_state) + gripe_wrong_type_arg ("symlink", args(1)); + else + { + std::string msg; + + int status = file_ops::symlink (from, to, msg); + + retval(0) = static_cast (status); + + if (status < 0) + retval(1) = msg; + } + } + } + else + print_usage ("symlink"); + + return retval; +} + +DEFUN (readlink, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {[@var{result}, @var{err}, @var{msg}] =} symlink (@var{symlink})\n\ +Read the value of the symbolic link @var{symlink}.\n\ +\n\ +If successful, @var{result} contains the contents of the symbolic link\n\ +@var{symlink}, @var{err} is 0 and @var{msg} is an empty string.\n\ +Otherwise, @var{err} is nonzero and @var{msg} contains a\n\ +system-dependent error message.\n\ +@end deftypefn") +{ + octave_value_list retval; + + retval(2) = std::string (); + retval(1) = -1.0; + retval(0) = std::string (); + + if (args.length () == 1) + { + std::string symlink = args(0).string_value (); + + if (error_state) + gripe_wrong_type_arg ("readlink", args(0)); + else + { + std::string result; + std::string msg; + + int status = file_ops::readlink (symlink, result, msg); + + retval(0) = result; + + retval(1) = static_cast (status); + + if (status < 0) + retval(2) = msg; + } + } + else + print_usage ("readlink"); + + return retval; +} + DEFUN (rename, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\