added sys::dup() and sys::openfd().

added the optional second parameter to sys::close(). it accepts sys::C_KEEPFD.
This commit is contained in:
2019-08-26 02:47:02 +00:00
parent 8bfac9fff4
commit 4e6015ed36
6 changed files with 239 additions and 22 deletions

View File

@ -1371,6 +1371,7 @@ The *dir* module provides an interface to read file names in a specified directo
- sys::chmod
- sys::close
- sys::closedir
- sys::dup
- sys::errmsg
- sys::fork
- sys::getegid
@ -1387,6 +1388,7 @@ The *dir* module provides an interface to read file names in a specified directo
- sys::mktime
- sys::open
- sys::opendir
- sys::openfd
- sys::pipe
- sys::read
- sys::readdir
@ -1406,6 +1408,16 @@ BEGIN {
}
~~~~~
~~~~~{.awk}
BEGIN {
a = sys::openfd(1);
sys::write (a, B"let me write something here\n");
sys::close (a, sys::C_KEEPFD); ## set C_KEEPFD to release 1 without closing it.
##sys::close (a);
print "done\n";
}
~~~~~
~~~~~{.awk}
BEGIN {
if (sys::pipe(p0, p1, sys::O_CLOEXEC | sys::O_NONBLOCK) <= -1)
@ -1458,6 +1470,27 @@ BEGIN {
}
~~~~~
~~~~~{.awk}
BEGIN {
a = sys::open("/etc/inittab", sys::O_RDONLY);
x = sys::open("/etc/fstab", sys::O_RDONLY);
b = sys::dup(a);
sys::close(a);
while (sys::read(b, abc, 100) > 0) printf (B"%s", abc);
print "-------------------------------";
c = sys::dup(x, b, sys::O_CLOEXEC);
## assertion: b == c
sys::close (x);
while (sys::read(c, abc, 100) > 0) printf (B"%s", abc);
sys::close (c);
}
~~~~~
~~~~~{.awk}
BEGIN {
d = sys::opendir("/etc", sys::DIR_SORT);