#include "common.h"
#define OPEN_FILE_NAME "./stu.dat"
int main (int argc, char *argv[])
{
struct stat st;
int ret = stat(OPEN_FILE_NAME, &st); //============ &st 因为 int stat(const char * file_name,struct stat *buf);
if(-1 == ret)
err_sys("stat")
system("ls -i stu.dat");
printf("index number=%d\n", st.st_ino);
printf("file size=%d\n", st.st_size);
system("ls -trl stu.dat");
if ( S_ISREG(st.st_mode)) //==================== S_ISREG (st_mode) 是否为一般文件 文件类型在POSIX 中定义了检查这些类型的宏定义
{
printf("Regular file\n");
}
if (S_IRUSR & st.st_mode)
{
printf("Read permission\n");
}
else if (S_IWUSR & st.st_mode)
{
printf("Write permission\n");
}
system("chmod a+w,a+r,u-r stu.dat");
system("ls -trl stu.dat");
chmod("stu.dat", S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP);
//chmod("stu.dat", 0770);
system("ls -trl stu.dat");//
if (! access("stu.dat", W_OK))
{
printf("Write permission\n");
}
return 0;
}
#define OPEN_FILE_NAME "./stu.dat"
int main (int argc, char *argv[])
{
struct stat st;
int ret = stat(OPEN_FILE_NAME, &st); //============ &st 因为 int stat(const char * file_name,struct stat *buf);
if(-1 == ret)
err_sys("stat")
system("ls -i stu.dat");
printf("index number=%d\n", st.st_ino);
printf("file size=%d\n", st.st_size);
system("ls -trl stu.dat");
if ( S_ISREG(st.st_mode)) //==================== S_ISREG (st_mode) 是否为一般文件 文件类型在POSIX 中定义了检查这些类型的宏定义
{
printf("Regular file\n");
}
if (S_IRUSR & st.st_mode)
{
printf("Read permission\n");
}
else if (S_IWUSR & st.st_mode)
{
printf("Write permission\n");
}
system("chmod a+w,a+r,u-r stu.dat");
system("ls -trl stu.dat");
chmod("stu.dat", S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP);
//chmod("stu.dat", 0770);
system("ls -trl stu.dat");//
if (! access("stu.dat", W_OK))
{
printf("Write permission\n");
}
return 0;
}