Guest User

Untitled

a guest
Aug 14th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/ioctl.h>
  3. #include <unistd.h>
  4.  
  5. int get_tty_size(struct winsize *ws, int fd)
  6. {
  7. if (isatty(fd) && ioctl(fd, TIOCGWINSZ, ws) != -1)
  8. return 0;
  9. return -1;
  10. }
  11.  
  12. int main()
  13. {
  14. struct winsize ws;
  15. int fd = STDIN_FILENO; /* fd must be an open file descriptor referred to a tty */
  16.  
  17. if (get_tty_size(&ws, fd) == -1) {
  18. perror(NULL); /* perror to know why the error occurred */
  19. return 1;
  20. }
  21. printf("Rows: %d\n", ws.ws_row);
  22. printf("Cols: %d\n", ws.ws_col);
  23. return 0;
  24. }
Add Comment
Please, Sign In to add comment