C:在不打开系统调用的情况下读取文件(仅读取!)

时间:2018-06-27 06:14:32

标签: c system-calls

我只是试图将文件的数据读取到内存中,但是我希望我的程序使用尽可能少的系统调用。这意味着我试图避免开放或开放。我只想使用阅读。但是我不知道该怎么做。有人可以帮我吗?

谢谢!

1 个答案:

答案 0 :(得分:3)

read需要一个打开的文件描述符,除非调用openopenat,否则您就无法获取该文件描述符,唯一的例外是如果您从stdin中读取(fd 0)

已更新以添加:

谢谢@Yunnosch的建议。怎么样:

http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html

NAME

pread, read - read from a file

简介

#include <unistd.h>

[XSI] [Option Start] ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset); [Option End]

ssize_t read(int fildes, void *buf, size_t nbyte);

说明

The read() function shall attempt to read nbyte bytes from the file associated with the open file descriptor, fildes, into the buffer pointed to by buf.
相关问题