diff options
[SP/P03] Solved exercises
1 files changed, 25 insertions, 0 deletions
| -rw-r--r-- | Year 3/System programming/Practice03/ex1.c | 25 |
diff --git a/Year 3/System programming/Practice03/ex1.c b/Year 3/System programming/Practice03/ex1.c new file mode 100644 index 0000000..944ee0a --- /dev/null +++ b/Year 3/System programming/Practice03/ex1.c @@ -0,0 +1,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); +} |
