+2005-06-22 Tor Lillqvist <tml@novell.com>
+
+ * glib/gutils.c (g_get_host_name): New function. Returns the
+ machine's name, or one of its names. Document that it is
+ best-effort only, and not guaranteed to be unique or anything.
+ (g_get_any_init): Get the host name here. On Unix use
+ gethostname(), on Windows use GetComputerName(). (#5200)
+
+ * glib/gutils.h
+ * glib/glib.symbols: Add here, too.
+
+ * tests/testglib.c: Test it.
+
2005-06-18 Matthias Clasen <mclasen@redhat.com>
* glib/goption.h:
+2005-06-22 Tor Lillqvist <tml@novell.com>
+
+ * glib/gutils.c (g_get_host_name): New function. Returns the
+ machine's name, or one of its names. Document that it is
+ best-effort only, and not guaranteed to be unique or anything.
+ (g_get_any_init): Get the host name here. On Unix use
+ gethostname(), on Windows use GetComputerName(). (#5200)
+
+ * glib/gutils.h
+ * glib/glib.symbols: Add here, too.
+
+ * tests/testglib.c: Test it.
+
2005-06-18 Matthias Clasen <mclasen@redhat.com>
* glib/goption.h:
+2005-06-22 Tor Lillqvist <tml@novell.com>
+
+ * glib/gutils.c (g_get_host_name): New function. Returns the
+ machine's name, or one of its names. Document that it is
+ best-effort only, and not guaranteed to be unique or anything.
+ (g_get_any_init): Get the host name here. On Unix use
+ gethostname(), on Windows use GetComputerName(). (#5200)
+
+ * glib/gutils.h
+ * glib/glib.symbols: Add here, too.
+
+ * tests/testglib.c: Test it.
+
2005-06-18 Matthias Clasen <mclasen@redhat.com>
* glib/goption.h:
+2005-06-22 Tor Lillqvist <tml@novell.com>
+
+ * glib/gutils.c (g_get_host_name): New function. Returns the
+ machine's name, or one of its names. Document that it is
+ best-effort only, and not guaranteed to be unique or anything.
+ (g_get_any_init): Get the host name here. On Unix use
+ gethostname(), on Windows use GetComputerName(). (#5200)
+
+ * glib/gutils.h
+ * glib/glib.symbols: Add here, too.
+
+ * tests/testglib.c: Test it.
+
2005-06-18 Matthias Clasen <mclasen@redhat.com>
* glib/goption.h:
g_getenv PRIVATE
g_unsetenv PRIVATE
g_get_home_dir PRIVATE
+g_get_host_name
g_setenv PRIVATE
g_listenv PRIVATE
#ifdef G_OS_WIN32
static gchar *g_user_name = NULL;
static gchar *g_real_name = NULL;
static gchar *g_home_dir = NULL;
+static gchar *g_host_name = NULL;
#ifdef G_OS_WIN32
/* System codepage versions of the above, kept at file level so that they,
{
if (!g_tmp_dir)
{
+ gchar hostname[100];
+
g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
if (!g_tmp_dir)
g_tmp_dir = g_strdup (g_getenv ("TMP"));
if (!g_real_name)
g_real_name = g_strdup ("Unknown");
+#ifndef G_OS_WIN32
+ if (gethostname (hostname, sizeof (hostname)) == -1)
+ g_host_name = g_strdup ("unknown");
+ else
+ g_host_name = g_strdup (hostname);
+#else
+ {
+ DWORD size = sizeof (hostname);
+
+ if (!GetComputerName (hostname, &size))
+ g_host_name = g_strdup ("unknown");
+ else
+ g_host_name = g_strdup (hostname);
+ }
+#endif
+
#ifdef G_OS_WIN32
g_tmp_dir_cp = g_locale_from_utf8 (g_tmp_dir, -1, NULL, NULL, NULL);
g_user_name_cp = g_locale_from_utf8 (g_user_name, -1, NULL, NULL, NULL);
return g_tmp_dir;
}
+/**
+ * g_get_host_name:
+ *
+ * Return a name for the machine.
+ *
+ * The returned name is not necessarily a fully-qualified domain name,
+ * or even present in DNS or some other name service at all. It need
+ * not even be unique on your local network or site, but usually it
+ * is. Callers should not rely on the return value having any specific
+ * properties like uniqueness for security purposes. Even if the name
+ * of the machine is changed while an application is running, the
+ * return value from this function does not change. The returned
+ * string is owned by GLib and should not be modified or freed. If no
+ * name can be determined, a default fixed string "unknown" is
+ * returned.
+ */
+const gchar *
+g_get_host_name (void)
+{
+ G_LOCK (g_utils_global);
+ if (!g_tmp_dir)
+ g_get_any_init ();
+ G_UNLOCK (g_utils_global);
+
+ return g_host_name;
+}
+
G_LOCK_DEFINE_STATIC (g_prgname);
static gchar *g_prgname = NULL;
G_CONST_RETURN gchar* g_get_real_name (void);
G_CONST_RETURN gchar* g_get_home_dir (void);
G_CONST_RETURN gchar* g_get_tmp_dir (void);
+G_CONST_RETURN gchar* g_get_host_name (void);
gchar* g_get_prgname (void);
void g_set_prgname (const gchar *prgname);
G_CONST_RETURN gchar* g_get_application_name (void);
g_free (string);
g_print ("user: %s\n", g_get_user_name ());
g_print ("real: %s\n", g_get_real_name ());
+ g_print ("host: %s\n", g_get_host_name ());
s = g_get_home_dir ();
g_print ("home: %s\n", s ? s : "NULL!");
s = g_get_user_data_dir ();