wij
2024-11-26 05:25:55 UTC
Reply
Permalinkwants more, so the answer should be yes it still is.
I just rewrote an example program:
---- a_ptytest.cpp
/* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2008
Convert the example program ptytest.c in Linux Application Development
[Michael K.Johnson, Erik W. Troan] p400. See the book for details.
See also
[Advanced Programming in the UNIX(r) Environment 2nd edition, W.R.S, S.A.R.]
Type 'exit' (or Cntrl-C) in the new pty to exit program.
Build: make a_ptytest
*/
#include <Wy.stdio.h>
#include <Wy.unistd.h>
#include <Wy.termios.h>
#include <Wy.select.h>
#include <Wy.signal.h>
#include <Wy.pty.h>
using namespace Wy;
void sigwinch_handler(int,::siginfo_t*,void*)
{
};
void t0() {
Errno r;
SigAct act(sigwinch_handler,Wy::SigSet(),SA_NOCLDWAIT);
ByteFlow master;
ProcessID cpid;
String name;
if((r=forkpty(master,cpid,name))!=Ok) {
WY_THROW(r);
}
if(cpid==0) {
::execl("/bin/sh", "/bin/sh", NULL);
::exit(-1);
}
// Parent process
FdSet rdset,errset;
rdset.set(cin);
rdset.set(master);
errset.set(master);
for(;;) {
FdSet rset(rdset),eset(errset);
char buf[512];
size_t n_rw;
r=pselect(&rset,NULL,&eset,NULL,NULL);
if((r!=Ok)&&(r!=EINTR)) {
cerr << wrd(r) << WY_ENDL;
break;
}
if(eset.contain(master)) {
WY_THROW( Errno() );
}
if(rset.contain(master)) {
if((r=master.read(buf,WY_CARRLEN(buf),n_rw))!=Ok) {
// may cause EIO while reading controllong terminal
if(r!=EIO) {
WY_THROW(r);
}
}
if(n_rw==0) {
break;
}
if((r=cout.write(buf,n_rw,n_rw))!=Ok) {
WY_THROW(r);
}
}
if(rset.contain(cin)) {
String str;
cin >> str;
master << str;
};
};
};
int main(int argc, const char* argv[])
try {
t0();
cout << "OK" WY_ENDL;
return 0;
}
catch(const Errno& e) {
cerr << wrd(e) << WY_ENDL;
return -1; // e.c_errno();
}
catch(...) {
cerr << "main() caught(...)" WY_ENDL;
throw;
};
--------------
[]$ g++ a_ptytest.cpp -lwy
[]$ ./a.out
sh-5.2$ hello
hello
sh: hello: command not found
sh-5.2$ sudo ls /root
sudo ls /root
[sudo] password for wij: PasswdIsAccessible
anaconda-ks.cfg
sh-5.2$ exit
exit
exit
OK
What's the significance of C++std library? Probably just demo. of flexibility
and support of AT%T's old software. There is no free lunch.