1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1998 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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
25 #include <sys/types.h>
26 #include <sys/param.h>
28 /* implement Glib's inline functions
30 #define G_INLINE_FUNC extern
31 #define G_CAN_INLINE 1
34 const guint glib_major_version = GLIB_MAJOR_VERSION;
35 const guint glib_minor_version = GLIB_MINOR_VERSION;
36 const guint glib_micro_version = GLIB_MICRO_VERSION;
37 const guint glib_interface_age = GLIB_INTERFACE_AGE;
38 const guint glib_binary_age = GLIB_BINARY_AGE;
42 g_snprintf (gchar *str,
52 retval = vsnprintf (str, n, fmt, args);
56 #else /* !HAVE_VSNPRINTF */
61 printed = g_strdup_vprintf (fmt, args);
64 strncpy (str, printed, n);
70 #endif /* !HAVE_VSNPRINTF */
74 g_vsnprintf (gchar *str,
82 retval = vsnprintf (str, n, fmt, args);
85 #else /* !HAVE_VSNPRINTF */
88 printed = g_strdup_vprintf (fmt, args);
89 strncpy (str, printed, n);
95 #endif /* !HAVE_VSNPRINTF */
99 g_parse_debug_string (const gchar *string,
106 g_return_val_if_fail (string != NULL, 0);
108 if (!g_strcasecmp (string, "all"))
110 for (i=0; i<nkeys; i++)
111 result |= keys[i].value;
115 gchar *str = g_strdup (string);
118 gboolean done = FALSE;
131 for (i=0; i<nkeys; i++)
132 if (!g_strcasecmp(keys[i].key, p))
133 result |= keys[i].value;
145 g_basename (const gchar *file_name)
147 register gchar *base;
149 g_return_val_if_fail (file_name != NULL, NULL);
151 base = strrchr (file_name, '/');
155 return (gchar*) file_name;
159 g_dirname (const gchar *file_name)
161 register gchar *base;
164 g_return_val_if_fail (file_name != NULL, NULL);
166 base = strrchr (file_name, '/');
168 return g_strdup (".");
169 while (base > file_name && *base == '/')
171 len = (guint) 1 + base - file_name;
173 base = g_new (gchar, len + 1);
174 g_memmove (base, file_name, len);
181 #define G_PATH_LENGTH (MAXPATHLEN + 1)
182 #elif defined (PATH_MAX)
183 #define G_PATH_LENGTH (PATH_MAX + 1)
184 #else /* !MAXPATHLEN */
185 #define G_PATH_LENGTH (2048 + 1)
186 #endif /* !MAXPATHLEN && !PATH_MAX */
189 g_get_current_dir (void)
194 buffer = g_new (gchar, G_PATH_LENGTH);
197 /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
198 * and, if that wasn't bad enough, hangs in doing so.
200 #if defined (sun) && !defined (__SVR4)
201 dir = getwd (buffer);
203 dir = getcwd (buffer, G_PATH_LENGTH - 1);
206 if (!dir || !*buffer)
208 /* hm, should we g_error() out here?
209 * this can happen if e.g. "./" has mode \0000
215 dir = g_strdup (buffer);
221 static gchar *g_tmp_dir = NULL;
222 static gchar *g_user_name = NULL;
223 static gchar *g_real_name = NULL;
224 static gchar *g_home_dir = NULL;
227 g_get_any_init (void)
233 g_tmp_dir = g_strdup (getenv ("TMPDIR"));
235 g_tmp_dir = g_strdup (getenv ("TMP"));
237 g_tmp_dir = g_strdup (getenv ("TEMP"));
239 g_tmp_dir = g_strdup ("/tmp");
241 g_home_dir = g_strdup (getenv ("HOME"));
244 pw = getpwuid (getuid ());
249 g_user_name = g_strdup (pw->pw_name);
250 g_real_name = g_strdup (pw->pw_gecos);
252 g_home_dir = g_strdup (pw->pw_dir);
258 g_get_user_name (void)
267 g_get_real_name (void)
276 g_get_home_dir (void)
293 static gchar *g_prgname = NULL;
302 g_set_prgname (const gchar *prgname)
304 gchar *c = g_prgname;
306 g_prgname = g_strdup (prgname);
311 g_direct_hash(gconstpointer v)
313 return GPOINTER_TO_UINT (v);
317 g_direct_equal(gconstpointer v, gconstpointer v2)
319 return GPOINTER_TO_UINT (v) == GPOINTER_TO_UINT (v2);
323 g_int_equal (gconstpointer v, gconstpointer v2)
325 return *((const gint*) v) == *((const gint*) v2);
329 g_int_hash (gconstpointer v)
331 return *(const gint*) v;