source: trunk/libs/newlib/src/newlib/libc/sys/linux/mq_close.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: 638 bytes
Line 
1/* Copyright 2002, Red Hat Inc. */
2
3#include <mqueue.h>
4#include <errno.h>
5#include <sys/sem.h>
6#define _LIBC 1
7#include <sys/lock.h>
8#undef _LIBC
9
10#include "mqlocal.h"
11
12int
13mq_close (mqd_t msgid)
14{
15  struct libc_mq *info;
16  struct sembuf sb0 = {0, -1, 0};
17  int rc;
18  int semid;
19
20  info = __find_mq (msgid);
21
22  if (info == NULL)
23    {
24      errno = EBADF;
25      return -1;
26    }
27
28  /* lock message queue */
29  semid = info->semid;
30  rc = semop (semid, &sb0, 1);
31
32  if (rc == 0)
33    {
34      __cleanup_mq (msgid);
35     
36      /* unlock message queue */
37      sb0.sem_op = 1;
38      semop (semid, &sb0, 1);
39    }
40
41  return rc;
42}
43     
44
45
46
47
48
Note: See TracBrowser for help on using the repository browser.