summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7758a9e)
raw | patch | inline | side by side (parent: 7758a9e)
author | Florian Forster <ff@octo.it> | |
Wed, 9 Jun 2010 17:02:30 +0000 (19:02 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 9 Jun 2010 17:02:30 +0000 (19:02 +0200) |
common.c | patch | blob | history | |
common.h | patch | blob | history |
diff --git a/common.c b/common.c
index a2bfd090f612a255104874b770e7b2dec60a2215..ec267af957a80ea15ff5707a671d3ee9903512cf 100644 (file)
--- a/common.c
+++ b/common.c
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
+#include <assert.h>
#include "common.h"
return (foreach_dir (DATA_DIR, callback, user_data));
} /* }}} int foreach_host */
+size_t c_strlcat (char *dst, const char *src, size_t size) /* {{{ */
+{
+ size_t retval;
+ size_t dst_len;
+ size_t src_len;
+
+ dst_len = strlen (dst);
+ src_len = strlen (src);
+ retval = dst_len + src_len;
+
+ if ((dst_len + 1) >= size)
+ return (retval);
+
+ dst += dst_len;
+ size -= dst_len;
+ assert (size >= 2);
+
+ /* Result will be truncated. */
+ if (src_len >= size)
+ src_len = size - 1;
+
+ memcpy (dst, src, src_len);
+ dst[src_len] = 0;
+
+ return (retval);
+} /* }}} size_t c_strlcat */
+
+
+
/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/common.h b/common.h
index 01c8710eb010c4560af4880701e6049a5234c3a1..e211406eb5e95fce9403a84f29c5b47467dc46b2 100644 (file)
--- a/common.h
+++ b/common.h
int foreach_plugin (const char *host, callback_plugin_t, void *user_data);
int foreach_host (callback_host_t, void *user_data);
+size_t c_strlcat (char *dst, const char *src, size_t size);
+#define strlcat c_strlcat
+
#endif /* COMMON_H */
/* vim: set sw=2 sts=2 et fdm=marker : */