tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: FYI: POSIX update - SIGWINCH and 'struct winsize' (etc) to be added



Those of you who follow source-changes will see that the
implementation of this has just been committed (the details
differ slightly from last discussed, but the result is better,
with less changes required.)

No new header file was needed.

All of this has been tested with the (near meaningless) trivial test
program (appended below), compiled with many different combinations of the
#ifdef symbols used in the program, plus _POSIX_SOURCE _NETBSD_SOURCE
and _XOPEN_SOURCE, and in all cases, it has behaved like I would
expect it to behave (including when it generates compilation errors
or warnings, depending on which -D command line args were given to cc).

There are two ways to include <termios.h> not because including it
twice is interesting (though I tested that as well) but because it
can (and did in some implementation variations tested) make a difference
which of <termios.h> and <sys/ioctl.h> is included first.   It shouldn't
(and doesn't in the version committed.)

All test compiles used -Wall.
Tested with gcc only (the gcc in -current today.)

Help improving the wording of the man page ( tcsetwinsize(3) - its source can
be found in src/lib/libc/termios/tcgetwinsize.3 ) would be much appreciated.

Let me know of any problems encountered due to this (there should be
few, it is a very small change really) and/or (perhaps better) file a PR.

kre

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef INCL_TERMIOS_1
#include <termios.h>
#endif

#ifdef INCL_IOCTL
#include <sys/ioctl.h>
#endif

#ifdef INCL_TERMIOS_2
#include <termios.h>
#endif

int
main(int argc, char **argv)
{
	struct winsize w;

	memset(&w, 0, sizeof w);

#ifdef	_NETBSD_SOURCE
	printf("_NETBSD_SOURCE is defined (%ld)\n", (long)_NETBSD_SOURCE);
#endif
#ifdef	_POSIX_SOURCE
	printf("_POSIX_SOURCE is defined (%ld)\n", (long)_POSIX_SOURCE);
#endif

#if USE_TERMIOS
	if (tcgetwinsize(0, &w) == -1)
		perror("tcgetwinsize"), exit(1);
#endif
#ifdef USE_IOCTL
	if (ioctl(0, TIOCGWINSZ, &w) == -1)
		perror("ioctl(TIOCGWINSZ)"), exit(1);
#endif
	printf("R %u C %u\n", w.ws_row, w.ws_col);

	if (argc >= 3) {
		w.ws_row = atoi(argv[1]);
		w.ws_col = atoi(argv[2]);

#if USE_TERMIOS
		if (tcsetwinsize(0, &w) == -1)
			perror("tcsetwinsize"), exit(1);
#endif
#ifdef USE_IOCTL
		if (ioctl(0, TIOCSWINSZ, &w) == -1)
			perror("ioctl(TIOCSWINSZ)"), exit(1);
#endif
#if USE_TERMIOS
		if (tcgetwinsize(0, &w) == -1)
			perror("tcgetwinsize 2"), exit(1);
#endif
#ifdef USE_IOCTL
		if (ioctl(0, TIOCGWINSZ, &w) == -1)
			perror("ioctl(TIOCGWINSZ)2"), exit(1);
#endif
		printf("Set: R %u C %u\n", w.ws_row, w.ws_col);

	}

	exit(0);
}




Home | Main Index | Thread Index | Old Index