🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sgi.bugs
Article #21

close() BUG ?

#21
From: Frederic Hemmer
Date: Mon, 21 Dec 1992 17:24
81 lines
2378 bytes
Perhaps I'm getting crazy (or tired), but I've a little problem
with close() used with ioctl(TIOCGWINSZ).

The following program :

#include <stdio.h>
#include <unistd.h>
#include <sys/termio.h>
#include <sys/types.h>
#include <fcntl.h>


/*
 * Getting terminal window size.
 */
int termwinsiz(col,row)
        int *col ;
        int *row ;
{
        int             term ;          /* Terminal identifier  */      
        struct winsize  win  ;          /* Window structure     */

        if ( (term= open("/dev/tty",O_RDWR)) == -1 ) {
                return -1 ;
        }
        if ( ioctl(term,TIOCGWINSZ,&win) == -1 ) {
                return -1 ;
        }
        if ( close(term) == -1 ) {
                return -1 ;
        }
        *col= win.ws_col ;
        *row= win.ws_row ;

        return 0 ;
}

main()  {
        int col;
        int row;

        if (termwinsiz(&col, &row) == -1)       {
                perror("unable to get terminal size");
        }
        else    {
                printf("Your window size is %dX%d\n", col, row);
        }
        exit (0);
}

Gives the following output on 4.0.5 (I believe it worked fine with 3):

unable to get terminal size: No such device

It is the close() syscall who complains.

Note that if I replace the close invocation by :

#if (defined(sgi) && defined(__EXTENSIONS__)) /* detects Irirx 4.0.5 */
        (void) close(term);
#else
        if ( close(term) == -1 ) {
                return -1 ;
        }
#endif /* sgi && __EXTENSIONS */

The output is fine :

	Your window size is 81X26

The same program worked without any problem on many systems
(sun, aix, hp, cray, ultrix ...)

Can somebody help ?

-- 
Frederic Hemmer                          email: hemmer@sun2.cern.ch
European Laboratory for Particle Physics bitnet: hemmer at cernvm
Computers and Networks division          phone: +41-22-7676104
CH-1211 Geneva 23 - Switzerland          fax:   +41-22-7677155
Technical Details
Message-ID: <1992Dec21.172454.9850@dxcern.cern.ch>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!dxcern!sun2!hemmer

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.sgi.bugs
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!dxcern!sun2!hemmer
From: hemmer@sun2.cern.ch (Frederic Hemmer)
Subject: close() BUG ?
Message-ID: <1992Dec21.172454.9850@dxcern.cern.ch>
Sender: hemmer@sun2 (Frederic Hemmer ATD10)
Organization: CERN - European Laboratory for Particle Physics
Date: Mon, 21 Dec 1992 17:24:54 GMT
Lines: 81