2 % (c) The GRASP/AQUA Project, Glasgow University, 1994
4 \subsection[setBuffering.lc]{hSetBuffering Runtime Support}
11 #ifdef HAVE_SYS_TYPES_H
12 #include <sys/types.h>
15 #ifdef HAVE_SYS_STAT_H
32 setBuffering(fp, size)
40 while ((flags = fcntl(fileno((FILE *) fp), F_GETFL)) < 0) {
48 input = flags == O_RDONLY || flags == O_RDWR;
52 if (setvbuf((FILE *) fp, NULL, _IONBF, 0L) != 0) {
57 if (input && isatty(fileno((FILE *) fp))) {
60 * Try to switch to CBREAK mode, or whatever they call it these days.
63 if (tcgetattr(fileno((FILE *) fp), &tio) < 0) {
68 tio.c_lflag &= ~ICANON;
71 if (tcsetattr(fileno((FILE *) fp), TCSANOW, &tio) < 0) {
80 if (setvbuf((FILE *) fp, NULL, _IOLBF, BUFSIZ) != 0) {
89 * We should actually peek at the buffer size in the stat struct, if there
90 * is one. Something to occupy us later, when we're bored.
95 if (setvbuf((FILE *) fp, NULL, _IOFBF, size) != 0) {
102 if (input && isatty(fileno((FILE *) fp))) {
105 * Try to switch back to cooked mode.
108 if (tcgetattr(fileno((FILE *) fp), &tio) < 0) {
113 tio.c_lflag |= ICANON;
114 if (tcsetattr(fileno((FILE *) fp), TCSANOW, &tio) < 0) {