Linxu系统IO函数 stat 和 lstat 函数
stat 和 lstat函数
作用:获取一个文件相关的一些信息

st_mode

1 /* 2 stat: man 2 stat 3 #include <sys/types.h> 4 #include <sys/stat.h> 5 #include <unistd.h> 6 7 int stat(const char* pathname,struct stat* statbuf); 8 作用:获取一个文件相关的一些信息 从路径文件中获取数据传入statbuf中 9 参数: 10 - pathname:操作的文件的路径 11 - statbuf:结构体变量,传出参数 12 返回值: 13 成功:返回0 14 失败:返回-1 设置errno 15 int lstat(const char* pathname,struct stat* statbuf); 16 作用:获取一个文件相关的一些信息 从路径文件中获取数据传入statbuf中 17 参数: 18 - pathname:操作的文件的路径 19 - statbuf:结构体变量,传出参数 20 返回值: 21 成功:返回0 22 失败:返回-1 设置errno 23 */ 24 #include <sys/types.h> //stat 25 #include <sys/stat.h> //stat 26 #include <unistd.h> //stat 27 #include <stdio.h> 28 29 int main() 30 { 31 struct stat statbuf; 32 int ret = stat("a.txt",&statbuf); 33 if(ret == -1) 34 { 35 perror("stat"); 36 return -1; 37 } 38 printf("size: %ld\n",statbuf.st_size); 39 return 0; 40 }

此时 vim b.txt文件 会打开 a.txt(类似windows下的快捷方式)
浙公网安备 33010602011771号