OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [mq_getattr.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* 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
 
13
int
14
mq_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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.