Search code examples
javajna

Value of IPC_CREAT when used in JNA


I need to communicate a java application and a c process via posix message queue, and I am using JNA in java application.

In C process, when create message queue I am using:

key_t key = 112233;
int msgflg = IPC_CREAT | 0666;

msqid = msgget(key, msgflg )

What is the value of IPC_CREAT to use in Java application? I found in ipc.h :

/usr/include/sys/ipc.h:#define  IPC_CREAT       0001000         /* create entry if key doesn't exist */

May I safety assume that I can use 512? (decimal) ?

Thanks.


Solution

  • I would suggest you use 950, because

    final int IPC_CREAT = 0001000;
    int msgflg = IPC_CREAT | 0666;
    System.out.println(msgflg);
    

    outputs

    950
    

    I may not understand your question, because

    printf("%i\n", 0001000 | 0666);
    

    also outputs

    950
    

    Edit

    Yes.

    final int IPC_CREAT = 0001000;
    System.out.printf("%d%n", IPC_CREAT);
    

    Output is 512. And,

    printf("%i\n", 0001000);
    

    Output is 512. So you could use decimal 512. Or the binary version like C.