zoukankan      html  css  js  c++  java
  • linux stat例程解读文件读写权限

    /* ************************************************************************
    * Filename: stat2.c
    * Description:
    * Version: 1.0
    * Created: 2011年05月11日 16时03分23秒
    * Revision: none
    * Compiler: gcc
    * Author: wenhao (wh), hnrain1004@gmail.com
    * Company: sunplusapp
    * ***********************************************************************
    */


    #include
    <stdio.h>
    #include
    <stdlib.h>
    #include
    <unistd.h>
    #include
    <sys/stat.h>
    #include
    <sys/types.h>
    int main(int argc, char *argv[])
    {
    struct stat buf;
    if(argc < 2)
    {
    printf(
    "please input filepath!\n");
    exit(
    1);
    }

    if(stat(argv[1],&buf)<0)
    {
    printf(
    "file not exiting.!\n");
    exit(
    1);
    }


    if(buf.st_mode&S_IRUSR)
    printf(
    "user can read!\n");
    if(buf.st_mode&S_IWUSR)
    printf(
    "user can write!\n");
    if(buf.st_mode&S_IXUSR)
    printf(
    "user can execute!\n");

    if(buf.st_mode&S_IRGRP)
    printf(
    "group can read!\n");
    if(buf.st_mode&S_IWGRP)
    printf(
    "group can write!\n");
    if(buf.st_mode&S_IXGRP)
    printf(
    "group can execute!\n");

    if(buf.st_mode&S_IROTH)
    printf(
    "other can read!\n");
    if(buf.st_mode&S_IWOTH)
    printf(
    "other can write!\n");
    if(buf.st_mode&S_IXOTH)
    printf(
    "other can execute!\n");



    return 0;
    }

  • 相关阅读:
    C# Path 目录
    Maxscript 窗体与结构体this的传递
    python---文件操作
    python---数据类型---集合
    python---购物车---更新
    python---三级菜单
    python---数据类型---字典
    python---数据类型---字符串
    python---购物车
    python---数据类型---列表
  • 原文地址:https://www.cnblogs.com/hnrainll/p/2043363.html
Copyright © 2011-2022 走看看