+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
+Fri Jan 1 20:43:19 EST 1999 Jeff Garzik <jgarzik@pobox.com>
+
+ * glib.h: added g_strndup_a macro
+
+ * testglib.c:
+ Added tests for new alloca-based string routines.
+ Reformatted a couple strings.
+
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
* ghook.c:
(newstr) = __new; \
} G_STMT_END
+# define g_strndup_a(newstr,str,n) G_STMT_START { \
+ const char *__old = (str); \
+ char *__new; \
+ size_t __len = strlen (__old); \
+ if (__len > (n)) __len = (n); \
+ __new = alloca (__len + 1); \
+ memcpy (__new, __old, __len); \
+ __new[__len] = 0; \
+ (newstr) = __new; \
+ } G_STMT_END
+
# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
(newstr) = __new; \
} G_STMT_END
+# define g_strndup_a(newstr,str,n) G_STMT_START { \
+ const char *__old = (str); \
+ char *__new; \
+ size_t __len = strlen (__old); \
+ if (__len > (n)) __len = (n); \
+ __new = alloca (__len + 1); \
+ memcpy (__new, __old, __len); \
+ __new[__len] = 0; \
+ (newstr) = __new; \
+ } G_STMT_END
+
# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
#define C2P(c) ((gpointer) ((long) (c)))
#define P2C(p) ((gchar) ((long) (p)))
+#define GLIB_TEST_STRING "el dorado "
+#define GLIB_TEST_STRING_5 "el do"
+
static gboolean
node_build_string (GNode *node,
gpointer data)
g_print ("endian macro tests...");
#if G_BYTE_ORDER == G_BIG_ENDIAN
- g_print ("big endian...");
+ g_print ("big endian...\n");
#else
- g_print ("little endian...");
+ g_print ("little endian...\n");
#endif
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
#ifdef G_HAVE_GINT64
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
#endif
+
+#ifdef G_HAVE_ALLOCA
+ /* test alloca()-based string duplication routines */
+ g_strdup_a(string, GLIB_TEST_STRING);
+ g_assert(string != NULL);
+ g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
+
+ g_strndup_a(string, GLIB_TEST_STRING, 5);
+ g_assert(string != NULL);
+ g_assert(strlen(string) == 5);
+ g_assert(strcmp(string, GLIB_TEST_STRING_5) == 0);
+
+ g_strconcat_a(string, GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING);
+ g_assert(string != NULL);
+ g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
+ GLIB_TEST_STRING) == 0);
+#endif
+
g_print ("ok\n");
return 0;
}
+
#define C2P(c) ((gpointer) ((long) (c)))
#define P2C(p) ((gchar) ((long) (p)))
+#define GLIB_TEST_STRING "el dorado "
+#define GLIB_TEST_STRING_5 "el do"
+
static gboolean
node_build_string (GNode *node,
gpointer data)
g_print ("endian macro tests...");
#if G_BYTE_ORDER == G_BIG_ENDIAN
- g_print ("big endian...");
+ g_print ("big endian...\n");
#else
- g_print ("little endian...");
+ g_print ("little endian...\n");
#endif
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
#ifdef G_HAVE_GINT64
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
#endif
+
+#ifdef G_HAVE_ALLOCA
+ /* test alloca()-based string duplication routines */
+ g_strdup_a(string, GLIB_TEST_STRING);
+ g_assert(string != NULL);
+ g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
+
+ g_strndup_a(string, GLIB_TEST_STRING, 5);
+ g_assert(string != NULL);
+ g_assert(strlen(string) == 5);
+ g_assert(strcmp(string, GLIB_TEST_STRING_5) == 0);
+
+ g_strconcat_a(string, GLIB_TEST_STRING, GLIB_TEST_STRING, GLIB_TEST_STRING);
+ g_assert(string != NULL);
+ g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
+ GLIB_TEST_STRING) == 0);
+#endif
+
g_print ("ok\n");
return 0;
}
+