定义EOF字符 [英] Define EOF character

查看:112
本文介绍了定义EOF字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇,是否可以暂时添加应解释为EOF的字符?例如,在循环中使用read()系统调用,并通过将新行字符临时注册为EOF来使其在'\n'上中止.

Out of curiosity is it possible to temporarily add a character that should be interpreted as EOF? For example using the read() syscall in a loop, and have it abort on '\n' by register the new line character as EOF temporarily.

推荐答案

否,不可能.如果要从文件描述符中读取数据,直到遇到特定字符,并避免读取任何超出其的字符(例如,以免消耗其他进程稍后需要的输入),唯一的解决方案是执行1字节读取.速度很慢,但事实就是如此.

Nope, not possible. If you want to read from a file descriptor until you encounter a specific character, and avoid reading anything past it (so as not to consume input needed later by another process, for instance) the only solution is to perform 1-byte reads. It's slow but that's how it is.

这篇关于定义EOF字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆