调用stat64系列函数

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

#include 
#include 
#include 

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 
#include 
#include 

int main(int argc,char **argv)
{
        struct stat64 st64;
        stat64("/home",&st64);
        return 0;
}

你可能感兴趣的:(unix系统)