File: ipcs.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (32 lines) | stat: -rw-r--r-- 936 bytes parent folder | download
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
#include <sys/ipc.h>
#include <sys/sem.h>

#include <sys/msg.h>
#include "test.h"

int main() {
    int id = semget(IPC_PRIVATE, 1, IPC_CREAT | 0666);
    if (id < 0) {
        perror("semget failed");
        return 1;
    }

    struct semid_ds buf;
    int ret = semctl(id, 0, IPC_STAT, &buf);
    if (ret < 0) {
        perror("semctl IPC_STAT failed");
    } else {
        printf("semctl IPC_STAT succeeded\n");
    }

    semctl(id, 0, IPC_RMID);
    printf("sizeof(msginfo) = %zu\n", sizeof(struct msginfo));
    ASSERT(32, sizeof(struct msginfo));
    printf("msgmax offset = %zu\n", offsetof(struct msginfo, msgmax));
    ASSERT(8, offsetof(struct msginfo, msgmax) );
    printf("msgmnb offset = %zu\n", offsetof(struct msginfo, msgmnb));
    ASSERT(12, offsetof(struct msginfo, msgmnb));
    printf("msgtql offset = %zu\n", offsetof(struct msginfo, msgtql));
    ASSERT(24, offsetof(struct msginfo, msgtql));
    return 0;
}