-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有关文件新接口的buf大小的疑问 #632
Comments
没错,这两个接口除了一个以fd为参数,另一个以文件名为参数之外没有区别。其实我更建议用文件名的接口,除非你自己要复用fd来创建下一个任务。 #include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int stat(const char *path, struct stat *buf);
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
}; 然后根据这个文件大小来分配内存。剩下的就和示例里没什么区别了。 |
好的,非常感谢 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,请教一下
在tutorial里面,我们调用这个老文件接口的时候,
我们通过lseek知道文件大小
在我们调用新接口的时候,如果说我要读入一个文件,传入文件名,此处buf大小是我们自己预估一个大小吗?
The text was updated successfully, but these errors were encountered: