c - 如果我没有流但有文件描述符,如何使用 fgets 或 getline?

标签 c linux ubuntu posix gnu

如果我没有流但有文件描述符,如何使用 fgets 或 getline ?
根据 fgets 的联机帮助页

It is not advisable to mix calls to input functions from the stdio library with low-level calls to read(2) for the file descriptor associated with the input stream; the results will be undefined and very probably not what you want.

最佳答案

您可以使用 read() 函数从文件描述符中读取,这很清楚,从手册页:

read(int fd, void *buf, size_t count); read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.

关于c - 如果我没有流但有文件描述符,如何使用 fgets 或 getline?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70872325/

相关文章:

c - 如何查看2个二叉树是否相似?

c - C中的地址转换

ubuntu - 警告 : remote connection disconnect, 连接到 169.254.169.254 超时

android - 如何提取 ISO 文件,然后将其重新打包成可用的 ISO 文件?

c - 自动完成视觉效果不佳(readline.h)

创建自定义大写方法

linux - Postfix 将所有收到的邮件收集到一个帐户中

linux - 如何判断 configure 和 make 是否支持树外构建?

linux - Asterisk CDR 向 MSSQL 报告

ubuntu - 使用 deb intall 文件在 ubuntu 中安装 hadoop 1.0.1 后如何指定 HADOOP_HOME