No Description

screehw.c 632B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <sys/ioctl.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5. #include <stdlib.h>
  6. void foo(int signum) {
  7. // printf("wowo %d\n",signum);
  8. //exit(signum);
  9. int cols = 80;
  10. int lines = 24;
  11. #ifdef TIOCGSIZE
  12. struct ttysize ts;
  13. ioctl(STDIN_FILENO, TIOCGSIZE, &ts);
  14. cols = ts.ts_cols;
  15. lines = ts.ts_lines;
  16. #elif defined(TIOCGWINSZ)
  17. struct winsize ts;
  18. ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
  19. cols = ts.ws_col;
  20. lines = ts.ws_row;
  21. #endif /* TIOCGSIZE */
  22. printf("Terminal is %dx%d\n", cols, lines);
  23. }
  24. int main (void)
  25. {
  26. (void)signal(SIGWINCH,foo);
  27. while(1) {
  28. }
  29. }