lib: add libxpc to implement functionality needed by xpc interfaces
This commit is contained in:
59
lib/libxpc/buffer.c
Normal file
59
lib/libxpc/buffer.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <mango/status.h>
|
||||
#include <xpc/buffer.h>
|
||||
#include <xpc/msg.h>
|
||||
|
||||
kern_status_t xpc_buffer_read(
|
||||
const xpc_buffer_t *buf,
|
||||
void *out,
|
||||
size_t max,
|
||||
size_t *nr_read)
|
||||
{
|
||||
if ((buf->buf_flags & (XPC_BUFFER_F_IN | XPC_BUFFER_F_REMOTE))
|
||||
!= (XPC_BUFFER_F_IN | XPC_BUFFER_F_REMOTE)) {
|
||||
return KERN_BAD_STATE;
|
||||
}
|
||||
|
||||
size_t to_read = max;
|
||||
if (to_read > buf->buf_len) {
|
||||
to_read = buf->buf_len;
|
||||
}
|
||||
|
||||
kern_status_t status
|
||||
= xpc_msg_read(buf->buf_origin, buf->buf_offset, out, to_read);
|
||||
if (status != KERN_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
*nr_read = to_read;
|
||||
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t xpc_buffer_write(
|
||||
xpc_buffer_t *buf,
|
||||
const void *in,
|
||||
size_t len,
|
||||
size_t *nr_written)
|
||||
{
|
||||
if ((buf->buf_flags & (XPC_BUFFER_F_OUT | XPC_BUFFER_F_REMOTE))
|
||||
!= (XPC_BUFFER_F_OUT | XPC_BUFFER_F_REMOTE)) {
|
||||
return KERN_BAD_STATE;
|
||||
}
|
||||
|
||||
size_t to_write = len;
|
||||
if (to_write > buf->buf_max) {
|
||||
to_write = buf->buf_max;
|
||||
}
|
||||
|
||||
kern_status_t status
|
||||
= xpc_msg_write(buf->buf_origin, buf->buf_offset, in, to_write);
|
||||
if (status != KERN_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
*nr_written = to_write;
|
||||
|
||||
return KERN_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user