home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / sgi / bugs / 31 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.2 KB  |  92 lines

  1. Newsgroups: comp.sys.sgi.bugs
  2. Path: sparky!uunet!mcsun!dxcern!sun2!hemmer
  3. From: hemmer@sun2.cern.ch (Frederic Hemmer)
  4. Subject: close() BUG ?
  5. Message-ID: <1992Dec21.172454.9850@dxcern.cern.ch>
  6. Sender: hemmer@sun2 (Frederic Hemmer ATD10)
  7. Organization: CERN - European Laboratory for Particle Physics
  8. Date: Mon, 21 Dec 1992 17:24:54 GMT
  9. Lines: 81
  10.  
  11.  
  12. Perhaps I'm getting crazy (or tired), but I've a little problem
  13. with close() used with ioctl(TIOCGWINSZ).
  14.  
  15. The following program :
  16.  
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <sys/termio.h>
  20. #include <sys/types.h>
  21. #include <fcntl.h>
  22.  
  23.  
  24. /*
  25.  * Getting terminal window size.
  26.  */
  27. int termwinsiz(col,row)
  28.         int *col ;
  29.         int *row ;
  30. {
  31.         int             term ;          /* Terminal identifier  */      
  32.         struct winsize  win  ;          /* Window structure     */
  33.  
  34.         if ( (term= open("/dev/tty",O_RDWR)) == -1 ) {
  35.                 return -1 ;
  36.         }
  37.         if ( ioctl(term,TIOCGWINSZ,&win) == -1 ) {
  38.                 return -1 ;
  39.         }
  40.         if ( close(term) == -1 ) {
  41.                 return -1 ;
  42.         }
  43.         *col= win.ws_col ;
  44.         *row= win.ws_row ;
  45.  
  46.         return 0 ;
  47. }
  48.  
  49. main()  {
  50.         int col;
  51.         int row;
  52.  
  53.         if (termwinsiz(&col, &row) == -1)       {
  54.                 perror("unable to get terminal size");
  55.         }
  56.         else    {
  57.                 printf("Your window size is %dX%d\n", col, row);
  58.         }
  59.         exit (0);
  60. }
  61.  
  62. Gives the following output on 4.0.5 (I believe it worked fine with 3):
  63.  
  64. unable to get terminal size: No such device
  65.  
  66. It is the close() syscall who complains.
  67.  
  68. Note that if I replace the close invocation by :
  69.  
  70. #if (defined(sgi) && defined(__EXTENSIONS__)) /* detects Irirx 4.0.5 */
  71.         (void) close(term);
  72. #else
  73.         if ( close(term) == -1 ) {
  74.                 return -1 ;
  75.         }
  76. #endif /* sgi && __EXTENSIONS */
  77.  
  78. The output is fine :
  79.  
  80.     Your window size is 81X26
  81.  
  82. The same program worked without any problem on many systems
  83. (sun, aix, hp, cray, ultrix ...)
  84.  
  85. Can somebody help ?
  86.  
  87. -- 
  88. Frederic Hemmer                          email: hemmer@sun2.cern.ch
  89. European Laboratory for Particle Physics bitnet: hemmer at cernvm
  90. Computers and Networks division          phone: +41-22-7676104
  91. CH-1211 Geneva 23 - Switzerland          fax:   +41-22-7677155
  92.