diff options
Diffstat (limited to 'semestr-5/so/lista4/so21_lista_4/zad6.c')
-rw-r--r-- | semestr-5/so/lista4/so21_lista_4/zad6.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/semestr-5/so/lista4/so21_lista_4/zad6.c b/semestr-5/so/lista4/so21_lista_4/zad6.c new file mode 100644 index 0000000..117fea9 --- /dev/null +++ b/semestr-5/so/lista4/so21_lista_4/zad6.c @@ -0,0 +1,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); + } + } +}
\ No newline at end of file |