diff options
Diffstat (limited to 'mq_cmd.c')
-rw-r--r-- | mq_cmd.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -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) && (i<cmd->sz)) @@ -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; } |