From 67860598185d248756316549a7522968f7294990 Mon Sep 17 00:00:00 2001 From: ZoRo Date: Thu, 26 Jan 2017 22:23:28 +0000 Subject: Made working basic mq IPC communication --- mq_cmd.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'mq_cmd.c') diff --git a/mq_cmd.c b/mq_cmd.c index 7f1887a..ce48713 100644 --- a/mq_cmd.c +++ b/mq_cmd.c @@ -7,19 +7,29 @@ mq_cmd* mq_cmd_create(int id, char *cmd, size_t cmd_sz, char *param, size_t para mq_cmd *ret = NULL; if (cmd == NULL) + { + PERM(); return NULL; + } if (param == NULL) + { + PERM(); return NULL; + } ret = malloc(sizeof(mq_cmd)); if (ret == NULL) + { + ENL(); return NULL; + } ret->id = id; ret->sz = MQ_CMD_MSG_SIZE; ret->buf = malloc(ret->sz); if (!ret->buf) { + ENL(); free(ret); return NULL; } @@ -31,6 +41,25 @@ mq_cmd* mq_cmd_create(int id, char *cmd, size_t cmd_sz, char *param, size_t para return ret; } +mq_cmd* mq_cmd_creates(char *str, size_t sz) +{ + mq_cmd *ret = NULL; + + //just naive belive everything is fine in string + ret = malloc(sizeof(mq_cmd)); + ret->buf = malloc(sz); + if (ret->buf == NULL) + { + PERM(); + return NULL; + } + ret->sz = sz; + memcpy(ret->buf,str,sz); + ret->id = -1; + + return ret; +} + int mq_cmd_id(mq_cmd *cmd, int *id) { int i,j,strt,sz; @@ -40,9 +69,15 @@ int mq_cmd_id(mq_cmd *cmd, int *id) /*:[ID]:*/ if (cmd == NULL) + { + PERM(); return -1; + } if (id == NULL) + { + PERM(); return -1; + } i = 0; while ((cmd->buf[i] != 0) && (isz)) @@ -84,11 +119,20 @@ char* mq_cmd_cmd(mq_cmd *cmd, char **buf, size_t *sz) char *p; if (cmd == NULL) + { + PERM(); return NULL; + } if (buf == NULL) + { + PERM(); return NULL; + } if (sz == NULL) + { + PERM(); return NULL; + } p = cmd->buf; @@ -164,6 +208,7 @@ size_t mq_cmd_size(mq_cmd *cmd) { if (cmd == NULL) { + PERM(); return -1; } return cmd->sz; @@ -173,6 +218,7 @@ char *mq_cmd_buf(mq_cmd *cmd) { if (cmd == NULL) { + PERM(); return NULL; } -- cgit v1.2.3