#include #include #include #include #include #include #include #include void check(const char* name, int status); void check2(const char* name, const void* status); int main() { // Test msgctl int msqid = 0; int cmd = 0; struct msqid_ds buf2; int status = msgctl(msqid, cmd, &buf2); check("msgctl", status); // Test msgget key_t key = IPC_PRIVATE; int msgflg = 0; status = msgget(key, msgflg); check("msgget", status); // Test msgrcv struct msgbuf msgp; msgp.mtype = 1; size_t msgsz = 0; long msgtyp = 0; status = msgrcv(msqid, &msgp, msgsz, msgtyp, msgflg); check("msgrcv", status); // Test msgsnd status = msgsnd(msqid, &msgp, msgsz, msgflg); check("msgsnd", status); printf("\n"); // Test semctl int semid = 0; int semnum = 0; status = semctl(semid, semnum, cmd); check("semctl", status); // Test semget int nsems = 0; int semflg = 0; status = semget(key, nsems, semflg); check("semget", status); // Test semop struct sembuf sops; unsigned nsops = 1; status = semop(semid, &sops, nsops); check("semop", status); printf("\n"); // Test shmat int shmid = 0; char* shmaddr = 0; int shmflg = 0; void* status2 = shmat(shmid, shmaddr, shmflg); check2("shmat", status2); // Test shmctl struct shmid_ds buf; status = shmctl(shmid, cmd, &buf); check("shmctl", status); // Test shmget int size = 0; status = shmget(key, size, shmflg); check("shmget", status); // Test shmdt status = shmdt(shmaddr); check("shmdt", status); } void check(const char* name, int status) { if (status < 0) printf("%s() failed: %s (errno = %d)\n", name, strerror(errno), errno); } void check2(const char* name, const void* status) { if (status == (const void*) -1) printf("%s() failed: %s (errno = %d)\n", name, strerror(errno), errno); }