1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
28 * Modified by Bruno Haible for use as a gnulib module.
31 /* ====================== Substitute for glibconfig.h ====================== */
34 #include <sys/types.h>
37 typedef uint16_t guint16;
38 typedef uint32_t guint32;
41 typedef ssize_t gssize;
43 #define GPOINTER_TO_INT(p) ((gint) (intptr_t) (p))
44 #define GPOINTER_TO_UINT(p) ((guint) (uintptr_t) (p))
46 #define GINT_TO_POINTER(i) ((gpointer) (intptr_t) (i))
47 #define GUINT_TO_POINTER(u) ((gpointer) (uintptr_t) (u))
49 #define g_memmove memmove
51 /* ================ Abridged version of for <glib/macros.h> ================ */
53 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
55 __attribute__((__pure__))
56 #define G_GNUC_MALLOC \
57 __attribute__((__malloc__))
64 #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
66 #define G_GNUC_NULL_TERMINATED
69 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
70 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
71 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
72 #define G_GNUC_SCANF( format_idx, arg_idx ) \
73 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
74 #define G_GNUC_FORMAT( arg_idx ) \
75 __attribute__((__format_arg__ (arg_idx)))
76 #define G_GNUC_NORETURN \
77 __attribute__((__noreturn__))
78 #define G_GNUC_CONST \
79 __attribute__((__const__))
80 #define G_GNUC_UNUSED \
81 __attribute__((__unused__))
82 #define G_GNUC_NO_INSTRUMENT \
83 __attribute__((__no_instrument_function__))
85 #define G_GNUC_PRINTF( format_idx, arg_idx )
86 #define G_GNUC_SCANF( format_idx, arg_idx )
87 #define G_GNUC_FORMAT( arg_idx )
88 #define G_GNUC_NORETURN
91 #define G_GNUC_NO_INSTRUMENT
92 #endif /* !__GNUC__ */
94 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
95 #define G_GNUC_WARN_UNUSED_RESULT \
96 __attribute__((warn_unused_result))
98 #define G_GNUC_WARN_UNUSED_RESULT
102 # define G_BEGIN_DECLS extern "C" {
103 # define G_END_DECLS }
105 # define G_BEGIN_DECLS
114 #define TRUE (!FALSE)
118 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
121 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
126 /* ====================== Substitute for <glib/gmem.h> ====================== */
130 #define g_malloc(n) xmalloc (n)
131 #define g_malloc0(n) xzalloc (n)
132 #define g_realloc(p,n) xrealloc (p, n)
133 #define g_free(p) free (p)
134 #define g_try_malloc(n) xmalloc (n)
135 #define g_try_malloc0(n) xzalloc (n)
136 #define g_try_realloc(p,n) xrealloc (p, n)
138 #define g_new(t,n) ((t *) xnmalloc (n, sizeof (t)))
139 #define g_new0(t,n) ((t *) xcalloc (n, sizeof (t)))
140 #define g_try_new(t,n) ((t *) xnmalloc (n, sizeof (t)))
141 #define g_try_new0(t,n) ((t *) xcalloc (n, sizeof (t)))
143 /* =================== Substitute for <glib/gmessages.h> =================== */
147 #define g_assert(expr) if (!(expr)) abort ()
148 #define g_assert_not_reached() abort ()
150 #define g_return_if_fail(expr) if (!(expr)) return
151 #define g_return_val_if_fail(expr,val) if (!(expr)) return (val)
152 #define g_return_if_reached() return
153 #define g_return_val_if_reached(val) return (val)
155 #define G_LOG_LEVEL_CRITICAL 0
156 #define G_LOG_LEVEL_INFO 0
157 #define G_LOG_LEVEL_DEBUG 0
159 extern void g_printerr (const char *format, ...) G_GNUC_PRINTF (1, 2);
160 extern void g_warning (const char *format, ...) G_GNUC_PRINTF (1, 2);
161 extern void g_log (const char *domain, int level, const char *format, ...) G_GNUC_PRINTF (3, 4);
163 /* ==================== Substitute for <glib/gprintf.h> ==================== */
167 #define g_printf printf
168 #define g_fprintf fprintf
169 #define g_sprintf sprintf
170 #define g_vprintf vprintf
171 #define g_vfprintf vfprintf
172 #define g_vsprintf vsprintf
173 #define g_vasprintf vasprintf
175 /* ===================== Substitute for <glib/gslice.h> ===================== */
177 #define g_slice_new(t) XMALLOC (t)
178 #define g_slice_new0(t) XZALLOC (t)
180 #define g_slice_free(t,p) free (p)
182 /* ======================= Helper for <glib/gtypes.h> ======================= */
184 /* We don't need to export variables from a shared library. */
185 #define GLIB_VAR extern
187 /* ==================== Substitute for <glib/gunicode.h> ==================== */
189 typedef unsigned int gunichar;