4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-15 11:00:04 +08:00
Jeff Johnston ef467338e4 2002-06-19 Jeff Johnston <jjohnstn@redhat.com>
* libc/sys/linux/Makefile.am: Add support for message queue routines,
        ipc routines, and ftok.
        * libc/sys/linux/Makefile.in: Regenerated.
        * libc/sys/linux/ftok.c: New file.
        * libc/sys/linux/ipc.c: Ditto.
        * libc/sys/linux/mq_close.c: Ditto.
        * libc/sys/linux/mq_getattr.c: Ditto.
        * libc/sys/linux/mq_notify.c: Ditto.
        * libc/sys/linux/mq_open.c: Ditto.
        * libc/sys/linux/mq_receive.c: Ditto.
        * libc/sys/linux/mq_send.c: Ditto.
        * libc/sys/linux/mq_setattr.c: Ditto.
        * libc/sys/linux/mq_unlink.c: Ditto.
        * libc/sys/linux/mqlocal.h: Ditto.
        * libc/sys/linux/include/mqueue.h: Ditto.
        * libc/sys/linux/sys/types.h: Define __gid_t_defined and
        __uid_t_defined.
2002-06-19 22:17:33 +00:00

53 lines
808 B
C

/* Copyright 2002, Red Hat Inc. */
#include <mqueue.h>
#include <errno.h>
#include <sys/sem.h>
#include <string.h>
#define _LIBC
#include <sys/lock.h>
#undef _LIBC
#include "mqlocal.h"
int
mq_getattr (mqd_t msgid, struct mq_attr *mqstat)
{
struct libc_mq *info;
struct sembuf sb0 = {0, -1, 0};
int num_msgs;
int rc = 0;
info = __find_mq (msgid);
if (info == NULL)
{
errno = EBADF;
return -1;
}
/* temporarily lock message queue */
semop (info->semid, &sb0, 1);
num_msgs = semctl (info->semid, 3, GETVAL);
if (num_msgs >= 0)
{
memcpy (mqstat, info->attr, sizeof(struct mq_attr));
mqstat->mq_curmsgs = num_msgs;
}
else
rc = -1;
/* release message queue */
sb0.sem_op = 1;
semop (info->semid, &sb0, 1);
return rc;
}