aboutsummaryrefslogtreecommitdiff
path: root/semestr-5/so/lista4/so21_lista_4/zad6.c
blob: 117fea9265dc42d32102c92afd4e245340a7c6ee (plain)
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
#include "csapp.h"

bool f_lock(const char *path) {
    if (open(path, O_CREAT|O_WRONLY|O_EXCL, 0700) == -1) {
        if (errno != EEXIST) {
            printf("%s\n", strerror(errno)); 
            exit(EXIT_FAILURE);
        }
        printf("%s\n", strerror(errno)); 
        return false;
    }
    return true;
}

void f_unlock(const char *path) {
    Unlink(path);
}


const char *name = "lock";

int main(void) {
    while (1) {
        if (f_lock(name)) {
            // printf("Hello\n");
            f_unlock(name);
        }
    }
}