I don’t trust sys/ioctl.ph. This code works for me:
But you may have to recompile and rerun the C code in DATA to get the proper values for the TIOCGWINSZ and the size of the structure.my $winsize = "\0" x 8; # XXX: should be require sys/ioctl.pl # value below is for BSD, eg: OpenBSD, darwin=MacOS X, (etc?) my $TIOCGWINSZ = 0x40087468; if (ioctl(STDOUT, $TIOCGWINSZ, $winsize)) { ($rows, $cols, $xpix, $ypix) = unpack('S4', $winsize); } else { $cols = 80; } print "$cols\n"; __END__ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <sys/ioctl.h> #include <termios.h> main() { struct winsize mywinsize; int ttyfd; if ((ttyfd = open("/dev/tty", O_RDWR|O_NOCTTY)) == -1) { perror("open /dev/tty"); exit(-1); } if (ioctl(ttyfd, TIOCGWINSZ, &mywinsize) == -1) { perror("ioctl TIOCGWINSZ"); exit(-1); } printf("TIOCGWINSZ %#08x\n", TIOCGWINSZ ); printf("sizeof struct winsize %d\n", sizeof(struct winsize) ); printf("rows %d\n", mywinsize.ws_row ); printf("cols %d\n", mywinsize.ws_col ); if (fclose(stdout) == EOF) { perror("close stdout"); exit(-1); } exit(0); }
In reply to Re: Don't understand why can't get 'size' assoc w/STDOUT
by tchrist
in thread Don't understand why can't get 'size' assoc w/STDOUT
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |