86 lines
2.7 KiB
C
86 lines
2.7 KiB
C
#ifndef XPC_STRING_H_
|
|
#define XPC_STRING_H_
|
|
|
|
#include <stddef.h>
|
|
#include <xpc/status.h>
|
|
|
|
#define XPC_STRING_NPOS ((size_t)-1)
|
|
|
|
#define XPC_STRING_IN(msg, offset, size) \
|
|
{ \
|
|
.s_flags = XPC_STRING_F_IN | XPC_STRING_F_REMOTE, \
|
|
.s_origin = (msg), \
|
|
.s_offset = (offset), \
|
|
.s_len = (size), \
|
|
}
|
|
#define XPC_STRING_OUT(msg, offset, size) \
|
|
{ \
|
|
.s_flags = XPC_STRING_F_OUT | XPC_STRING_F_REMOTE, \
|
|
.s_origin = (msg), \
|
|
.s_offset = (offset), \
|
|
.s_len = (size), \
|
|
}
|
|
|
|
struct xpc_msg;
|
|
|
|
typedef enum xpc_string_flags {
|
|
/* the string can be read from */
|
|
XPC_STRING_F_IN = 0x01u,
|
|
/* the string can be written to */
|
|
XPC_STRING_F_OUT = 0x02u,
|
|
/* the string is backed by a buffer located in another address space.
|
|
* the string can only be accessed via xpc_string_read and/or
|
|
* xpc_string_write */
|
|
XPC_STRING_F_REMOTE = 0x04u,
|
|
/* free the buffer backing this string when the string is discarded.
|
|
* this is only used for out-strings. the buffer must have been
|
|
* allocated using xpc_context_alloc, as it will be freed via a call
|
|
* to xpc_context_free */
|
|
XPC_STRING_F_FREE_ON_DISCARD = 0x08u,
|
|
} xpc_string_flags_t;
|
|
|
|
typedef struct xpc_string {
|
|
xpc_string_flags_t s_flags;
|
|
union {
|
|
struct {
|
|
/* only valid if F_OUT is set. specifies the maximum
|
|
* number of chars that can be written to s_buf,
|
|
* including the null terminator. */
|
|
size_t s_max;
|
|
/* only valid if F_OUT is set.
|
|
* if F_FREE_ON_DISCARD is set, must be either NULL or
|
|
* allocated via xpc_context_alloc */
|
|
const char *s_buf;
|
|
};
|
|
|
|
struct {
|
|
/* only valid if F_IN is set. offset of the string data
|
|
* within the associated message. used when reading
|
|
* string data from a message. */
|
|
size_t s_offset;
|
|
};
|
|
};
|
|
|
|
/* only valid if F_REMOTE is set.
|
|
* used to read/write string data from/to the sender's address space. */
|
|
const struct xpc_msg *s_origin;
|
|
|
|
/* valid for both F_IN and F_OUT strings.
|
|
* F_IN: specifies the length of the incoming string data.
|
|
* F_OUT: specifies how many characters from s_buf to send. */
|
|
size_t s_len;
|
|
} xpc_string_t;
|
|
|
|
extern xpc_status_t xpc_string_read(
|
|
const xpc_string_t *s,
|
|
char *out,
|
|
size_t max,
|
|
size_t *nr_read);
|
|
extern xpc_status_t xpc_string_write(
|
|
xpc_string_t *s,
|
|
const char *in,
|
|
size_t len,
|
|
size_t *nr_written);
|
|
|
|
#endif
|