Linux系统编程之查看文件大小的方法,以前发过两种方法,即使用lseek和stat函数。今天再补充一种方法,即使用fseek和ftell函数实现。
#include <sys/types.h> #include <unistd.h> off_t lseek(int fd, off_t offset, int whence);
#include <stdio.h> int fseek(FILE *stream, long offset, int whence); long ftell(FILE *stream);
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int stat(const char *pathname, struct stat *statbuf); int fstat(int fd, struct stat *statbuf); int lstat(const char *pathname, struct stat *statbuf);