Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice03 / ex1.c
blob: 944ee0a7a943ec292ac9f61ce596c2a81aab4c3a (plain) (blame)
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
#include <fcntl.h> // open
#include <unistd.h> // close
#include <stdio.h> // perror
#include <sys/stat.h> // mode_t

int main(int argc, char* argv[]) {
	int f1 = open(argv[1], O_CREAT, 0777);
	if (f1 < 0) {
		perror("open");
		return 1;
	}

	mode_t oldmask = umask(0);

	int f2 = open(argv[2], O_CREAT, 0777);
	if (f2 < 0) {
		perror("open");
		return 2;
	}

	umask(oldmask);

	close(f1);
	close(f2);
}