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;
33 extern char* g_vsprintf (const gchar *fmt, va_list *args, va_list *args2);
36 g_snprintf (gchar *str,
46 retval = vsnprintf (str, n, fmt, args);
56 va_start (args2, fmt);
58 printed = g_vsprintf (fmt, &args, &args2);
59 strncpy (str, printed, n);
71 g_parse_debug_string (const gchar *string,
78 g_return_val_if_fail (string != NULL, 0);
80 if (!g_strcasecmp (string, "all"))
82 for (i=0; i<nkeys; i++)
83 result |= keys[i].value;
87 gchar *str = g_strdup (string);
90 gboolean done = FALSE;
103 for (i=0; i<nkeys; i++)
104 if (!g_strcasecmp(keys[i].key, p))
105 result |= keys[i].value;
117 g_basename (const gchar *file_name)
119 register gchar *base;
121 g_return_val_if_fail (file_name != NULL, NULL);
123 base = strrchr (file_name, '/');
127 return (gchar*) file_name;
131 g_dirname (const gchar *file_name)
133 register gchar *base;
136 g_return_val_if_fail (file_name != NULL, NULL);
138 base = strrchr (file_name, '/');
140 return g_strdup (".");
141 while (base > file_name && *base == '/')
143 len = (guint) 1 + base - file_name;
145 base = g_new (gchar, len + 1);
146 g_memmove (base, file_name, len);
155 static gchar g_getcwd_buf[MAXPATHLEN + 1] = { 0 };
160 /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
161 * and, if that wasn't bad enough, hangs in doing so.
163 #if defined (sun) && !defined (__SVR4)
164 dir = getwd (g_getcwd_buf);
166 dir = getcwd (g_getcwd_buf, MAXPATHLEN);
169 if (!dir || g_getcwd_buf[0] == 0)
171 /* hm, we should probably g_error() out here...
173 g_getcwd_buf[0] = '/';
180 static gchar *g_tmp_dir = NULL;
181 static gchar *g_user_name = NULL;
182 static gchar *g_real_name = NULL;
183 static gchar *g_home_dir = NULL;
186 g_get_any_init (void)
192 g_tmp_dir = g_strdup (getenv ("TMP"));
194 g_tmp_dir = g_strdup (getenv ("TEMP"));
196 g_tmp_dir = g_strdup ("/tmp");
198 g_home_dir = g_strdup (getenv ("HOME"));
201 pw = getpwuid (getuid ());
206 g_user_name = g_strdup (pw->pw_name);
207 g_real_name = g_strdup (pw->pw_gecos);
209 g_home_dir = g_strdup (pw->pw_dir);
215 g_get_user_name (void)
224 g_get_real_name (void)
233 g_get_home_dir (void)
250 static gchar *g_prgname = NULL;
259 g_set_prgname (const gchar *prgname)
261 gchar *c = g_prgname;
263 g_prgname = g_strdup (prgname);
268 g_direct_hash(gconstpointer v)
270 return GPOINTER_TO_UINT (v);
274 g_direct_equal(gconstpointer v, gconstpointer v2)
276 return GPOINTER_TO_UINT (v) == GPOINTER_TO_UINT (v2);
280 g_int_equal (gconstpointer v, gconstpointer v2)
282 return *((const gint*) v) == *((const gint*) v2);
286 g_int_hash (gconstpointer v)
288 return *(const gint*) v;