* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include "glibconfig.h"
#ifdef HAVE_UNISTD_H
return getenv (variable);
#else
gchar *v;
- guint l, k;
- gchar *p;
+ guint k;
+ static gchar *p = NULL;
+ static gint l;
+ gchar dummy[2];
g_return_val_if_fail (variable != NULL, NULL);
* calling ExpandEnvironmentStrings.
*/
- v = g_strdup (v);
- l = 16;
- do
+ /* First check how much space we need */
+ k = ExpandEnvironmentStrings (v, dummy, 2);
+ /* Then allocate that much, and actualy do the expansion */
+ if (p == NULL)
{
- p = g_new (gchar, l);
-
- k = ExpandEnvironmentStrings (v, p, l);
- if (k > l)
- {
- g_free (p);
- l *= 2;
- }
+ p = g_malloc (k);
+ l = k;
}
- while (k > l);
-
- g_free (v);
-
+ else if (k > l)
+ {
+ p = g_realloc (p, k);
+ l = k;
+ }
+ ExpandEnvironmentStrings (v, p, k);
return p;
#endif
}
if (!g_tmp_dir)
g_tmp_dir = g_strdup (g_getenv ("TEMP"));
+#ifdef P_tmpdir
+ if (!g_tmp_dir)
+ {
+ int k;
+ g_tmp_dir = g_strdup (P_tmpdir);
+ k = strlen (g_tmp_dir);
+ if (g_tmp_dir[k-1] == G_DIR_SEPARATOR)
+ g_tmp_dir[k-1] = '\0';
+ }
+#endif
if (!g_tmp_dir)
{
#ifndef NATIVE_WIN32
- g_tmp_dir = g_strdup (G_DIR_SEPARATOR_S "tmp");
-#else /* !NATIVE_WIN32 */
- g_tmp_dir = g_strdup (".");
-#endif /* !NATIVE_WIN32 */
+ g_tmp_dir = g_strdup ("/tmp");
+#else /* NATIVE_WIN32 */
+ g_tmp_dir = g_strdup ("C:\\");
+#endif /* NATIVE_WIN32 */
}
g_home_dir = g_strdup (g_getenv ("HOME"));
}
else
g_real_name = g_strdup (g_user_name);
- g_home_dir = NULL;
}
# else /* !NATIVE_WIN32 */
g_user_name = g_strdup ("somebody");
# endif /* !NATIVE_WIN32 */
#endif /* !HAVE_PWD_H */
}
-
- if (!g_home_dir)
- g_home_dir = g_strdup (g_tmp_dir);
}
gchar*
return g_real_name;
}
+/* Return the home directory of the user. If there is a HOME
+ * environment variable, its value is returned, otherwise use some
+ * system-dependent way of finding it out. If no home directory can be
+ * deduced, return NULL.
+ */
+
gchar*
g_get_home_dir (void)
{
return g_home_dir;
}
+/* Return a directory to be used to store temporary files. This is the
+ * value of the TMPDIR, TMP or TEMP environment variables (they are
+ * checked in that order). If none of those exist, use P_tmpdir from
+ * stdio.h. If that isn't defined, return "/tmp" on POSIXly systems,
+ * and C:\ on Windows.
+ */
+
gchar*
g_get_tmp_dir (void)
{
GIOChannel*
g_iochannel_new (gint fd)
{
- GIOChannel *channel = g_new0 (GIOChannel, 1);
+ GIOChannel *channel = g_new (GIOChannel, 1);
channel->fd = fd;
channel->peer = 0;
channel->peer_fd = 0;
channel->offset = 0;
- channel->peer_offset = 0;
+ channel->need_wakeups = 0;
#endif /* NATIVE_WIN32 */
return channel;