31#if defined (HAVE_CONFIG_H)
65mk_stat_map (
const sys::base_file_stat& fs)
68 = sys::base_file_stat::have_struct_stat_st_rdev ();
69 static bool have_blksize
70 = sys::base_file_stat::have_struct_stat_st_blksize ();
71 static bool have_blocks
72 = sys::base_file_stat::have_struct_stat_st_blocks ();
74 static double nan = numeric_limits<double>::NaN ();
78 m.
assign (
"dev",
static_cast<double> (fs.dev ()));
79 m.
assign (
"ino", fs.ino ());
80 m.
assign (
"mode", fs.mode ());
81 m.
assign (
"modestr", fs.mode_as_string ());
82 m.
assign (
"nlink", fs.nlink ());
83 m.
assign (
"uid", fs.uid ());
84 m.
assign (
"gid", fs.gid ());
85 m.
assign (
"rdev", have_rdev ?
static_cast<double> (fs.rdev ()) : nan);
86 m.
assign (
"size", fs.size ());
87 m.
assign (
"atime", fs.atime ());
88 m.
assign (
"mtime", fs.mtime ());
89 m.
assign (
"ctime", fs.ctime ());
92 m.
assign (
"blksize", fs.blksize ());
97 m.
assign (
"blocks", fs.blocks ());
105mk_stat_result (
const sys::base_file_stat& fs)
124 if (args.length () != 2)
142 i_old = args(0).int_value (
true);
143 i_new = args(1).int_value (
true);
146 if (i_old < 0 || i_new < 0)
152 int status = sys::dup2 (i_old, i_new, msg);
154 return ovl (status, msg);
178 int nargin = args.length ();
180 if (nargin < 1 || nargin > 2)
183 std::string exec_file = args(0).xstring_value (
"exec: FILE must be a string");
189 string_vector tmp = args(1).xstring_vector_value (
"exec: all arguments must be strings");
195 exec_args[0] = exec_file;
197 for (
int i = 0; i <
len; i++)
198 exec_args[i+1] = tmp[i];
204 exec_args[0] = exec_file;
216 int status = sys::execvp (exec_file, exec_args, msg);
218 return ovl (status, msg);
268 int nargin = args.length ();
270 if (nargin < 1 || nargin > 3)
273 std::string exec_file = args(0).xstring_value (
"popen2: COMMAND argument must be a string");
279 string_vector tmp = args(1).xstring_vector_value (
"popen2: all arguments must be strings");
285 arg_list[0] = exec_file;
287 for (
int i = 0; i <
len; i++)
288 arg_list[i+1] = tmp[i];
294 arg_list[0] = exec_file;
297 bool sync_mode = (nargin == 3 ? args(2).bool_value () :
false);
303 pid = sys::popen2 (exec_file, arg_list, sync_mode, filedesc, msg);
306 error (
"%s", msg.c_str ());
308 FILE *ifile = fdopen (filedesc[1],
"r");
309 FILE *ofile = fdopen (filedesc[0],
"w");
448 if (args.length () != 3)
462 fid = args(0).int_value (
true);
466 error (
"fcntl: invalid file id FID");
468 int req = args(1).strict_int_value (
"fcntl: REQUEST must be an integer");
469 int arg = args(2).strict_int_value (
"fcntl: ARG must be an integer");
474 int status = sys::fcntl (fid, req, arg, msg);
479 error (
"fcntl: operation failed: %s", msg.c_str ());
484 retval =
ovl (-1.0, msg);
486 retval =
ovl (status,
"");
515 if (args.length () != 0)
518 if (interp.at_top_level ())
519 error (
"fork: cannot be called from command line");
523 pid_t pid = sys::fork (msg);
525 return ovl (pid, msg);
534 if (args.length () != 0)
539 pid_t pid = sys::getpgrp (msg);
541 return ovl (pid, msg);
551 if (args.length () != 0)
554 return ovl (sys::getpid ());
564 if (args.length () != 0)
567 return ovl (sys::getppid ());
577 if (args.length () != 0)
580 return ovl (sys::getegid ());
590 if (args.length () != 0)
593 return ovl (sys::getgid ());
603 if (args.length () != 0)
606 return ovl (sys::geteuid ());
616 if (args.length () != 0)
619 return ovl (sys::getuid ());
647 if (args.length () != 2)
650 pid_t pid = args(0).int_value (
true);
652 int sig = args(1).int_value (
true);
657 int status = sys::kill (pid, sig, msg);
662 error (
"kill: operation failed: %s", msg.c_str ());
667 retval =
ovl (-1.0, msg);
669 retval =
ovl (0.0,
"");
686 if (args.length () != 1)
689 std::string fname = args(0).xstring_value (
"lstat: NAME must be a string");
691 sys::file_stat fs (fname,
false);
693 return mk_stat_result (fs);
699convert (
int x,
int ibase,
int obase)
706 error (
"mkfifo: invalid digit");
710 while ((
x = (
x - tmp) / obase))
715 error (
"mkfifo: invalid digit");
717 retval += mult * tmp;
739 if (args.length () != 2)
742 std::string name = args(0).xstring_value (
"mkfifo: FILE must be a string");
744 int octal_mode = args(1).strict_int_value (
"mkfifo: MODE must be an integer");
747 error (
"mkfifo: MODE must be a positive integer value");
749 int mode = convert (octal_mode, 8, 10);
754 int status = sys::mkfifo (name, mode, msg);
759 error (
"mkfifo: operation failed: %s", msg.c_str ());
764 retval =
ovl (-1.0, msg);
766 retval =
ovl (0.0,
"");
797 if (args.length () != 0)
803 int status = sys::pipe (fid, msg);
806 return ovl (-1, -1, -1, msg);
809 FILE *ifile = fdopen (fid[0],
"r");
810 FILE *ofile = fdopen (fid[1],
"w");
918 if (args.length () != 1)
923 if (args(0).is_scalar_type ())
935 fid = args(0).int_value (
true);
939 error (
"stat: invalid file id FID");
941 sys::file_fstat fs (fid);
943 retval = mk_stat_result (fs);
947 std::string fname = args(0).xstring_value (
"stat: NAME must be a string");
949 sys::file_stat fs (fname);
951 retval = mk_stat_result (fs);
967 if (args.length () != 1)
970 double mode = args(0).xdouble_value (
"S_ISREG: invalid MODE value");
972 return ovl (sys::file_stat::is_reg (
static_cast<mode_t
> (mode)));
985 if (args.length () != 1)
988 double mode = args(0).xdouble_value (
"S_ISDIR: invalid MODE value");
990 return ovl (sys::file_stat::is_dir (
static_cast<mode_t
> (mode)));
1003 if (args.length () != 1)
1006 double mode = args(0).xdouble_value (
"S_ISCHR: invalid MODE value");
1008 return ovl (sys::file_stat::is_chr (
static_cast<mode_t
> (mode)));
1021 if (args.length () != 1)
1024 double mode = args(0).xdouble_value (
"S_ISBLK: invalid MODE value");
1026 return ovl (sys::file_stat::is_blk (
static_cast<mode_t
> (mode)));
1039 if (args.length () != 1)
1042 double mode = args(0).xdouble_value (
"S_ISFIFO: invalid MODE value");
1044 return ovl (sys::file_stat::is_fifo (
static_cast<mode_t
> (mode)));
1057 if (args.length () != 1)
1060 double mode = args(0).xdouble_value (
"S_ISLNK: invalid MODE value");
1062 return ovl (sys::file_stat::is_lnk (
static_cast<mode_t
> (mode)));
1075 if (args.length () != 1)
1078 double mode = args(0).xdouble_value (
"S_ISSOCK: invalid MODE value");
1080 return ovl (sys::file_stat::is_sock (
static_cast<mode_t
> (mode)));
1083DEFUN (gethostname, args, ,
1089 if (args.length () != 0)
1092 return ovl (sys::env::get_host_name ());
1120 if (args.length () != 0)
1127 m.
assign (
"sysname", sysinfo.sysname ());
1128 m.
assign (
"nodename", sysinfo.nodename ());
1129 m.
assign (
"release", sysinfo.release ());
1130 m.
assign (
"version", sysinfo.version ());
1131 m.
assign (
"machine", sysinfo.machine ());
1133 return ovl (m, sysinfo.error (), sysinfo.message ());
1157 if (args.length () != 1)
1160 std::string name = args(0).xstring_value (
"unlink: FILE must be a string");
1169 int status = sys::unlink (name, msg);
1176 error (
"unlink: operation failed: %s", msg.c_str ());
1181 retval =
ovl (-1.0, msg);
1183 retval =
ovl (0.0,
"");
1256 int nargin = args.
length ();
1258 if (nargin != 1 && nargin != 2)
1261 pid_t pid = args(0).strict_int_value (
"waitpid: OPTIONS must be an integer");
1266 options = args(1).strict_int_value (
"waitpid: PID must be an integer value");
1271 pid_t result = sys::waitpid (pid, &status, options, msg);
1273 return ovl (result, status, msg);
1285 if (args.length () != 1)
1288 int status = args(0).strict_int_value (
"WIFEXITED: STATUS must be an integer");
1290 return ovl (sys::wifexited (status));
1304 if (args.length () != 1)
1307 int status = args(0).strict_int_value (
"WEXITSTATUS: STATUS must be an integer");
1309 return ovl (sys::wexitstatus (status));
1321 if (args.length () != 1)
1324 int status = args(0).strict_int_value (
"WIFSIGNALED: STATUS must be an integer");
1326 return ovl (sys::wifsignaled (status));
1340 if (args.length () != 1)
1343 int status = args(0).strict_int_value (
"WTERMSIG: STATUS must be an integer");
1345 return ovl (sys::wtermsig (status));
1361 if (args.length () != 1)
1364 int status = args(0).strict_int_value (
"WCOREDUMP: STATUS must be an integer");
1366 return ovl (sys::wcoredump (status));
1381 if (args.length () != 1)
1384 int status = args(0).strict_int_value (
"WIFSTOPPED: STATUS must be an integer");
1386 return ovl (sys::wifstopped (status));
1400 if (args.length () != 1)
1403 int status = args(0).strict_int_value (
"WSTOPSIG: STATUS must be an integer");
1405 return ovl (sys::wstopsig (status));
1417 if (args.length () != 1)
1420 int status = args(0).strict_int_value (
"WIFCONTINUED: STATUS must be an integer");
1422 return ovl (sys::wifcontinued (status));
1436 if (args.length () != 1)
1439 std::string name = args(0).xstring_value (
"canonicalize_file_name: NAME must be a string");
1443 std::string result = sys::canonicalize_file_name (name, msg);
1445 return ovl (result, msg.empty () ? 0 : -1, msg);
1470 return const_value (args, val);
1486 return const_value (args, val);
1502 return const_value (args, val);
1518 return const_value (args, val);
1534 return const_value (args, val);
1554 return const_value (args, val);
1573 return const_value (args, val);
1593 return const_value (args, val);
1612 return const_value (args, val);
1632 return const_value (args, val);
1651 return const_value (args, val);
1671 return const_value (args, val);
1690 return const_value (args, val);
1710 return const_value (args, val);
1729 return const_value (args, val);
1743 return const_value (args, sys::wnohang ());
1757 return const_value (args, sys::wuntraced ());
1771 return const_value (args, sys::wcontinue ());
1774OCTAVE_END_NAMESPACE(octave)
static bool ignoring_entries()
static void clean_up_and_save(const std::string &="", int=-1)
Provides threadsafe access to octave.
void file_renamed(bool load_new)
void file_remove(const std::string &old_name, const std::string &new_name)
void assign(const std::string &k, const octave_value &val)
octave_idx_type length() const
static stream create(const std::string &n, FILE *f=nullptr, std::ios::openmode m=std::ios::in|std::ios::out, mach_info::float_format ff=mach_info::native_float_format(), const std::string &encoding="utf-8", c_file_ptr_buf::close_fcn cf=c_file_ptr_buf::file_close)
int get_file_number(const octave_value &fid) const
stream lookup(int fid, const std::string &who="") const
void resize(octave_idx_type n, const std::string &rfv="")
octave_idx_type numel() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
#define DEFMETHODX(name, fname, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method with certain internal name.
void error(const char *fmt,...)
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
int octave_o_trunc_wrapper(void)
int octave_f_dupfd_wrapper(void)
int octave_o_wronly_wrapper(void)
int octave_o_creat_wrapper(void)
int octave_o_append_wrapper(void)
int octave_o_sync_wrapper(void)
int octave_o_nonblock_wrapper(void)
int octave_o_excl_wrapper(void)
int octave_f_getfd_wrapper(void)
int octave_o_rdonly_wrapper(void)
int octave_f_setfd_wrapper(void)
int octave_o_rdwr_wrapper(void)
int octave_f_setfl_wrapper(void)
int octave_o_async_wrapper(void)
int octave_f_getfl_wrapper(void)
F77_RET_T const F77_DBLE * x
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
octave_value_list FF_SETFL(const octave_value_list &args, int)
octave_value_list Fwaitpid(const octave_value_list &args, int)
octave_value_list Fdup2(octave::interpreter &interp, const octave_value_list &args, int)
octave_value_list Fgetuid(const octave_value_list &args, int)
octave_value_list FWCONTINUE(const octave_value_list &args, int)
octave_value_list FO_RDWR(const octave_value_list &args, int)
octave_value_list FS_ISREG(const octave_value_list &args, int)
octave_value_list FF_GETFD(const octave_value_list &args, int)
octave_value_list FS_ISSOCK(const octave_value_list &args, int)
octave_value_list Fpopen2(octave::interpreter &interp, const octave_value_list &args, int)
octave_value_list FWIFSIGNALED(const octave_value_list &args, int)
octave_value_list FO_RDONLY(const octave_value_list &args, int)
octave_value_list FO_WRONLY(const octave_value_list &args, int)
octave_value_list FO_NONBLOCK(const octave_value_list &args, int)
octave_value_list FWIFCONTINUED(const octave_value_list &args, int)
octave_value_list Fgetegid(const octave_value_list &args, int)
octave_value_list FF_DUPFD(const octave_value_list &args, int)
octave_value_list FWIFEXITED(const octave_value_list &args, int)
octave_value_list FS_ISCHR(const octave_value_list &args, int)
octave_value_list Funlink(octave::interpreter &interp, const octave_value_list &args, int nargout)
octave_value_list FO_TRUNC(const octave_value_list &args, int)
octave_value_list Fgetppid(const octave_value_list &args, int)
octave_value_list Fgetgid(const octave_value_list &args, int)
octave_value_list Fgeteuid(const octave_value_list &args, int)
octave_value_list Fmkfifo(const octave_value_list &args, int nargout)
octave_value_list FWCOREDUMP(const octave_value_list &args, int)
octave_value_list FF_SETFD(const octave_value_list &args, int)
octave_value_list Flstat(const octave_value_list &args, int)
octave_value_list FS_ISFIFO(const octave_value_list &args, int)
octave_value_list FS_ISBLK(const octave_value_list &args, int)
octave_value_list FWSTOPSIG(const octave_value_list &args, int)
octave_value_list FWUNTRACED(const octave_value_list &args, int)
octave_value_list Fgetpgrp(const octave_value_list &args, int)
octave_value_list Fkill(const octave_value_list &args, int nargout)
octave_value_list FWTERMSIG(const octave_value_list &args, int)
octave_value_list FWNOHANG(const octave_value_list &args, int)
octave_value_list FO_CREAT(const octave_value_list &args, int)
octave_value_list Fcanonicalize_file_name(const octave_value_list &args, int)
octave_value_list FO_ASYNC(const octave_value_list &args, int)
octave_value_list FWIFSTOPPED(const octave_value_list &args, int)
octave_value_list Ffcntl(octave::interpreter &interp, const octave_value_list &args, int nargout)
octave_value_list FO_APPEND(const octave_value_list &args, int)
octave_value_list FO_SYNC(const octave_value_list &args, int)
octave_value_list FF_GETFL(const octave_value_list &args, int)
octave_value_list Fpipe(octave::interpreter &interp, const octave_value_list &args, int)
octave_value_list FS_ISLNK(const octave_value_list &args, int)
octave_value_list Ffork(octave::interpreter &interp, const octave_value_list &args, int)
octave_value_list Fstat(octave::interpreter &interp, const octave_value_list &args, int)
octave_value_list FS_ISDIR(const octave_value_list &args, int)
octave_value_list Fgetpid(const octave_value_list &args, int)
octave_value_list Fexec(octave::interpreter &interp, const octave_value_list &args, int)
octave_value_list FWEXITSTATUS(const octave_value_list &args, int)
octave_value_list FO_EXCL(const octave_value_list &args, int)