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;
    }

  • 相关阅读:
    为网站添加图标和收藏夹图标
    常用css入门
    利用反射动态创建对象
    如何用实现.NET的插件机制
    设计模式(18)-Command Pattern
    C#中调用API
    判断一个string是否可以为数字
    080709 阴
    7月9日 多云
    080710 闷热闷热
  • 原文地址:https://www.cnblogs.com/hnrainll/p/2043363.html
Copyright © 2011-2022 走看看