Is there a way to peek a value from a tty device

2019-08-15 18:40发布

Im writing a program which reads and writes to serial. I was wondering, is there a way to peek the next value from a tty device such as /dev/ttyS0 without removing it from the queue. I have looked for documentation or even source code for this module and have been so far, unable to find it. If anyone knows where it is, or which ioctls are available, please let me know.

标签: linux
1条回答
Lonely孤独者°
2楼-- · 2019-08-15 19:38

Using a combination of getc and ungetc will allow you to peek a single byte.

If you need more than one byte, you'll need to buffer it manually.

查看更多
登录 后发表回答