Opens a message queue.
Standard C Library (libc.a)
#include <mqueue.h>
mqd_t mq_open (name, oflag [mode, attr])
const char *name;
int oflag;
mode_t mode;
mq_attr *attr;
The mq_open subroutine establishes a connection between a process and a message queue with a message queue descriptor. It creates an open message queue description that refers to the message queue, and a message queue descriptor that refers to that open message queue description. The message queue descriptor is used by other subroutines to refer to that message queue.
The name parameter points to a string naming a message queue, and has no representation in the file system. The name parameter conforms to the construction rules for a pathname. It may or may not begin with a slash character, but contains at least one character. Processes calling the mq_open subroutine with the same value of name refer to the same message queue object, as long as that name has not been removed. If the name parameter is not the name of an existing message queue and creation is not requested, the mq_open subroutine will fail and return an error.
The oflag parameter requests the desired receive and send access to the message queue. The requested access permission to receive messages or send messages is granted if the calling process would be granted read or write access, respectively, to an equivalently protected file.
The mq_open subroutine does not add or remove messages from the queue.
Item | Description |
---|---|
name | Points to a string naming a message queue. |
oflag | Requests the desired receive and send access to the message queue. |
mode | Specifies the value of the file permission bits. Used with O_CREAT to create a message queue. |
attr | Points to an mq_attr structure. Used with O_CREAT to create a message queue. |
Upon successful completion, the mq_open subroutine returns a message queue descriptor. Otherwise, it returns (mqd_t)-1 and sets errno to indicate the error.
Item | Description |
---|---|
EACCES | The message queue exists and the permissions specified by the oflag parameter are denied. |
EEXIST | The O_CREAT and O_EXCL flags are set and the named message queue already exists. |
EFAULT | Invalid used address. |
EINVAL | The mq_open subroutine is not supported for the given name. |
EINVAL | The O_CREAT flag was specified in the oflag parameter, the value of attr is not NULL, and either mq_maxmsg or mq_msgsize was less than or equal to zero. |
EINVAL | The oflag parameter value is not valid. |
EMFILE | Too many message queue descriptors are currently in use by this process. |
ENAMETOOLONG | The length of the name parameter exceeds PATH_MAX or a pathname component is longer than NAME_MAX. |
ENFILE | Too many message queues are currently open in the system. |
ENOENT | The O_CREAT flag is not set and the named message queue does not exist. |
ENOMEM | Insufficient memory for the required operation. |
ENOSPC | There is insufficient space for the creation of the new message queue. |
ENOTSUP | This function is not supported with processes that have been checkpoint-restart'ed. |