-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmytouch.cpp
More file actions
31 lines (24 loc) · 765 Bytes
/
mytouch.cpp
File metadata and controls
31 lines (24 loc) · 765 Bytes
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
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
using std::string;
using std::cerr;
int main(int argc, char* argv[]) {
if (argc < 2) {
cerr << "Usage: " << argv[0] << " <filename...>\n";
return 1; // No file specified
}
// Open the file, create it if it doesn't exist, and set permissions to rw-r--r--
for (int i = 1; i < argc; ++i) {
const char* filename = argv[i];
int fd = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd == -1) {
cerr << "Error creating file: " << filename << "\n";
return 1; // Error creating file
}
close(fd);
}
return 0; // Success
}