wmii/libixp/message.c

173 lines
3.5 KiB
C
Raw Normal View History

2005-11-18 18:54:58 +03:00
/*
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <string.h>
#include "ixp.h"
#include <cext.h>
2005-12-05 01:45:59 +03:00
void *tcreate_message(char *path, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ReqHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ReqHeader) + strlen(path) + 1;
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.req = TCREATE;
memcpy(msg, &h, sizeof(ReqHeader));
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
return msg;
}
2005-12-05 01:45:59 +03:00
void *topen_message(char *path, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ReqHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ReqHeader) + strlen(path) + 1;
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.req = TOPEN;
memcpy(msg, &h, sizeof(ReqHeader));
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
return msg;
}
2005-12-05 01:45:59 +03:00
void *tread_message(int fd, size_t offset, size_t buf_len,
size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ReqHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ReqHeader);
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.req = TREAD;
h.fd = fd;
h.offset = offset;
h.buf_len = buf_len;
memcpy(msg, &h, sizeof(ReqHeader));
return msg;
}
2005-12-05 01:45:59 +03:00
void *twrite_message(int fd, size_t offset, void *content,
size_t content_len, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ReqHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ReqHeader) + content_len;
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.req = TWRITE;
h.fd = fd;
h.offset = offset;
h.buf_len = content_len;
memcpy(msg, &h, sizeof(ReqHeader));
memcpy(msg + sizeof(ReqHeader), content, content_len);
return msg;
}
2005-12-05 01:45:59 +03:00
void *tclose_message(int fd, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ReqHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ReqHeader);
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.req = TCLUNK;
h.fd = fd;
memcpy(msg, &h, sizeof(ReqHeader));
return msg;
}
2005-12-05 01:45:59 +03:00
void *tremove_message(char *path, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ReqHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ReqHeader) + strlen(path) + 1;
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.req = TREMOVE;
memcpy(msg, &h, sizeof(ReqHeader));
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
return msg;
}
2005-12-05 01:45:59 +03:00
void *rcreate_message(size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ResHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ResHeader);
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.res = RCREATE;
memcpy(msg, &h, sizeof(ResHeader));
return msg;
}
2005-12-05 01:45:59 +03:00
void *ropen_message(int fd, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ResHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ResHeader);
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.res = ROPEN;
h.fd = fd;
memcpy(msg, &h, sizeof(ResHeader));
return msg;
}
2005-12-05 01:45:59 +03:00
void *rread_message(void *content, size_t content_len, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ResHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ResHeader) + content_len;
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.res = RREAD;
h.buf_len = content_len;
memcpy(msg, &h, sizeof(ResHeader));
memmove(msg + sizeof(ResHeader), content, content_len);
return msg;
}
2005-12-05 01:45:59 +03:00
void *rwrite_message(size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ResHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ResHeader);
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.res = RWRITE;
memcpy(msg, &h, sizeof(ResHeader));
return msg;
}
2005-12-05 01:45:59 +03:00
void *rclose_message(size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ResHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ResHeader);
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.res = RCLUNK;
memcpy(msg, &h, sizeof(ResHeader));
return msg;
}
2005-12-05 01:45:59 +03:00
void *rremove_message(size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
ResHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ResHeader);
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.res = RREMOVE;
memcpy(msg, &h, sizeof(ResHeader));
return msg;
}
2005-12-05 01:45:59 +03:00
void *rerror_message(char *errstr, size_t * msg_len)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
char *msg;
size_t len = strlen(errstr) + 1;
ResHeader h;
2005-11-18 18:54:58 +03:00
*msg_len = sizeof(ResHeader) + len;
msg = cext_emallocz(*msg_len);
2005-11-18 18:54:58 +03:00
h.res = RERROR;
memcpy(msg, &h, sizeof(ResHeader));
memmove(msg + sizeof(ResHeader), errstr, len);
return msg;
}