31 #if defined (HAVE_CONFIG_H)
65 mk_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 ();
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 ());
94 m.assign (
"blksize", nan);
97 m.assign (
"blocks", fs.blocks ());
99 m.assign (
"blocks", nan);
105 mk_stat_result (
const sys::base_file_stat& fs)
124 if (args.length () != 2)
136 if (i_old >= 0 && i_new >= 0)
140 int status =
sys::dup2 (i_old, i_new, msg);
142 return ovl (status, msg);
169 int nargin = args.length ();
171 if (nargin < 1 || nargin > 2)
174 std::string exec_file = args(0).xstring_value (
"exec: FILE must be a string");
180 string_vector tmp = args(1).xstring_vector_value (
"exec: all arguments must be strings");
186 exec_args[0] = exec_file;
188 for (
int i = 0; i <
len; i++)
189 exec_args[i+1] = tmp[i];
195 exec_args[0] = exec_file;
207 int status =
sys::execvp (exec_file, exec_args, msg);
209 return ovl (status, msg);
259 int nargin = args.length ();
261 if (nargin < 1 || nargin > 3)
264 std::string exec_file = args(0).xstring_value (
"popen2: COMMAND argument must be a string");
270 string_vector tmp = args(1).xstring_vector_value (
"popen2: all arguments must be strings");
276 arg_list[0] = exec_file;
278 for (
int i = 0; i <
len; i++)
279 arg_list[i+1] = tmp[i];
285 arg_list[0] = exec_file;
288 bool sync_mode = (nargin == 3 ? args(2).bool_value () :
false);
294 pid =
sys::popen2 (exec_file, arg_list, sync_mode, filedesc, msg);
297 error (
"%s", msg.c_str ());
299 FILE *ifile = fdopen (filedesc[1],
"r");
300 FILE *ofile = fdopen (filedesc[0],
"w");
439 if (args.length () != 3)
450 int req = args(1).int_value (
true);
451 int arg = args(2).int_value (
true);
455 error (
"fcntl: invalid file id");
465 error (
"fcntl: operation failed: %s", msg.c_str ());
470 retval =
ovl (-1.0, msg);
472 retval =
ovl (0.0,
"");
501 if (args.length () != 0)
504 if (interp.at_top_level ())
505 error (
"fork: cannot be called from command line");
511 return ovl (pid, msg);
520 if (args.length () != 0)
527 return ovl (pid, msg);
537 if (args.length () != 0)
550 if (args.length () != 0)
563 if (args.length () != 0)
576 if (args.length () != 0)
589 if (args.length () != 0)
602 if (args.length () != 0)
633 if (args.length () != 2)
636 pid_t pid = args(0).int_value (
true);
638 int sig = args(1).int_value (
true);
648 error (
"kill: operation failed: %s", msg.c_str ());
653 retval =
ovl (-1.0, msg);
655 retval =
ovl (0.0,
"");
672 if (args.length () != 1)
675 std::string fname = args(0).xstring_value (
"lstat: NAME must be a string");
677 sys::file_stat fs (fname,
false);
679 return mk_stat_result (fs);
685 convert (
int x,
int ibase,
int obase)
692 error (
"mkfifo: invalid digit");
696 while ((
x = (
x - tmp) / obase))
701 error (
"mkfifo: invalid digit");
703 retval += mult * tmp;
725 if (args.length () != 2)
728 std::string name = args(0).xstring_value (
"mkfifo: FILE must be a string");
730 int octal_mode = args(1).xint_value (
"mkfifo: MODE must be an integer");
733 error (
"mkfifo: MODE must be a positive integer value");
735 int mode = convert (octal_mode, 8, 10);
745 error (
"mkfifo: operation failed: %s", msg.c_str ());
750 retval =
ovl (-1.0, msg);
752 retval =
ovl (0.0,
"");
783 if (args.length () != 0)
792 return ovl (-1, -1, -1, msg);
795 FILE *ifile = fdopen (fid[0],
"r");
796 FILE *ofile = fdopen (fid[1],
"w");
904 if (args.length () != 1)
909 if (args(0).is_scalar_type ())
915 sys::file_fstat fs (fid);
917 retval = mk_stat_result (fs);
921 std::string fname = args(0).xstring_value (
"stat: NAME must be a string");
923 sys::file_stat fs (fname);
925 retval = mk_stat_result (fs);
941 if (args.length () != 1)
944 double mode = args(0).xdouble_value (
"S_ISREG: invalid MODE value");
946 return ovl (sys::file_stat::is_reg (
static_cast<mode_t
> (mode)));
959 if (args.length () != 1)
962 double mode = args(0).xdouble_value (
"S_ISDIR: invalid MODE value");
964 return ovl (sys::file_stat::is_dir (
static_cast<mode_t
> (mode)));
977 if (args.length () != 1)
980 double mode = args(0).xdouble_value (
"S_ISCHR: invalid MODE value");
982 return ovl (sys::file_stat::is_chr (
static_cast<mode_t
> (mode)));
995 if (args.length () != 1)
998 double mode = args(0).xdouble_value (
"S_ISBLK: invalid MODE value");
1000 return ovl (sys::file_stat::is_blk (
static_cast<mode_t
> (mode)));
1013 if (args.length () != 1)
1016 double mode = args(0).xdouble_value (
"S_ISFIFO: invalid MODE value");
1018 return ovl (sys::file_stat::is_fifo (
static_cast<mode_t
> (mode)));
1031 if (args.length () != 1)
1034 double mode = args(0).xdouble_value (
"S_ISLNK: invalid MODE value");
1036 return ovl (sys::file_stat::is_lnk (
static_cast<mode_t
> (mode)));
1049 if (args.length () != 1)
1052 double mode = args(0).xdouble_value (
"S_ISSOCK: invalid MODE value");
1054 return ovl (sys::file_stat::is_sock (
static_cast<mode_t
> (mode)));
1057 DEFUN (gethostname, args, ,
1063 if (args.length () != 0)
1066 return ovl (sys::env::get_host_name ());
1094 if (args.length () != 0)
1101 m.assign (
"sysname", sysinfo.sysname ());
1102 m.assign (
"nodename", sysinfo.nodename ());
1103 m.assign (
"release", sysinfo.release ());
1104 m.assign (
"version", sysinfo.version ());
1105 m.assign (
"machine", sysinfo.machine ());
1107 return ovl (
m, sysinfo.error (), sysinfo.message ());
1131 if (args.length () != 1)
1134 std::string name = args(0).xstring_value (
"unlink: FILE must be a string");
1150 error (
"unlink: operation failed: %s", msg.c_str ());
1155 retval =
ovl (-1.0, msg);
1157 retval =
ovl (0.0,
"");
1230 int nargin = args.length ();
1232 if (nargin != 1 && nargin != 2)
1235 pid_t pid = args(0).xint_value (
"waitpid: OPTIONS must be an integer");
1240 options = args(1).xint_value (
"waitpid: PID must be an integer value");
1245 pid_t result =
sys::waitpid (pid, &status, options, msg);
1247 return ovl (result, status, msg);
1259 if (args.length () != 1)
1262 int status = args(0).xint_value (
"WIFEXITED: STATUS must be an integer");
1278 if (args.length () != 1)
1281 int status = args(0).xint_value (
"WEXITSTATUS: STATUS must be an integer");
1295 if (args.length () != 1)
1298 int status = args(0).xint_value (
"WIFSIGNALED: STATUS must be an integer");
1314 if (args.length () != 1)
1317 int status = args(0).xint_value (
"WTERMSIG: STATUS must be an integer");
1335 if (args.length () != 1)
1338 int status = args(0).xint_value (
"WCOREDUMP: STATUS must be an integer");
1355 if (args.length () != 1)
1358 int status = args(0).xint_value (
"WIFSTOPPED: STATUS must be an integer");
1374 if (args.length () != 1)
1377 int status = args(0).xint_value (
"WSTOPSIG: STATUS must be an integer");
1391 if (args.length () != 1)
1394 int status = args(0).xint_value (
"WIFCONTINUED: STATUS must be an integer");
1410 if (args.length () != 1)
1413 std::string name = args(0).xstring_value (
"canonicalize_file_name: NAME must be a string");
1419 return ovl (result, msg.empty () ? 0 : -1, msg);
1444 return const_value (args, val);
1460 return const_value (args, val);
1476 return const_value (args, val);
1492 return const_value (args, val);
1508 return const_value (args, val);
1528 return const_value (args, val);
1547 return const_value (args, val);
1567 return const_value (args, val);
1586 return const_value (args, val);
1606 return const_value (args, val);
1625 return const_value (args, val);
1645 return const_value (args, val);
1664 return const_value (args, val);
1684 return const_value (args, val);
1703 return const_value (args, val);
1748 OCTAVE_END_NAMESPACE(
octave)
octave_value_list FO_NONBLOCK(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_ASYNC(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_EXCL(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fgetuid(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fpipe(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list FF_SETFD(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fgetppid(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWCONTINUE(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWCOREDUMP(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fdup2(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWTERMSIG(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FF_DUPFD(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fgetpgrp(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWIFCONTINUED(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fmkfifo(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fpopen2(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Flstat(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fkill(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_TRUNC(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fwaitpid(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fgetgid(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FS_ISSOCK(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_RDONLY(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_APPEND(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWIFSIGNALED(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_WRONLY(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fstat(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list FS_ISFIFO(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Funlink(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fgetpid(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FF_SETFL(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FS_ISBLK(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWIFSTOPPED(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Ffork(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_RDWR(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FS_ISDIR(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fexec(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWNOHANG(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWIFEXITED(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FS_ISLNK(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fgeteuid(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FS_ISREG(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FF_GETFD(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Ffcntl(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list FS_ISCHR(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_SYNC(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fcanonicalize_file_name(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWSTOPSIG(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWUNTRACED(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fgetegid(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FF_GETFL(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FO_CREAT(const octave_value_list &=octave_value_list(), int=0)
octave_value_list FWEXITSTATUS(const octave_value_list &=octave_value_list(), int=0)
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)
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.
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
std::string canonicalize_file_name(const std::string &name)
int mkfifo(const std::string &nm, mode_t md)
int unlink(const std::string &name)
bool wifexited(int status)
pid_t fork(std::string &msg)
int execvp(const std::string &file, const string_vector &argv)
int kill(pid_t pid, int sig)
int wexitstatus(int status)
pid_t getpgrp(std::string &msg)
pid_t waitpid(pid_t pid, int *status, int options)
bool wifstopped(int status)
bool wifcontinued(int status)
bool wifsignaled(int status)
int wcoredump(int status)
int fcntl(int fd, int cmd, long arg)
pid_t popen2(const std::string &cmd, const string_vector &args, bool sync_mode, int *fildes)
int dup2(int old_fd, int new_fd)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
DEFMETHODX("quad", Fquad, interp, args,, doc:)