调用stat64系列函数

来源:互联网 发布:js防水涂料 编辑:程序博客网 时间:2024/06/07 02:34

前文是对stat64系列函数的源码分析。下面将介绍如何在实际情况下调用stat64系列函数。

#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>int main(int argc,char **argv){        struct stat64 st64;        stat64("/home",&st64);        return 0;}

如果使用编译上述文件将报错。

stat.c:7:16: error: storage size ofst64isnt known  struct stat64 st64;

原因是找不到struct stat64的定义。

只要添加宏定义_GNU_SOURCE即可

#define _GNU_SOURCE#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>int main(int argc,char **argv){        struct stat64 st64;        stat64("/home",&st64);        return 0;}