Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2006-10-08 08:44:47 +0400
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2006-10-08 08:44:47 +0400
commit423dac532236f11fe1ac2785ad2c1330b5972290 (patch)
tree0a5562cd9fcc14caa16763859717127d381f773b /eglib
parent3950b3e1af95f4e45041bb814bf3153afab9e50d (diff)
2006-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* test/string-util.c: * configure.ac: * TODO: * src/gstr.c: * src/glib.h: implemented g_strlcpy. svn path=/trunk/mono/; revision=66394
Diffstat (limited to 'eglib')
-rw-r--r--eglib/ChangeLog8
-rw-r--r--eglib/TODO1
-rw-r--r--eglib/configure.ac3
-rw-r--r--eglib/src/glib.h6
-rw-r--r--eglib/src/gstr.c33
-rw-r--r--eglib/test/string-util.c38
6 files changed, 87 insertions, 2 deletions
diff --git a/eglib/ChangeLog b/eglib/ChangeLog
index 9bdcdde173b..aed2fcb1146 100644
--- a/eglib/ChangeLog
+++ b/eglib/ChangeLog
@@ -1,6 +1,14 @@
2006-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* test/string-util.c:
+ * configure.ac:
+ * TODO:
+ * src/gstr.c:
+ * src/glib.h: implemented g_strlcpy.
+
+2006-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * test/string-util.c:
* TODO:
* src/gstr.c:
* src/glib.h: implemented g_strdelimit.
diff --git a/eglib/TODO b/eglib/TODO
index b1c54826d23..8e8bb0833c5 100644
--- a/eglib/TODO
+++ b/eglib/TODO
@@ -21,7 +21,6 @@ Important Groups:
* String manipulation
1 g_filename_from_utf8 [LIMITATION: UTF8 only today]
- 10 g_strlcpy
1 g_strescape
* Miscelaneous
diff --git a/eglib/configure.ac b/eglib/configure.ac
index 347375d4772..f942f714211 100644
--- a/eglib/configure.ac
+++ b/eglib/configure.ac
@@ -50,6 +50,7 @@ AC_SUBST(OS)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(void *)
+AC_CHECK_FUNCS(strlcpy)
if test $ac_cv_sizeof_void_p != $ac_cv_sizeof_int; then
GPOINTER_TO_INT="((gint)(long) (ptr))"
@@ -81,4 +82,4 @@ Makefile
src/Makefile
src/eglib-config.h
test/Makefile
-]) \ No newline at end of file
+])
diff --git a/eglib/src/glib.h b/eglib/src/glib.h
index 61c39657d4f..3629a294b76 100644
--- a/eglib/src/glib.h
+++ b/eglib/src/glib.h
@@ -190,6 +190,12 @@ gint g_snprintf (gchar *string, gulong n, gchar const *format, ..
#define g_vsnprintf vsnprintf
#define g_vasprintf vasprintf
+#ifdef HAVE_STRLCPY
+#define g_strlcpy strlcpy
+#else
+gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
+#endif
+
#define g_ascii_isspace(c) (isspace (c) != 0)
#define g_ascii_isalpha(c) (isalpha (c) != 0)
#define g_ascii_isprint(c) (isprint (c) != 0)
diff --git a/eglib/src/gstr.c b/eglib/src/gstr.c
index 04666da134b..5cd6ad479a0 100644
--- a/eglib/src/gstr.c
+++ b/eglib/src/gstr.c
@@ -528,3 +528,36 @@ g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter)
return string;
}
+#ifndef HAVE_STRLCPY
+gsize
+g_strlcpy (gchar *dest, const gchar *src, gsize dest_size)
+{
+ gchar *d;
+ const gchar *s;
+ gchar c;
+ gsize len;
+
+ g_return_val_if_fail (src != NULL, 0);
+ g_return_val_if_fail (dest != NULL, 0);
+
+ len = dest_size;
+ if (len == 0)
+ return 0;
+
+ s = src;
+ d = dest;
+ while (--len) {
+ c = *s++;
+ *d++ = c;
+ if (c == '\0')
+ return (dest_size - len - 1);
+ }
+
+ /* len is 0 i we get here */
+ *d = '\0';
+ /* we need to return the length of src here */
+ while (*s++) ; /* instead of a plain strlen, we use 's' */
+ return s - src - 1;
+}
+#endif
+
diff --git a/eglib/test/string-util.c b/eglib/test/string-util.c
index 833e52a19cf..8483918952a 100644
--- a/eglib/test/string-util.c
+++ b/eglib/test/string-util.c
@@ -285,6 +285,43 @@ test_strdelimit ()
return OK;
}
+RESULT
+test_strlcpy ()
+{
+ const gchar *src = "onetwothree";
+ gchar *dest;
+ int i;
+
+ dest = g_malloc (strlen (src) + 1);
+ memset (dest, 0, strlen (src) + 1);
+ i = g_strlcpy (dest, src, -1);
+ if (i != strlen (src))
+ return FAILED ("Test1 got %d", i);
+
+ if (0 != strcmp (dest, src))
+ return FAILED ("Src and dest not equal");
+
+ i = g_strlcpy (dest, src, 3);
+ if (i != strlen (src))
+ return FAILED ("Test1 got %d", i);
+ if (0 != strcmp (dest, "on"))
+ return FAILED ("Test2");
+
+ i = g_strlcpy (dest, src, 1);
+ if (i != strlen (src))
+ return FAILED ("Test3 got %d", i);
+ if (*dest != '\0')
+ return FAILED ("Test4");
+
+ i = g_strlcpy (dest, src, 12345);
+ if (i != strlen (src))
+ return FAILED ("Test4 got %d", i);
+ if (0 != strcmp (dest, src))
+ return FAILED ("Src and dest not equal 2");
+ g_free (dest);
+ return OK;
+}
+
static Test strutil_tests [] = {
{"g_strfreev", test_strfreev},
{"g_strconcat", test_concat},
@@ -298,6 +335,7 @@ static Test strutil_tests [] = {
{"g_filename_from_uri", test_filename_from_uri},
{"g_ascii_xdigit_value", test_ascii_xdigit_value},
{"g_strdelimit", test_strdelimit},
+ {"g_strlcpy", test_strlcpy},
{NULL, NULL}
};