-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftok_check.c
More file actions
36 lines (31 loc) · 814 Bytes
/
ftok_check.c
File metadata and controls
36 lines (31 loc) · 814 Bytes
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
30
31
32
33
34
35
36
/**
Verify the implementation of ftok() function.
On linux the result is expected to be composed of
proj, inode number, device id
*/
#include <unistd.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#define KEY_FILE "/tmp/ftok_check.sysv"
#define PROJ 1
int main(int argc, char **argv) {
struct stat sb;
int fd;
key_t tok;
// Create the key file if it doesn't exist.
if (stat(KEY_FILE, &sb) == -1) {
fd = open(KEY_FILE, O_CREAT | O_RDWR, S_IRWXU);
close(fd);
}
tok = ftok(KEY_FILE, PROJ);
printf("FTOK:\t%08llx\n", (long long)tok);
if (stat(KEY_FILE, &sb) == -1)
exit(EXIT_FAILURE);
printf("INO:\t%08llx\n", (long long)sb.st_ino);
printf("DEV:\t%08llx\n", (long long)sb.st_dev);
printf("PRJ:\t%08x\n", PROJ);
exit(EXIT_SUCCESS);
}