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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [mqueueopen.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  NOTE:  The structure of the routines is identical to that of POSIX
3
 *         Message_queues to leave the option of having unnamed message
4
 *         queues at a future date.  They are currently not part of the
5
 *         POSIX standard but unnamed message_queues are.  This is also
6
 *         the reason for the apparently unnecessary tracking of
7
 *         the process_shared attribute.  [In addition to the fact that
8
 *         it would be trivial to add pshared to the mq_attr structure
9
 *         and have process private message queues.]
10
 *
11
 *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
12
 *         time.
13
 *
14
 *  $Id: mqueueopen.c,v 1.2 2001-09-27 11:59:17 chris Exp $
15
 */
16
 
17
#include <stdarg.h>
18
 
19
#include <pthread.h>
20
#include <limits.h>
21
#include <errno.h>
22
#include <fcntl.h>
23
#include <mqueue.h>
24
 
25
#include <rtems/system.h>
26
#include <rtems/score/watchdog.h>
27
#include <rtems/posix/seterr.h>
28
#include <rtems/posix/mqueue.h>
29
#include <rtems/posix/time.h>
30
 
31
/*PAGE
32
 *
33
 *  15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
34
 */
35
 
36
mqd_t mq_open(
37
  const char *name,
38
  int         oflag,
39
  ...
40
  /* mode_t mode, */
41
  /* struct mq_attr  attr */
42
)
43
{
44
  va_list                        arg;
45
  mode_t                         mode;
46
  struct mq_attr                *attr = NULL;
47
  int                            status;
48
  Objects_Id                     the_mq_id;
49
  POSIX_Message_queue_Control   *the_mq;
50
  Objects_Locations              location;
51
 
52
  _Thread_Disable_dispatch();
53
 
54
  if ( oflag & O_CREAT ) {
55
    va_start(arg, oflag);
56
    mode = (mode_t) va_arg( arg, mode_t );
57
    attr = (struct mq_attr *) va_arg( arg, struct mq_attr * );
58
    va_end(arg);
59
  }
60
 
61
  status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id );
62
 
63
  /*
64
   *  If the name to id translation worked, then the message queue exists
65
   *  and we can just return a pointer to the id.  Otherwise we may
66
   *  need to check to see if this is a "message queue does not exist"
67
   *  or some other miscellaneous error on the name.
68
   */
69
 
70
  if ( status ) {
71
 
72
    /*
73
     * Unless provided a valid name that did not already exist
74
     * and we are willing to create then it is an error.
75
     */
76
 
77
    if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
78
      _Thread_Enable_dispatch();
79
      set_errno_and_return_minus_one_cast( status, mqd_t );
80
    }
81
 
82
  } else {                /* name -> ID translation succeeded */
83
 
84
    /*
85
     * Check for existence with creation.
86
     */
87
 
88
    if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
89
      _Thread_Enable_dispatch();
90
      set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
91
    }
92
 
93
    /*
94
     * XXX In this case we need to do an ID->pointer conversion to
95
     *     check the mode.   This is probably a good place for a subroutine.
96
     */
97
 
98
    the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
99
    the_mq->open_count += 1;
100
    _Thread_Enable_dispatch();
101
    _Thread_Enable_dispatch();
102
    return (mqd_t)the_mq->Object.id;
103
 
104
  }
105
 
106
  /*
107
   *  At this point, the message queue does not exist and everything has been
108
   *  checked. We should go ahead and create a message queue.
109
   */
110
 
111
  status = _POSIX_Message_queue_Create_support(
112
    name,
113
    TRUE,         /* shared across processes */
114
    oflag,
115
    attr,
116
    &the_mq
117
  );
118
 
119
  /*
120
   * errno was set by Create_support, so don't set it again.
121
   */
122
 
123
  _Thread_Enable_dispatch();
124
 
125
  if ( status == -1 )
126
    return (mqd_t) -1;
127
 
128
  return (mqd_t) the_mq->Object.id;
129
}
130
 
131
 
132
 
133
 
134
 

powered by: WebSVN 2.1.0

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