Fix g_autoptr_cleanup_gstring_free( ) argument to avoid of confliting arument name
[platform/upstream/glib.git] / gio / glocalvfs.c
index c29d071..7266ee0 100644 (file)
@@ -2,6 +2,8 @@
  * 
  * Copyright (C) 2006-2007 Red Hat, Inc.
  *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -27,6 +29,7 @@
 #include <gio/gdummyfile.h>
 #include <sys/types.h>
 #ifdef G_OS_UNIX
+#include "glib-unix.h"
 #include <pwd.h>
 #endif
 #include <string.h>
@@ -79,7 +82,10 @@ static GFile *
 g_local_vfs_get_file_for_path (GVfs       *vfs,
                                const char *path)
 {
-  return _g_local_file_new (path);
+  if (*path == '\0')
+    return _g_dummy_file_new (path);
+  else
+    return _g_local_file_new (path);
 }
 
 static GFile *
@@ -88,22 +94,9 @@ g_local_vfs_get_file_for_uri (GVfs       *vfs,
 {
   char *path;
   GFile *file;
-  char *stripped_uri, *hash;
-  
-  if (strchr (uri, '#') != NULL)
-    {
-      stripped_uri = g_strdup (uri);
-      hash = strchr (stripped_uri, '#');
-      *hash = 0;
-    }
-  else
-    stripped_uri = (char *)uri;
-      
-  path = g_filename_from_uri (stripped_uri, NULL, NULL);
 
-  if (stripped_uri != uri)
-    g_free (stripped_uri);
-  
+  path = g_filename_from_uri (uri, NULL, NULL);
+
   if (path != NULL)
     file = _g_local_file_new (path);
   else
@@ -160,15 +153,17 @@ g_local_vfs_parse_name (GVfs       *vfs,
               struct passwd *passwd_file_entry;
               char *user_name;
 
-             user_name = g_strndup (user_start, user_end - user_start);
-             passwd_file_entry = getpwnam (user_name);
-             g_free (user_name);
-             
-             if (passwd_file_entry != NULL &&
-                 passwd_file_entry->pw_dir != NULL)
-               user_prefix = g_strdup (passwd_file_entry->pw_dir);
-             else
-               user_prefix = g_strdup (g_get_home_dir ());
+              user_name = g_strndup (user_start, user_end - user_start);
+              passwd_file_entry = g_unix_get_passwd_entry (user_name, NULL);
+              g_free (user_name);
+
+              if (passwd_file_entry != NULL &&
+                  passwd_file_entry->pw_dir != NULL)
+                user_prefix = g_strdup (passwd_file_entry->pw_dir);
+              else
+                user_prefix = g_strdup (g_get_home_dir ());
+
+              g_free (passwd_file_entry);
            }
 #else
          user_prefix = g_strdup (g_get_home_dir ());