|
|

楼主 |
发表于 2006-7-14 15:41:22
|
显示全部楼层
上面这个问题解决了:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdio.h>
#define SEM_NUM 10
#define SEM_MODE(IPC_CREAT|0660)
//void printf_stat(union semun *arg);
void printfmode (union semun *arg)
{
printf(" mode=%d:\n", arg->buf->sem_perm.mode);
//return;
}
void changemode(int sid, char *mode)
{
int rc;
union semun semopts;
struct semid_ds mysemds;
semopts.buf=&mysemds;
rc=semctl(sid,0, IPC_STAT, semopts);
if(rc==-1)
{
printf("semctl error!\n");
exit(1);
}
sscanf(mode,"%ho", &semopts.buf->sem_perm.mode);
semctl(sid,0, IPC_SET, semopts);
// return;
}
int main(void)
{
int semid;
union semun semopts;
struct semid_ds semds;
if ((semid=semget(IPC_PRIVATE, SEM_NUM, SEM_MODE))==-1)
{
fprintf(stderr, "semget error!\n");
exit(1);
}
semopts.buf=&semds;
if(semctl(semid,0,IPC_STAT,semopts)==-1)
{
fprintf(stderr, "get semid_ds error!\n");
exit(1);
}
printfmode(&semopts);
changemode(semid, 0600);
if(semctl(semid,0, IPC_STAT, semopts)==-1)
{
fprintf(stderr, "get semid_ds error!\n");
exit(1);
}
printfmode(&semopts);
if(semctl(semid,0, IPC_RMID, 0)<0)
{
fprintf(stderr,"semctl error\n");
exit(1);
}
return 1;
}
[root@localhost linuxc]# gcc -o a29 a29.c
a29.c:7:27: "|" may not appear in macro parameter list
a29.c:10: warning: `union semun' declared inside parameter list
a29.c:10: warning: its scope is only this definition or declaration, which is probably not what you want
a29.c: In function `printfmode':
a29.c:12: dereferencing pointer to incomplete type
a29.c: In function `changemode':
a29.c:20: storage size of `semopts' isn't known
a29.c: In function `main':
a29.c:42: storage size of `semopts' isn't known
a29.c:45: `SEM_MODE' undeclared (first use in this function)
a29.c:45: (Each undeclared identifier is reported only once
a29.c:45: for each function it appears in.)
a29.c:60: warning: passing arg 2 of `changemode' makes pointer from integer without a cast
a29.c:75:2: warning: no newline at end of file
多谢各位大哥了! |
|