stat函数
获得文件信息
int stat(const char *pathname,struct stat *buf);
pathname文件名
struct stat *buf传出参数,定义 struct stat sb; &sb
返回值:成功返回0,失败返回-1,设置errno
struct timespec{
__lernel_time tv_sec; /sencond/当前时间 到1970.1.1 0:0:0的秒数
long tv_nsec; /nano second/纳秒
};
stat.c
#include<stdio.h>
#include<sys/type.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
int main(int argc,char *argv[])
{
if(argc!=2){
printf("./a.out filename\n");
return -1;
}
struct stat sb;
stat(argv[1],&sb);
return 0;
}
makefile
### xxx.c--->xxx
SrcFiles=$(wildcard *.c)
TargetFiles=$(patsubst %.c,%,$(SrcFiles))
all:$(TargetFiles)
%:%.c
gcc -o $@ $^-g
clean:
rm -f $(TargetFiles)