|
From: K-mart Cashier on 4 Jul 2008 12:10 I just don't spend enough time "tinkering" with *nix. Anyhow when I read from an unbuffered input and type something in, I get two prompts after I hit return. m-net% more tty.c #include <stdio.h> int main(void) { char c; return(read(0, &c, 1) == 1) ? (unsigned char)c : EOF; return 0; } m-net% ./tty c m-net% m-net% Now when I buffer the input, and type something in, I only get one prompt after I hit return. m-net% more tty2.c #include <stdio.h> int main(void) { static char buf[BUFSIZ]; static char *bufp = buf; static int n = 0; if(n == 0) { n = read(0,buf, sizeof buf); bufp = buf; } return (--n >= 0) ? (unsigned char) *bufp++ : EOF; } m-net% ./tty2 c h a d m-net% Why is this? Chad
From: Chad on 4 Jul 2008 16:18 On Jul 4, 9:10 am, K-mart Cashier <cdal...(a)gmail.com> wrote: > I just don't spend enough time "tinkering" with *nix. Anyhow when I > read from an unbuffered input and type something in, I get two prompts > after I hit return. > > m-net% more tty.c > #include <stdio.h> > > int main(void) > { > char c; > > return(read(0, &c, 1) == 1) ? (unsigned char)c : EOF; > > return 0;} > > m-net% ./tty > c > m-net% > m-net% > > Now when I buffer the input, and type something in, I only get one > prompt after I hit return. > > m-net% more tty2.c > #include <stdio.h> > > int main(void) > { > static char buf[BUFSIZ]; > static char *bufp = buf; > static int n = 0; > > if(n == 0) { > n = read(0,buf, sizeof buf); > bufp = buf; > } > return (--n >= 0) ? (unsigned char) *bufp++ : EOF;} > > m-net% ./tty2 > c h a d > m-net% > > Why is this? > > Chad Never mind. I thought about it and realized that in the latter, newline is stored in buf..
|
Pages: 1 Prev: Solaris 5.10 cpu hike --- _flockget --- possible deadlock ? Next: iovecs don't print right |