-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUmask.cpp
More file actions
71 lines (51 loc) · 1.59 KB
/
Umask.cpp
File metadata and controls
71 lines (51 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* \file Umask.cpp
* \brief https://support.sas.com/documentation/onlinedoc/sasc/doc/lr2/umask.htm
*
* \review
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
#include <sys/types.h>
#include <sys/stat.h>
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
#if 0
mode_t old_mask = umask( 011 );
open( ... );
umask old_mask);
#endif
mode_t oldMask {};
mode_t newMask {};
// Get old mask, temporarily setting the mask to 0
oldMask = ::umask( static_cast<mode_t>(0) );
// Print old mask. Octal values are used by mask
printf("Old mask = %o\n", static_cast<int>(oldMask));
// Make sure group read permission is allowed
if (oldMask & S_IRGRP) {
printf("Changing group read permission from MASKED to UNMASKED.\n");
oldMask = (oldMask ^ S_IRGRP);
}
// Make sure group write and execute permission is not allowed.
newMask = (oldMask | S_IWGRP | S_IXGRP);
// Update mask
::umask(newMask);
// Print new mask
printf("New mask = %o\n\n", (int) newMask);
printf("The file mode creation mask now specifies:\n\n");
printf(" Group read permission UNMASKED\n");
printf(" Group write permission MASKED\n");
printf(" Group execute permission MASKED\n");
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
Old mask = 2
New mask = 32
The file mode creation mask now specifies:
Group read permission UNMASKED
Group write permission MASKED
Group execute permission MASKED
#endif