tAdd an echo() function - synk - synchronize files between hosts
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit da5b2a4bb3b995389485a50167dc232c8337b740
(DIR) parent 500c9acbff9c266759980f4fa5162e40056c2054
(HTM) Author: Willy <willyatmailoodotorg>
Date: Wed, 31 Aug 2016 00:15:56 +0200
Add an echo() function
Diffstat:
M synk.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/synk.c b/synk.c
t@@ -51,6 +51,8 @@ void usage(char *name);
void *sendmetadata(void *arg);
int serverloop(in_addr_t, in_port_t);
+char *echo(char * []);
+
struct peer_t *addpeer(struct peers_t *, in_addr_t, in_port_t);
long gettimestamp(const char *path);
int getpeermeta(struct peer_t *, struct metadata_t *);
t@@ -70,6 +72,30 @@ usage(char *name)
}
/*
+ * Same as the echo(1) command as defined by POSIX. Takes a like of arguments
+ * and return a string containing all args separated by white spaces.
+ */
+char *
+echo(char *args[])
+{
+ size_t len = 0;
+ char *str = NULL;
+ char **p;
+
+ str = malloc(_POSIX_ARG_MAX);
+ memset(str, 0, _POSIX_ARG_MAX);
+
+ for (p = args; *p || len > _POSIX_ARG_MAX; p++) {
+ snprintf(str + len, _POSIX_ARG_MAX, "%s ", *p);
+ len += strnlen(*p, _POSIX_ARG_MAX) + 1;
+ }
+
+ str[len-1] = 0;
+
+ return str;
+}
+
+/*
* Returns the UNIX timestamp for the given file, or -1 in case stat(2)
* is in error.
*/