博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
chmod权限
阅读量:4298 次
发布时间:2019-05-27

本文共 918 字,大约阅读时间需要 3 分钟。

1、使用命令"man 2 chmod"学习chmod函数

2、int chmod(const char *path, mode_t mode);

      –参数*path:文件路径。
      –参数mode:直接使用数字即可。和前面命令中chmod 777 xxx 中的777 这个参数含义类似,也可以使用文档中的         组合值。
      –返回值:成功返回0,错误返回-1。

3、int fchmod(int fd, mode_t mode);

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

#include 
#include
#include
#include
int main(int argc,char *argv[]){ int fd,ret; if(argc <3){ printf("\nPlease input file path\n"); return 1; } //chmod函数测试 ret = chmod(argv[1],0777); if(ret<0){ printf("Please make sure file path\n"); return 1; } printf("chmod %s 0777 is success!\n",argv[1]);//fchmod函数测试 fd = open(argv[2],O_RDWR|O_NOCTTY|O_NDELAY); if(fd<0) { printf("Please make sure file path\n"); return 1; } ret = fchmod(fd,0555); if(ret<0){ printf("Please make sure file path\n"); return 1; } printf("fchmod %s 0555 is success!\n",argv[1]); return 0;}

转载地址:http://yynws.baihongyu.com/

你可能感兴趣的文章
eclipse安装插件的两种方式在线和离线
查看>>
linux下源的相关笔记(suse)
查看>>
linux系统分区文件系统划分札记
查看>>
Linux(SUSE 12)安装Tomcat
查看>>
Linux(SUSE 12)安装jboss4并实现远程访问
查看>>
Neutron在给虚拟机分配网络时,底层是如何实现的?
查看>>
netfilter/iptables全攻略
查看>>
Overlay之VXLAN架构
查看>>
Eclipse : An error occurred while filtering resources(Maven错误提示)
查看>>
在eclipse上用tomcat部署项目404解决方案
查看>>
web.xml 配置中classpath: 与classpath*:的区别
查看>>
suse如何修改ssh端口为2222?
查看>>
详细理解“>/dev/null 2>&1”
查看>>
suse如何创建定时任务?
查看>>
suse搭建ftp服务器方法
查看>>
centos虚拟机设置共享文件夹并通过我的电脑访问[增加smbd端口修改]
查看>>
文件拷贝(IFileOperation::CopyItem)
查看>>
Tensorflow神经网络框架(第三课 3-1Tensorflow简单实例 非线性回归 梯度下降法)
查看>>
Tensorflow神经网络框架(第三课 3-2MNIST数据集分类简单版本,手写数字识别)
查看>>
解决PyCharm [import tensorflow as tf]报错
查看>>