mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 05:54:08 +00:00
dix: rpcbuf: add x_rpcbuf_write_string_0t_pad()
The existing x_rpcbuf_write_string() function is just writing the string w/o trailing zero. It's for cases where the string length is known by other means (eg. some header field). In cases where we also need the trailing zero written (eg. when sending lists of strings) this isn't sufficient. Thus introducing another variant of this function, which is always writing a leading zero. Using this one, the string's characters will be followed by 1, 2 or 3 zeros (and also be 32bit aligned) Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
17
dix/rpcbuf.c
17
dix/rpcbuf.c
@@ -93,6 +93,23 @@ Bool x_rpcbuf_write_string_pad(struct x_rpcbuf *rpcbuf, const char *str)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Bool x_rpcbuf_write_string_0t_pad(struct x_rpcbuf *rpcbuf, const char *str)
|
||||
{
|
||||
if (!str)
|
||||
return x_rpcbuf_write_CARD32(rpcbuf, 0);
|
||||
|
||||
size_t slen = strlen(str);
|
||||
if (!slen)
|
||||
return x_rpcbuf_write_CARD32(rpcbuf, 0);
|
||||
|
||||
char *reserved = x_rpcbuf_reserve(rpcbuf, pad_to_int32(slen+1));
|
||||
if (!reserved)
|
||||
return FALSE;
|
||||
|
||||
memcpy(reserved, str, slen+1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Bool x_rpcbuf_write_CARD8(struct x_rpcbuf *rpcbuf, CARD8 value)
|
||||
{
|
||||
CARD8 *reserved = x_rpcbuf_reserve(rpcbuf, sizeof(value));
|
||||
|
||||
Reference in New Issue
Block a user