diff options
| author | Jakob Kaivo <jkk@ung.org> | 2020-11-12 19:45:09 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2020-11-12 19:45:09 -0500 |
| commit | bc84c9688b2e406cb4926bda42eb5bddf838fe33 (patch) | |
| tree | bb5630010369c9cb6774c9bb7f3ed6000795c636 | |
| parent | 25ef0e31af60f54f67bb5d69d1654cc94a48b8fd (diff) | |
add separate path for reading key from SHM
| -rw-r--r-- | readkey.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/readkey.c b/readkey.c new file mode 100644 index 0000000..a7337b6 --- /dev/null +++ b/readkey.c @@ -0,0 +1,23 @@ +#define _XOPEN_SOURCE 700 +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/shm.h> +#include "deonebook.h" + +unsigned char *readkey(const char *path) +{ + key_t key = ftok(path, 0x2a); + if (key == (key_t)(-1)) { + perror("ftok"); + return NULL; + } + + int shmid = shmget(key, 0, 0); + if (shmid == -1) { + perror("shmget"); + return NULL; + } + + return shmat(shmid, NULL, 0); +} |
