Background: I’m trying to create a pseudo-terminal using only the tools that come with “Git for windows” so please don’t tell me “just install tool XYZ” if XYZ requires extra native binaries. (Actually, feel free to mention XYZ since it may be useful to others, but it likely won’t help me.)
With that background out of the way, the rest of this question actually assumes we’re on Linux, because Linux has strace and I can’t live without strace.
So, consider this code snippet…
open PTMX, '/dev/ptmx';
my $out = "1234"; # is this right??
my $ret = ioctl PTMX, 0x5430, $out; # hardcode number for now
if (!$ret) {
say "errno is $!"
} else {
say "out is $out; ret is $ret"
}
When I run this using strace -e ioctl /usr/bin/perl t.pl
I see that
- It’s passing file descriptor 3, as expected. Good!
- The ioctl number got resolved to TIOCGPTN, which is what I hoped for. Great!
- But the call fails with EINVAL (Invalid argument)
Thus I conclude that the trouble is with the third parameter. At the C level, I want to pass a pointer to an integer but I can’t figure out from the docs at https://perldoc.perl.org/functions/ioctl how to do so.