mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 23:46:17 +01:00
added g_strndup_a macro
* glib.h: added g_strndup_a macro * testglib.c: Added tests for new alloca-based string routines. Reformatted a couple strings.
This commit is contained in:
parent
00e064d2af
commit
58aaa9d32b
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
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>
|
Sat Jan 2 02:20:59 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* ghook.c:
|
* ghook.c:
|
||||||
|
11
glib.h
11
glib.h
@ -1469,6 +1469,17 @@ gpointer g_memdup (gconstpointer mem,
|
|||||||
(newstr) = __new; \
|
(newstr) = __new; \
|
||||||
} G_STMT_END
|
} 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 { \
|
# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
|
||||||
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
||||||
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
||||||
|
11
glib/glib.h
11
glib/glib.h
@ -1469,6 +1469,17 @@ gpointer g_memdup (gconstpointer mem,
|
|||||||
(newstr) = __new; \
|
(newstr) = __new; \
|
||||||
} G_STMT_END
|
} 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 { \
|
# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \
|
||||||
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \
|
||||||
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \
|
||||||
|
26
testglib.c
26
testglib.c
@ -39,6 +39,9 @@ else \
|
|||||||
#define C2P(c) ((gpointer) ((long) (c)))
|
#define C2P(c) ((gpointer) ((long) (c)))
|
||||||
#define P2C(p) ((gchar) ((long) (p)))
|
#define P2C(p) ((gchar) ((long) (p)))
|
||||||
|
|
||||||
|
#define GLIB_TEST_STRING "el dorado "
|
||||||
|
#define GLIB_TEST_STRING_5 "el do"
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
node_build_string (GNode *node,
|
node_build_string (GNode *node,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
@ -859,16 +862,35 @@ main (int argc,
|
|||||||
|
|
||||||
g_print ("endian macro tests...");
|
g_print ("endian macro tests...");
|
||||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||||
g_print ("big endian...");
|
g_print ("big endian...\n");
|
||||||
#else
|
#else
|
||||||
g_print ("little endian...");
|
g_print ("little endian...\n");
|
||||||
#endif
|
#endif
|
||||||
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
|
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
|
||||||
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
|
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
|
||||||
#ifdef G_HAVE_GINT64
|
#ifdef G_HAVE_GINT64
|
||||||
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
|
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
|
||||||
#endif
|
#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");
|
g_print ("ok\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ else \
|
|||||||
#define C2P(c) ((gpointer) ((long) (c)))
|
#define C2P(c) ((gpointer) ((long) (c)))
|
||||||
#define P2C(p) ((gchar) ((long) (p)))
|
#define P2C(p) ((gchar) ((long) (p)))
|
||||||
|
|
||||||
|
#define GLIB_TEST_STRING "el dorado "
|
||||||
|
#define GLIB_TEST_STRING_5 "el do"
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
node_build_string (GNode *node,
|
node_build_string (GNode *node,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
@ -859,16 +862,35 @@ main (int argc,
|
|||||||
|
|
||||||
g_print ("endian macro tests...");
|
g_print ("endian macro tests...");
|
||||||
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
||||||
g_print ("big endian...");
|
g_print ("big endian...\n");
|
||||||
#else
|
#else
|
||||||
g_print ("little endian...");
|
g_print ("little endian...\n");
|
||||||
#endif
|
#endif
|
||||||
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
|
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
|
||||||
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
|
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
|
||||||
#ifdef G_HAVE_GINT64
|
#ifdef G_HAVE_GINT64
|
||||||
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
|
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
|
||||||
#endif
|
#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");
|
g_print ("ok\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user