Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)
System Functions (k - m) msgrcv(2)
However, the data type for the mtype field (long int) is a problem when 64-bit processes send
and receive messages with 32-bit processes because the length of the field varies depending on
whether the caller is a 32-bit or 64-bit process. This field is 32 bits for 32-bit processes and 64
bits for 64-bit processes.
Because the msgbuf structure is user supplied, it is the application’s responsibility to handle the
differences in data types between 32-bit and 64-bit senders and receivers. For example, suppose a
64-bit process sends a msgbuf structure that contains a 64-bit mtype field to a 32-bit process.
The 32-bit process that receives the structure does not understand how to process the message
because it expects this field to be only 32 bits long. Additionally, although the mtext field starts
at the 65th bit of the message, the 32-bit process expects the mtype field to start at the 33rd bit of
the message.
To allow interoperability between 64-bit and 32-bit processes, it is recommended that 64-bit
applications define their msgbuf structure as follows:
struct msgbuf {
int mtype;
char mtext[ ];
};
and that all 64-bit callers use the MSG_32BIT_MTYPE flag in the msgflg parameter for all calls
to msgrcv() and msgsnd().
RETURN VALUES
Upon successful completion, the msgrcv() function returns the number of bytes actually stored
in the mtext field. Also, the system updates the msqid_ds structure associated with the message
queue identifier as follows:
• Decrements the value in the msg_qnum field by 1.
• Decrements the value in the msg_cbytes field by the message text size.
• Sets the msg_lrpid field to the OSS process ID of the calling process.
• Sets the msg_rtime field to the current time.
When the msgrcv() function fails, the value -1 is returned and errno is set to indicate the error.
ERRORS
If any of the following conditions occurs, the msgrcv() function sets errno to the value that
corresponds to the condition.
[E2BIG] The number of bytes to be received in the mtext field is greater than the value of
the msgsz parameter and the MSG_NOERROR flag is used in the msgflg param-
eter.
[EACCES] The calling process does not have read permission for the specified message
queue.
[EFAULT] The msqid_ds structure associated with the message queue identifier cannot be
found.
[EIDRM] The message queue identified by the msqid parameter has been removed from
the system.
527186-023 Hewlett-Packard Company 4−67