How to set stty row and columns of the terminal through C program

Hi,

I'm have a big problem with one of the C programs that I'm developping.
actually, I'm trying to monitor the users' session in solaris.
therefore, I have used the source code of the unix "script" command. but the problem is that, when i run that program, the stty settings are lost:
speed 38400 baud; -parity
erase = ^h; swtch = <undef>;
brkint -inpck -istrip icrnl -ixany imaxbel onlcr tab3
echo echoe echok echoctl echoke iexten
However, before executing it, it was like this:
speed 38400 baud; -parity
rows = 50; columns = 132; ypixels = 0; xpixels = 0;
erase = ^h; swtch = <undef>;
brkint -inpck -istrip icrnl -ixany imaxbel onlcr tab3
echo echoe echok echoctl echoke iexten

This is actually resulting in having problems while trying to edit any file with VI editor or view it with the "less" command...
so, can anyone help me on how to get set the rows and columns size from inside the C program?
thank you in advance.
Regards,
Saad

First off, once you use script, is the resulting environment even still a terminal?

Hi Corona688,

When I execute the script, I see that new terminal is set.
root@voms11 # tty
/dev/pts/2
root@voms11 # ./script
root@voms11 # tty
/dev/pts/4

by the way, I have attached the script I'm using. so, if you can tell me how can i exactly set the rows/columns options in that terminal.

thank you.

You can save your tty's values with stty -g, then restore them by giving stty that same output on the commandline. How to do this in C is a trickier question if you don't feel like using system(), since there's a lot of ioctl calls involved. You could run strace on stty to see what calls its making to get the values and set the values, though sometimes it might print ambiguous statements due to ioctls meaning different things on different kinds of files.

Hi Corona688,

Thanks for your precious help.
However, I could mange monitoring of user sessions using the screen tool, it is much more sophisticated that the script tool :).

thanks again for your help.
Regards,
Saad