Fix typo
[platform/upstream/glib.git] / glib / gwin32.c
index 14579e2..ffc5fe2 100644 (file)
@@ -161,12 +161,12 @@ g_win32_getlocale (void)
  * g_win32_error_message:
  * @error: error code.
  *
- * Translate a Win32 error code (as returned by GetLastError()) into
- * the corresponding message. The message is either language neutral,
- * or in the thread's language, or the user's language, the system's
- * language, or US English (see docs for FormatMessage()). The
- * returned string is in UTF-8. It should be deallocated with
- * g_free().
+ * Translate a Win32 error code (as returned by GetLastError() or
+ * WSAGetLastError()) into the corresponding message. The message is
+ * either language neutral, or in the thread's language, or the user's
+ * language, the system's language, or US English (see docs for
+ * FormatMessage()). The returned string is in UTF-8. It should be
+ * deallocated with g_free().
  *
  * Returns: newly-allocated error message
  **/
@@ -238,22 +238,43 @@ g_win32_error_message (gint error)
 gchar *
 g_win32_get_package_installation_directory_of_module (gpointer hmodule)
 {
+  gchar *filename;
   gchar *retval;
   gchar *p;
   wchar_t wc_fn[MAX_PATH];
 
+  /* NOTE: it relies that GetModuleFileNameW returns only canonical paths */
   if (!GetModuleFileNameW (hmodule, wc_fn, MAX_PATH))
     return NULL;
 
-  retval = g_utf16_to_utf8 (wc_fn, -1, NULL, NULL, NULL);
+  filename = g_utf16_to_utf8 (wc_fn, -1, NULL, NULL, NULL);
 
-  if ((p = strrchr (retval, G_DIR_SEPARATOR)) != NULL)
+  if ((p = strrchr (filename, G_DIR_SEPARATOR)) != NULL)
     *p = '\0';
 
-  p = strrchr (retval, G_DIR_SEPARATOR);
-  if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0 ||
-           g_ascii_strcasecmp (p + 1, "lib") == 0))
-    *p = '\0';
+  retval = g_strdup (filename);
+
+  do
+    {
+      p = strrchr (retval, G_DIR_SEPARATOR);
+      if (p == NULL)
+        break;
+
+      *p = '\0';
+
+      if (g_ascii_strcasecmp (p + 1, "bin") == 0 ||
+          g_ascii_strcasecmp (p + 1, "lib") == 0)
+        break;
+    }
+  while (p != NULL);
+
+  if (p == NULL)
+    {
+      g_free (retval);
+      retval = filename;
+    }
+  else
+    g_free (filename);
 
 #ifdef G_WITH_CYGWIN
   /* In Cygwin we need to have POSIX paths */
@@ -335,8 +356,8 @@ get_package_directory_from_module (const gchar *module_name)
  * the package, typically the same identifier as used for
  * `GETTEXT_PACKAGE` in software configured using GNU
  * autotools. The function first looks in the Windows Registry for the
- * value `#InstallationDirectory` in the key
- * `#HKLM\Software\@package`, and if that value
+ * value `#InstallationDirectory` in the key
+ * `#HKLM\Software\@package`, and if that value
  * exists and is a string, returns that.
  *
  * It is strongly recommended that packagers of GLib-using libraries
@@ -547,7 +568,7 @@ g_win32_get_windows_version (void)
  * The return value is dynamically allocated and should be freed with
  * g_free() when no longer needed.
  *
- * Return value: The converted filename, or %NULL on conversion
+ * Returns: The converted filename, or %NULL on conversion
  * failure and lack of short names.
  *
  * Since: 2.8