readkey.c 391 B

123456789101112131415161718192021222324
  1. #define _XOPEN_SOURCE 700
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <sys/shm.h>
  6. #include "deonebook.h"
  7. unsigned char *readkey(const char *path)
  8. {
  9. key_t key = ftok(path, 0x2a);
  10. if (key == (key_t)(-1)) {
  11. perror("ftok");
  12. return NULL;
  13. }
  14. int shmid = shmget(key, 0, 0);
  15. if (shmid == -1) {
  16. perror("shmget");
  17. return NULL;
  18. }
  19. return shmat(shmid, NULL, 0);
  20. }