How to get the file length in C on Linux given the address of the file (e.g. “/tmp/a.txt”)?
给定文件地址(例如“ /tmp/a.txt”),如何在Linux上的C语言中获取文件长度?
This function returns the length of the file:
此函数返回文件的长度:
#include <sys/stat.h>
long file_length(char *f)
{
struct stat st;
stat(f, &st);
return st.st_size;
}
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。
翻译自: https://www.systutorials.com/how-to-get-the-file-length-in-c-on-linux/