您的位置:首页 > 运维架构 > Linux

linux之umask函数解析

2013-08-03 21:31 302 查看
[lingyun@localhost umask_1]$ vim umask.c
+ umask.c

/*********************************************************************************

* Copyright: (C) 2013 fulinux<fulinux@sina.com>

* All rights reserved.

*

* Filename: umask.c

* Description: This file

*

* Version: 1.0.0(08/02/2013~)

* Author: fulinux <fulinux@sina.com>

* ChangeLog: 1, Release initial version on "08/02/2013 07:09:24 PM"

*

********************************************************************************/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#include <fcntl.h>

#include <sys/stat.h>

#define RWRWRW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

int main(void)

{

umask(0);

if(creat("hello", RWRWRW) < 0)

{

printf("creat error for hello\n");

exit(1);

}

umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);

if(creat("world", RWRWRW) < 0)

{

printf("creat error for world");

exit(1);

}

exit(0);

}

~

~

~

~

~

~

~

~

~

~

~/apue/umask/umask_1/umask.c[+] CWD: /usr/local/src/lingyun/apue/umask/umask_1 Line: 37/38:12

"umask.c" [New] 38L, 1016C written

[lingyun@localhost umask_1]$ gcc umask.c

[lingyun@localhost umask_1]$ umask

0022

[lingyun@localhost umask_1]$ ./a.out

[lingyun@localhost umask_1]$ ls -l hello world

-rw-rw-rw- 1 lingyun trainning 0 Aug 2 19:19 hello

-rw------- 1 lingyun trainning 0 Aug 2 19:19 world

[lingyun@localhost umask_1]$ umask

0022

[lingyun@localhost umask_1]$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: