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 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>
29 const guint glib_major_version = GLIB_MAJOR_VERSION;
30 const guint glib_minor_version = GLIB_MINOR_VERSION;
31 const guint glib_micro_version = GLIB_MICRO_VERSION;
32 const guint glib_interface_age = GLIB_INTERFACE_AGE;
33 const guint glib_binary_age = GLIB_BINARY_AGE;
35 extern char* g_vsprintf (const gchar *fmt, va_list *args, va_list *args2);
38 g_snprintf (gchar *str,
48 retval = vsnprintf (str, n, fmt, args);
52 #else /* !HAVE_VSNPRINTF */
57 va_start (args2, fmt);
59 printed = g_vsprintf (fmt, &args, &args2);
60 strncpy (str, printed, n);
67 #endif /* !HAVE_VSNPRINTF */
71 g_vsnprintf (gchar *str,
80 retval = vsnprintf (str, n, fmt, *args1);
83 #else /* !HAVE_VSNPRINTF */
86 printed = g_vsprintf (fmt, args1, args2);
87 strncpy (str, printed, n);
91 #endif /* !HAVE_VSNPRINTF */
95 g_parse_debug_string (const gchar *string,
102 g_return_val_if_fail (string != NULL, 0);
104 if (!g_strcasecmp (string, "all"))
106 for (i=0; i<nkeys; i++)
107 result |= keys[i].value;
111 gchar *str = g_strdup (string);
114 gboolean done = FALSE;
127 for (i=0; i<nkeys; i++)
128 if (!g_strcasecmp(keys[i].key, p))
129 result |= keys[i].value;
141 g_basename (const gchar *file_name)
143 register gchar *base;
145 g_return_val_if_fail (file_name != NULL, NULL);
147 base = strrchr (file_name, '/');
151 return (gchar*) file_name;
155 g_dirname (const gchar *file_name)
157 register gchar *base;
160 g_return_val_if_fail (file_name != NULL, NULL);
162 base = strrchr (file_name, '/');
164 return g_strdup (".");
165 while (base > file_name && *base == '/')
167 len = (guint) 1 + base - file_name;
169 base = g_new (gchar, len + 1);
170 g_memmove (base, file_name, len);
177 #define G_PATH_LENGTH (MAXPATHLEN + 1)
178 #elif defined (PATH_MAX)
179 #define G_PATH_LENGTH (PATH_MAX + 1)
180 #else /* !MAXPATHLEN */
181 #define G_PATH_LENGTH (2048 + 1)
182 #endif /* !MAXPATHLEN && !PATH_MAX */
185 g_get_current_dir (void)
190 buffer = g_new (gchar, G_PATH_LENGTH);
193 /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
194 * and, if that wasn't bad enough, hangs in doing so.
196 #if defined (sun) && !defined (__SVR4)
197 dir = getwd (buffer);
199 dir = getcwd (buffer, G_PATH_LENGTH - 1);
202 if (!dir || !*buffer)
204 /* hm, should we g_error() out here?
205 * this can happen if e.g. "./" has mode \0000
211 dir = g_strdup (buffer);
217 static gchar *g_tmp_dir = NULL;
218 static gchar *g_user_name = NULL;
219 static gchar *g_real_name = NULL;
220 static gchar *g_home_dir = NULL;
223 g_get_any_init (void)
229 g_tmp_dir = g_strdup (getenv ("TMPDIR"));
231 g_tmp_dir = g_strdup (getenv ("TMP"));
233 g_tmp_dir = g_strdup (getenv ("TEMP"));
235 g_tmp_dir = g_strdup ("/tmp");
237 g_home_dir = g_strdup (getenv ("HOME"));
240 pw = getpwuid (getuid ());
245 g_user_name = g_strdup (pw->pw_name);
246 g_real_name = g_strdup (pw->pw_gecos);
248 g_home_dir = g_strdup (pw->pw_dir);
254 g_get_user_name (void)
263 g_get_real_name (void)
272 g_get_home_dir (void)
289 static gchar *g_prgname = NULL;
298 g_set_prgname (const gchar *prgname)
300 gchar *c = g_prgname;
302 g_prgname = g_strdup (prgname);
307 g_direct_hash(gconstpointer v)
309 return GPOINTER_TO_UINT (v);
313 g_direct_equal(gconstpointer v, gconstpointer v2)
315 return GPOINTER_TO_UINT (v) == GPOINTER_TO_UINT (v2);
319 g_int_equal (gconstpointer v, gconstpointer v2)
321 return *((const gint*) v) == *((const gint*) v2);
325 g_int_hash (gconstpointer v)
327 return *(const gint*) v;