database: call getuid only once
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 25 Oct 2017 09:30:57 +0000 (11:30 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 25 Oct 2017 09:30:57 +0000 (11:30 +0200)
Change-Id: I249c0b712a66016bb578f203dc62ecaf6dac2b91
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
ll-database-binding/src/ll-database-binding.c

index bbbba80..e878896 100644 (file)
@@ -72,11 +72,12 @@ static int get_database_path(char *buffer, size_t size)
                        rc = snprintf(buffer, size, "%s/.config/%s", home, dbfile);
                else
                {
-                       struct passwd *pwd = getpwuid(getuid());
+                       uid_t uid = getuid();
+                       struct passwd *pwd = getpwuid(uid);
                        if (pwd)
                                rc = snprintf(buffer, size, "%s/.config/%s", pwd->pw_dir, dbfile);
                        else
-                               rc = snprintf(buffer, size, "/home/%d/.config/%s", (int)getuid(), dbfile);
+                               rc = snprintf(buffer, size, "/home/%d/.config/%s", (int)uid, dbfile);
                }
        }
        return rc;