$NetBSD: patch-av,v 1.3 2009/07/24 01:24:39 christos Exp $ --- icb/unix.c.orig 1995-02-24 16:20:31.000000000 -0500 +++ icb/unix.c 2009-07-23 21:22:34.000000000 -0400 @@ -7,20 +7,27 @@ #include #include "icb.h" #include "externs.h" +#include #include +#include #include #undef stty #undef gtty -#ifndef SYSV - #ifdef linux #include #else #include #endif +#if defined(__linux__) || defined(__NetBSD__) +#include +#define TTYSTRUCT termios +#define stty(fd,buf) tcsetattr((fd),TCSANOW,(buf)) +#define gtty(fd,buf) tcgetattr((fd),(buf)) +#else +#ifndef SYSV #define TTYSTRUCT sgttyb #define stty(fd,buf) ioctl((fd),TIOCSETN,(buf)) #define gtty(fd,buf) ioctl((fd),TIOCGETP,(buf)) @@ -30,6 +37,7 @@ #define stty(fd,buf) ioctl((fd),TCSETA,(buf)) #define gtty(fd,buf) ioctl((fd),TCGETA,(buf)) #endif /* SYSV */ +#endif /* TIOCSETA */ char *getlogin(); @@ -65,13 +73,16 @@ /* set line buffering for an open file pointer */ /* output will be flushed every newline */ +static char buf[1024]; linebuffer(fp) FILE *fp; { -#ifndef SYSV +#ifndef _IOLBF + setvbuf(fp, buf, _IOLBF, sizeof(buf)); +#else setlinebuf(fp); -#endif /* SYSV */ +#endif } @@ -79,13 +90,13 @@ pushback(c) char c; { -#ifndef SYSV +#ifdef TIOCSTI if (ioctl(0, TIOCSTI, &c) < 0) perror("TIOCSTI ioctl failed"); -#else /* SYSV */ +#else if (ungetc(c,stdin) == EOF) perror("ungetc() failed"); -#endif /* SYSV */ +#endif } @@ -94,25 +105,25 @@ getterm() { -#ifndef SYSV +#if !defined(TCSETA) && !defined(TCSANOW) struct ltchars lt; -#endif /* SYSV */ +#endif /* get tty settings */ if (gtty(0,&origtty) < 0) { badttyinfo++; ttyinfo.erase = '\b'; /* ^H */ ttyinfo.kill = '\025'; /* ^U */ } else { -#ifndef SYSV - ttyinfo.erase = origtty.sg_erase; - ttyinfo.kill = origtty.sg_kill; -#else /* SYSV */ +#if defined(TCSETA) || defined(TCSANOW) ttyinfo.erase = origtty.c_cc[VERASE]; ttyinfo.kill = origtty.c_cc[VKILL]; -#endif /* SYSV */ +#else + ttyinfo.erase = origtty.sg_erase; + ttyinfo.kill = origtty.sg_kill; +#endif } -#ifndef SYSV +#if !defined(TCSETA) && !defined(TCSANOW) /* get local special chars */ if (ioctl(0, TIOCGLTC, <) < 0) { ttyinfo.redraw = '\022'; /* ^R */ @@ -121,10 +132,10 @@ ttyinfo.redraw = lt.t_rprntc; ttyinfo.werase = lt.t_werasc; } -#else /* SYSV */ +#else ttyinfo.redraw = '\022'; /* ^R */ ttyinfo.werase = '\027'; /* ^W */ -#endif /* SYSV */ +#endif /* get the current window size */ getwinsize(); @@ -145,14 +156,14 @@ bcopy((char *)&origtty, (char *)&tty, (unsigned)sizeof(struct TTYSTRUCT)); /* turn on cbreak - turn off echo */ -#ifndef SYSV - tty.sg_flags |= CBREAK; - tty.sg_flags &= ~ECHO; -#else /* SYSV */ +#if defined(TCSETA) || defined(TCSANOW) tty.c_lflag &= ~ICANON; tty.c_cc[VEOF] = 1; tty.c_lflag &= ~ECHO; -#endif /* SYSV */ +#else + tty.sg_flags |= CBREAK; + tty.sg_flags &= ~ECHO; +#endif echomode = 0; /* set the new flags */ @@ -206,7 +217,11 @@ struct passwd *pw; char login[17]; char *p = login; +#ifdef NAME_MAX + static char path[NAME_MAX + 1]; +#else static char path[MAXNAMLEN+1]; +#endif /* has to start with a tilde */ if (*s++ != '~') @@ -258,11 +273,11 @@ } /* turn on echo */ -#ifndef SYSV - tty.sg_flags |= ECHO; -#else /* SYSV */ +#if defined(TCSETA) || defined(TCSANOW) tty.c_lflag |= ECHO; -#endif /* SYSV */ +#else + tty.sg_flags |= ECHO; +#endif echomode = 1; @@ -287,11 +302,11 @@ } /* turn off echo */ -#ifndef SYSV - tty.sg_flags &= ~ECHO; -#else /* SYSV */ +#if defined(TCSETA) || defined(TCSANOW) tty.c_lflag &= ~ECHO; -#endif /* SYSV */ +#else + tty.sg_flags &= ~ECHO; +#endif echomode = 0;