File & Directory - pkoper/gtm-posix GitHub Wiki
chmod
chmod^posix(.path,.mode)
takes file path and octal file mode and calls chmod(2).
GTM>d stat^posix("test",.n)
GTM>w $$octal^posix(n("mode"))
0644
GTM>d chmod^posix("test",0755)
GTM>d stat^posix("test",.n)
GTM>w $$octal^posix(n("mode"))
0755
GTM>
chown
chown^posix(.path,.uid,.gid)
takes file path, UID and GID and calls chown(2).
NOTICE: Hopefully you don't run GT.M as superuser. That means chown(2) will have limited or no use for you.
GTM>zsy "id"
uid=1001(gtm) gid=1001(gtm) groups=1001(gtm),12345(test)
GTM>d stat^posix("test",.n)
GTM>w n("uid")," ",n("gid"),!
1001 1001
GTM>d chown^posix("test",n("uid"),12345)
GTM>d stat^posix("test",.n)
GTM>w n("uid")," ",n("gid"),!
1001 12345
GTM>
lchown
lchown^posix(.path,.uid,.gid)
is like chown^posix(.path,.uid,.gid)
, but it calls lchown(2).
unlink
unlink^posix(.path)
takes file path and calls unlink(2).
GTM>d stat^posix("test",.n)
GTM>w $$strerror^posix(errno)
GTM>d unlink^posix("test")
GTM>d stat^posix("test",.n)
GTM>w $$strerror^posix(errno)
%SYSTEM-E-ENO2, No such file or directory
GTM>
link
link^posix(.oldpath,.newpath)
takes old path and new path and calls link(2).
GTM>d stat^posix("/etc/passwd",.n)
GTM>w n("size")
1140
GTM>d link^posix("/etc/passwd","test")
GTM>d stat^posix("test",.n)
GTM>w n("size")
1140
GTM>
symlink
symlink^posix(.oldpath,.newpath)
takes old path and new path and calls symlink(2).
GTM>d stat^posix("/etc/passwd",.n)
GTM>w n("size")
1140
GTM>d symlink^posix("/etc/passwd","test")
GTM>d stat^posix("test",.n)
GTM>w n("size")
1140
GTM>w $$readlink^posix("test")
/etc/passwd
GTM>d lstat^posix("test",.n)
GTM>w n("size")
11
GTM>
readlink
$$readlink^posix(.path)
takes path to the symlink and calls readlink(2).
GTM>d symlink^posix("../../../etc/passwd","test")
GTM>w $$readlink^posix("test")
../../../etc/passwd
GTM>
mkdir
mkdir^posix(.dir,.mode)
takes path and optional mode, and calls mkdir(2). When the mode is not specified 0755
is used.
NOTICE: umask(2) modifies specified permissions.
GTM>d mkdir^posix("a")
GTM>d mkdir^posix("a/b",0755)
GTM>d mkdir^posix("a/b/c","0755")
GTM>f x="a","a/b","a/b/c" d stat^posix(x,.n) w $$octal^posix(n("mode"))," ",x,!
0755 a
0755 a/b
0755 a/b/c
GTM>
rmdir
rmdir^posix(.dir)
takes directory path and calls rmdir(2).
GTM>d rmdir^posix("a")
%GTM-E-ZCSTATUSRET, External call returned error status
GTM>w $$strerror^posix(errno)
%SYSTEM-E-ENO39, Directory not empty
GTM>f x="a/b/c","a/b","a" d rmdir^posix(x)
GTM>
mkpath
mkpath^posix(.path)
takes directory path and makes parent directories as needed. It's like mkdir -p
.
GTM>d mkpath^posix("a/b/c")
GTM>d mkpath^posix("a/b/c")
GTM>f x="a","a/b","a/b/c" d stat^posix(x,.n) w $$isdir^posix(n("mode")),!
1
1
1
GTM>
rmpath
rmpath^posix(.path)
recursively removes files and directories. It's like rm -r
.
GTM>d mkpath^posix("a/b/c")
GTM>f x="a","a/b","a/b/c" d stat^posix(x,.n) w $$isdir^posix(n("mode")),!
1
1
1
GTM>d rmpath^posix("a")
GTM>d stat^posix("a",.n)
GTM>w $$strerror^posix(errno)
%SYSTEM-E-ENO2, No such file or directory
GTM>
opendir
$$opendir^posix(.path)
calls opendir(3) for specified path and returns a directory handler for use with $$readdir^posix(.dir)
and closedir^posix(.dir)
.
Number of active directory handlers, i.e. opened but not closed, is limited. See EMFILE error code in errno for more details.
readdir
$$readdir^posix(.dir)
calls readdir(3) for the specified directory handler and returns directory entries.
GTM>s dir=$$opendir^posix("/usr")
GTM>w dir
167933784
GTM>f s name=$$readdir^posix(.dir) q:name="" w name,!
.
..
share
games
include
bin
lib
src
sbin
local
GTM>d closedir^posix(.dir)
GTM>
closedir
closedir^posix(.dir)
calls readdir(3) for the specified directory handler.