summaryrefslogtreecommitdiff
path: root/src/actions.c
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-10 14:34:09 +0200
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-10 14:34:09 +0200
commitdb8be33ae5bc8645342c62cca0a481bc0078d846 (patch)
tree27e945a315ecb807bc7ef893f06ef4b5baf2886d /src/actions.c
parent9c95991fcefa80ab54e3bc39aa3b66f2b44d05f0 (diff)
downloadratpoison-db8be33ae5bc8645342c62cca0a481bc0078d846.zip
Refactor cmd_time
* instead of playing with xmalloc, strlen and strncpy, use xstrdup to do the copying and strcspn to delete the newline
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/actions.c b/src/actions.c
index fa5af52..27a13f3 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -2691,11 +2691,10 @@ cmd_time (int interactive UNUSED, struct cmdarg **args UNUSED)
time_t timep;
cmdret *ret;
- timep = time(NULL);
- tmp = ctime(&timep);
- msg = xmalloc (strlen (tmp));
- strncpy(msg, tmp, strlen (tmp) - 1); /* Remove the newline */
- msg[strlen(tmp) - 1] = 0;
+ timep = time (NULL);
+ tmp = ctime (&timep);
+ msg = xstrdup (tmp);
+ msg[strcspn (msg, "\n")] = '\0' ; /* Remove the newline */
ret = cmdret_new (RET_SUCCESS, "%s", msg);
free (msg);