I am coding a C program with termcaps
, and I need to return a value by executing like :
more `./program arg1 arg2 arg3 arg4`
And my function get_winsize
have a condition if my screen is too small.
int *get_winsize()
{
struct winsize w;
int *ret;
ret = malloc(sizeof(int) * 2);
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
ret[0] = w.ws_row;
ret[1] = w.ws_col;
if (ret[0] <= 5 || ret[1] <= 5)
{
printf("screen too small : size %d x %d\n", ret[0], ret[1]);
exit(0);
}
return (ret);
}
When i start my program without the back-quote, I don't have problem. but with the back-quote i have :
size: No such file or directory
screen: No such file or directory
0: No such file or directory
x: No such file or directory
0: No such file or directory
Any idea why ? Maybe back-quoting duplicate a environment without a screen ?!
I found the solution !
First i can get the size with the termcaps function like
tgetnum("co"); //column
tgetnum("li"); //rows
Then, for handle the backcote, i'm printing everything on /dev/tty
!
Problem Solve !