-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_creator.cpp
More file actions
81 lines (73 loc) · 1.83 KB
/
file_creator.cpp
File metadata and controls
81 lines (73 loc) · 1.83 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
72
73
74
75
76
77
78
79
80
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <map>
#include <ios>
using namespace std;
int main()
{
std::map<std::string,int >m; //Hashmap to store the permissions
std::map<std::string,int>::iterator mode;
m["read"] = 400;
m["read-write"] = 600;
m["read-execute"] = 500;
m["read-write-execute"] = 700;
m["write-execute"] = 300;
m["execute"] = 100;
//char file;
string file_ptr;
string test;
string perm;
int val;
cout << "Enter a file name:";
cin >> test;
//cout << "What permissions should the file have? FOR NOW ASSUMING mode" << endl;
//file_ptr = file;
cout << "What permissions would u like to give to the owner of this group?" << endl;
cout << "read" << endl;
cout << "read-write" << endl;
cout << "read-execute" << endl;
cout << "read-write-execute" << endl;
cout << "write-execute" << endl;
cout << "execute" << endl;
cin >> perm;
if(perm.compare("read") == 0 )
{
file_ptr = test;
val = creat(file_ptr.c_str(),0400);
}
else if(perm.compare("read-write") == 0 )
{
file_ptr = test;
val = creat(file_ptr.c_str(),0600);
}
else if(perm.compare("read-execute") == 0 )
{
file_ptr = test;
val = creat(file_ptr.c_str(),0500);
}
else if(perm.compare("read-write-execute") == 0 )
{
file_ptr = test;
val = creat(file_ptr.c_str(),0700);
}
else if(perm.compare("write-execute") == 0 )
{
file_ptr = test;
val = creat(file_ptr.c_str(),0300);
}
else if(perm.compare("execute") == 0 )
{
file_ptr = test;
val = creat(file_ptr.c_str(),0100);
}
else
{
cout << "Error has occured exiting program";
exit(1);
}
close(val);
}