summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-23 02:12:47 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-23 02:12:47 +0100
commita04ed100da7a88bf6a8bf2f1ecb6a77fbb1ed1f8 (patch)
tree6310dd7d9a0355e99d445af725ececaaea432bce
parent7d2af49e0f344d78dc68d16f3db318be35430b38 (diff)
downloadrspamd-a04ed100da7a88bf6a8bf2f1ecb6a77fbb1ed1f8.tar.gz
rspamd-a04ed100da7a88bf6a8bf2f1ecb6a77fbb1ed1f8.zip
Add the tolower variant of strlcpy function.
-rw-r--r--src/util.c23
-rw-r--r--src/util.h11
2 files changed, 33 insertions, 1 deletions
diff --git a/src/util.c b/src/util.c
index 90497c803..88d62f974 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1325,6 +1325,29 @@ rspamd_strlcpy (gchar *dst, const gchar *src, gsize siz)
return (s - src - 1); /* count does not include NUL */
}
+gsize
+rspamd_strlcpy_tolower (gchar *dst, const gchar *src, gsize siz)
+{
+ gchar *d = dst;
+ const gchar *s = src;
+ gsize n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = g_ascii_tolower (*s++)) == '\0') {
+ break;
+ }
+ }
+ }
+
+ if (n == 0 && siz != 0) {
+ *d = '\0';
+ }
+
+ return (s - src - 1); /* count does not include NUL */
+}
+
/* Compare two emails for building emails tree */
gint
compare_email_func (gconstpointer a, gconstpointer b)
diff --git a/src/util.h b/src/util.h
index c95cc5448..405d289a3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -186,7 +186,7 @@ void g_queue_clear (GQueue *queue);
#endif
-/*
+/**
* Copy src to dest limited to len, in compare with standart strlcpy(3) rspamd strlcpy does not
* traverse the whole string and it is possible to use it for non NULL terminated strings. This is
* more like memccpy(dst, src, size, '\0')
@@ -198,6 +198,15 @@ void g_queue_clear (GQueue *queue);
*/
gsize rspamd_strlcpy (gchar *dst, const gchar *src, gsize siz);
+/**
+ * Lowercase strlcpy variant
+ * @param dst
+ * @param src
+ * @param siz
+ * @return
+ */
+gsize rspamd_strlcpy_tolower (gchar *dst, const gchar *src, gsize siz);
+
/*
* Strip <> from email address
*/