zoukankan      html  css  js  c++  java
  • 4412 chmod权限

    chmod权限

    使用命令"man 2 chmod"学习chmod函数
    int chmod(const char *path, mode_t mode);
    参数*path:文件路径。
    参数mode:直接使用数字即可。和前面命令中chmod 777 xxx 中的777
    个参数含义类似,也可以使用文档中的组合值。
    返回值:成功返回0,错误返回-1

    int fchmod(int fd, mode_t mode);
    参数fd:文件描述符。
    参数mode:直接使用数字即可。和前面命令中chmod 777 xxx 中的777
    个参数含义类似,也可以使用文档中的组合值。
    返回值:成功返回0,错误返回-1

    #include <sys/stat.h>
    
    #include <stdio.h>
    #include <sys/types.h>
    #include <fcntl.h>
    
    int main(int argc, char *argv[])
    {
            int fd, ret;
    
            if(argc < 3) {
                    printf("
    Please input file apth 
    ");
                    return 1;
            }
    
            //chmod test
            ret = chmod(argv[1], 0777);
            if(ret < 0) {
                    printf("Please makes sure file path
    ");
                    return 1;
            }
            printf("chmod %s is success.
    ", argv[1]);
    
            //fchmod test
            fd = open(argv[2], O_RDWR|O_NOCTTY|O_NDELAY);
            if(fd < 0) {
                    printf("Please makes sure file path
    ");
                    return 1;
            }
            ret = fchmod(fd, 0555);
            if(ret) {
                    printf("Please makes sure file path
    ");
                    return 1;
            }
            printf("fchmod %s is success.
    ", argv[2]);
    
            return 0;
    }
    无欲速,无见小利。欲速,则不达;见小利,则大事不成。
  • 相关阅读:
    centos 7 安装ntp服务器
    centos 7编译安装nodejs 6.1
    修改IKAnalyzer配置
    Elasticsearch5.5.0安装head插件
    搭建ELASTICSEARCH实现中文分词搜索功能
    0426HTML基础:标签
    事件事件流
    纯css设置各行变色
    dom操作之元素的增删复制
    dom操作
  • 原文地址:https://www.cnblogs.com/ch122633/p/9401525.html
Copyright © 2011-2022 走看看