about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2012-11-18 01:51:01 +0200
committerDmitry Podgorny <pasis.ua@gmail.com>2012-11-18 01:51:01 +0200
commitcf3d50f855a0ce3adf24d05121bc4c4b5c1910dc (patch)
tree883c150313aea30313d8293f341b462cbee94043
parent2fe5e7bd5914c3062e8f914492e4e745ab6b9a15 (diff)
downloadprofani-tty-cf3d50f855a0ce3adf24d05121bc4c4b5c1910dc.tar.gz
command.c: replace strndup with strdup
Function strndup conforms to POSIX.1-2008 and MacOS doesn't have it.
strndup doesn't make sense when a string is copied to the end. So
replacing fixes incompatibility with MacOS and doesn't influence to
execution.
-rw-r--r--src/command.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/command.c b/src/command.c
index a02c77e9..55b755f2 100644
--- a/src/command.c
+++ b/src/command.c
@@ -1010,7 +1010,7 @@ _cmd_help(const char * const inp, struct cmd_help_t help)
     } else if (strcmp(inp, "/help navigation") == 0) {
         cons_navigation_help();
     } else {
-        char *cmd = strndup(inp+6, strlen(inp)-6);
+        char *cmd = strdup(inp + 6);
         char cmd_with_slash[1 + strlen(cmd) + 1];
         sprintf(cmd_with_slash, "/%s", cmd);
 
@@ -1193,7 +1193,7 @@ _cmd_msg(const char * const inp, struct cmd_help_t help)
         usr = strtok(NULL, " ");
         if ((usr != NULL) && (strlen(inp) > (5 + strlen(usr) + 1))) {
             // get message
-            msg = strndup(inp+5+strlen(usr)+1, strlen(inp)-(5+strlen(usr)+1));
+            msg = strdup(inp + 5 + strlen(usr) + 1);
 
             if (msg != NULL) {
                 jabber_send(msg, usr);
@@ -1205,6 +1205,8 @@ _cmd_msg(const char * const inp, struct cmd_help_t help)
                 }
 
             } else {
+                /* TODO: this should be error while sending message cause
+                 * this is the case when strdup can't allocate memory */
                 cons_show("Usage: %s", help.usage);
             }
         } else {
@@ -1612,7 +1614,7 @@ _update_presence(const jabber_presence_t presence,
 {
     char *msg;
     if (strlen(inp) > strlen(show) + 2) {
-        msg = strndup(inp+(strlen(show) + 2), strlen(inp)-(strlen(show) + 2));
+        msg = strdup(inp + strlen(show) + 2);
     } else {
         msg = NULL;
     }