Chinaunix首页 | 论坛 | 博客
  • 博客访问: 542113
  • 博文数量: 150
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-17 00:19
文章分类

全部博文(150)

文章存档

2011年(1)

2009年(14)

2008年(135)

我的朋友

分类: LINUX

2008-08-31 11:29:00

If we try, using either open or creat, to create a file that already exists, the file's access permission bits are not changed. We can verify this by running the program from :

     $ rm foo bar               delete the files in case they already exist
$ date > foo create them with some data
$ date > bar
$ chmod a-r foo bar turn off all read permissions
$ ls -l foo bar verify their permissions
--w------- 1 sar 29 Feb 5 14:25 bar
--w------- 1 sar 29 Feb 5 14:25 foo
$ ./a.out run program from
$ ls -l foo bar check permissions and sizes
--w------- 1 sar 0 Feb 5 14:26 bar
--w------- 1 sar 0 Feb 5 14:26 foo


Note that the permissions didn't change but that the files were truncated.





/*================================================================

mode_t umask( mode_t cmode) function stes the file mode creation

mask for the process and returns the previous value.

==============================================================*/


#include<fcntl.h>
#include<stdio.h>

#define RWRWRW ( S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH )
int main( int argc , char *argv[])
{
   struct stat statbuff;
   umask(0);
   if(creat( "foo" ,RWRWRW)<0 ){
      perror( "create function failed!" );
   }
   umask( S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH );
   if(creat( "bar" ,RWRWRW )<0){
      perror( "create 2 function failed " );
   }
return 0;
}

阅读(1292) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~