source: trunk/libs/newlib/src/newlib/libc/sys/linux/mq_getattr.c

Last change on this file was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 810 bytes
Line 
1/* Copyright 2002, Red Hat Inc. */
2
3#include <mqueue.h>
4#include <errno.h>
5#include <sys/sem.h>
6#include <string.h>
7#define _LIBC 1
8#include <sys/lock.h>
9#undef _LIBC
10
11#include "mqlocal.h"
12
13int
14mq_getattr (mqd_t msgid, struct mq_attr *mqstat)
15{
16  struct libc_mq *info;
17  struct sembuf sb0 = {0, -1, 0};
18  int num_msgs;
19  int rc = 0;
20
21  info = __find_mq (msgid);
22
23  if (info == NULL)
24    {
25      errno = EBADF;
26      return -1;
27    }
28
29  /* temporarily lock message queue */
30  semop (info->semid, &sb0, 1);
31
32  num_msgs = semctl (info->semid, 3, GETVAL);
33  if (num_msgs >= 0)
34    {
35      memcpy (mqstat, info->attr, sizeof(struct mq_attr));
36      mqstat->mq_curmsgs = num_msgs;
37    }
38  else
39    rc = -1;
40
41  /* release message queue */
42  sb0.sem_op = 1;
43  semop (info->semid, &sb0, 1);
44
45  return rc;
46}
47     
48
49
50
51
52
Note: See TracBrowser for help on using the repository browser.