source: rtems/cpukit/posix/src/mqueuegetattr.c

Last change on this file was 0a645dad, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 22:31:50

cpukit/posix/src/[a-o]*.c: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup POSIXAPI
7 *
8 * @brief Message Queue Attributes
9 */
10
11/*
12 *  NOTE:  The structure of the routines is identical to that of POSIX
13 *         Message_queues to leave the option of having unnamed message
14 *         queues at a future date.  They are currently not part of the
15 *         POSIX standard but unnamed message_queues are.  This is also
16 *         the reason for the apparently unnecessary tracking of
17 *         the process_shared attribute.  [In addition to the fact that
18 *         it would be trivial to add pshared to the mq_attr structure
19 *         and have process private message queues.]
20 *
21 *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
22 *         time.
23 *
24 *  COPYRIGHT (c) 1989-2011.
25 *  On-Line Applications Research Corporation (OAR).
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 *    notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 *    notice, this list of conditions and the following disclaimer in the
34 *    documentation and/or other materials provided with the distribution.
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
37 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
40 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
41 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 * POSSIBILITY OF SUCH DAMAGE.
47 */
48
49#ifdef HAVE_CONFIG_H
50#include "config.h"
51#endif
52
53#include <rtems/posix/mqueueimpl.h>
54
55/*
56 *  15.2.8 Get Message Queue Attributes, P1003.1b-1993, p. 283
57 */
58
59int mq_getattr(
60  mqd_t           mqdes,
61  struct mq_attr *mqstat
62)
63{
64  POSIX_Message_queue_Control *the_mq;
65  Thread_queue_Context         queue_context;
66
67  if ( mqstat == NULL ) {
68    rtems_set_errno_and_return_minus_one( EINVAL );
69  }
70
71  the_mq = _POSIX_Message_queue_Get( mqdes, &queue_context );
72
73  if ( the_mq == NULL ) {
74    rtems_set_errno_and_return_minus_one( EBADF );
75  }
76
77  _CORE_message_queue_Acquire_critical(
78    &the_mq->Message_queue,
79    &queue_context
80  );
81
82  if ( the_mq->open_count == 0 ) {
83    _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
84    rtems_set_errno_and_return_minus_one( EBADF );
85  }
86
87  /*
88   *  Return the old values.
89   */
90  mqstat->mq_flags   = the_mq->oflag;
91  mqstat->mq_msgsize = the_mq->Message_queue.maximum_message_size;
92  mqstat->mq_maxmsg  = the_mq->Message_queue.maximum_pending_messages;
93  mqstat->mq_curmsgs = the_mq->Message_queue.number_of_pending_messages;
94
95  _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
96  return 0;
97}
Note: See TracBrowser for help on using the repository browser.