I am trying to make my own code better + shorter + more portable.
If/when anyone has time, can you please explain the following to me so
that I do not make embarrassing claims like the one that I made on the
other patch thread? :D
Revision 1.33 of script(1) changes
(void)tcgetattr(STDIN_FILENO, &tt);
(void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win);
to
if (isatty(0)) {
if (tcgetattr(STDIN_FILENO, &tt) == 0 &&
ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == 0)
istty = 1;
}
based on the fact that tty operations should not be performed on stdin
if it is not a tty [ maybe it is a regular file ]. This observation
was made by [email protected]. I claim that only
if (tcgetattr(STDIN_FILENO, &tt) == 0 &&
ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == 0)
istty = 1;
would have been sufficient because tcgetattr will fail with errno ==
ENOTTY if stdin is not a tty. Am I wrong? This claim is true on
NetBSD/FreeBSD because their versions of isatty simply make a call to
tcgetattr to see it it succeeds. However, the OpenBSD version [
/lib/libc/gen/isatty.c ] calls fcntl with F_ISATTY, which also, like
tcgetattr, sets errno to ENOTTY if the fd is not a tty [ sys_fcntl()
from /sys/kern/kern_descrip.c ].
Additional note: tcgetattr calls ioctl with TIOCGETA [
/lib/libc/termios/tcgetattr.c and ttioctl() from /sys/kern/tty.c ].
Thank you very much for your patience.
Soumendra
On 8/9/20, Soumendra Ganguly <[email protected]> wrote:
> Stefan,
> I had heard about asciinema before [
> https://intoli.com/blog/terminal-recorders/ mentions a ton of other
> terminal recorders ]. asciinema is great. I had not heard about
> textproc before. Thank you very much for the information!
>
> My original intention was to know HOW these programs record the
> terminal. I have now written my own C program [ not released yet ]
> that does what I want while not using the Linux specific signalfd api
> that the util-linux version does. That way, it can run on many
> operating systems. Since the Linux, FreeBSD, and NetBSD versions of
> script have the replay feature, my OCD tempted me to request it for
> OpenBSD as well :D However, I understand Theo's message about "scope
> creep".
>
> Thank you again.
> Soumendra.
>
> On 8/9/20, Stefan Hagen <[email protected]> wrote:
>> Soumendra Ganguly wrote:
>>> It is particularly useful if someone wants to replay [ not re-run ] a
>>> curses session [ such as a game or an editing session on vi ].
>>
>> Have you tried textproc/asciinema?
>>
>> $ asciinema rec demo.cast
>> # do something ncurses or not; stop with ctrl+d
>> $ asciinema play demo.cast
>>
>> Best Regards,
>> Stefan
>>
>