#include"head.h"
// vsp xxx
int main(int argc, const char *argv[])
{
struct stat buf;
if(stat("./1.c",&buf)<0)
{
perror("stat");
return -1;
}
//见 man 2 stat
//文件类型以及权限
printf("mode:0%o\n",buf.st_mode);
# define MODE buf.st_mode //定义一个 图省事
int a=0400;
int i;
char str[10]="";
for(i=0;i<9;i++)
{
if((a&MODE)!=0) //这里要括号,否则有优先级问题,先算MODE!=0得1或者0,再与a
{
switch (i%3)
{
case 0:str[i]='r';break;
case 1:str[i]='w';break;
case 2:str[i]='x';break;
}
}
else str[i]='-';
a=a>>1;
}
puts(str);
}
#ifndef __head_h__
#define __head_h__
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif