c - read() and write() sending excess output to Vim -
i'm using read()
, write()
syscalls input stdin
, print stdout
.
from inside vim exeute command run program
:!./lowio
the buffer array gets printed out, discarded chars didn't put array sent vim. vim interperts chars command.
#include <unistd.h> #define bufsize 3 int main() { char low[bufsize + 1]; read(0, low, bufsize); low[bufsize + 1] = '\0'; write(1, low, bufsize); return 0; }
for example, typing
abcdg
will print abc
stdin
send dg
vim goes , deletes cursor end of file.
what going on here?
your stdin
terminal (/dev/tty
) , typed abcdg<nl>
. read(0,...,3)
call requested 3 characters (abc
) terminal device driver's buffer. remaining characters remained in buffer. when returned control vim, proceeded read stdin
, remaining, buffered characters.
Comments
Post a Comment