do we really expect these to change runtime?
>From e393bd79143463bf96bede5a5596fc65288c7ecc Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Tue, 28 Sep 2010 03:40:35 +0200
Subject: [PATCH] Do not look static information up every time
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/findfile.c | 36 ++++++++++++++++++++++++------------
1 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/WINGs/findfile.c b/WINGs/findfile.c
index b5b4348..28fa256 100644
--- a/WINGs/findfile.c
+++ b/WINGs/findfile.c
@@ -35,38 +35,50 @@
char *wgethomedir()
{
- char *home = getenv("HOME");
+ static char *home = NULL;
struct passwd *user;
if (home)
return home;
+ home = getenv("HOME");
+ if (home)
+ return home;
+
user = getpwuid(getuid());
if (!user) {
werror(_("could not get password entry for UID %i"), getuid());
- return "/";
- }
- if (!user->pw_dir) {
- return "/";
- } else {
- return user->pw_dir;
+ home = "/";
}
+
+ if (!user->pw_dir)
+ home = "/";
+ else
+ home = wstrdup(user->pw_dir);
+
+out:
+ return home;
}
static char *getuserhomedir(const char *username)
{
+ static char *home = NULL;
struct passwd *user;
+ if (home)
+ return home;
+
user = getpwnam(username);
if (!user) {
werror(_("could not get password entry for user %s"), username);
return NULL;
}
- if (!user->pw_dir) {
- return "/";
- } else {
- return user->pw_dir;
- }
+ if (!user->pw_dir)
+ home = "/";
+ else
+ home = wstrdup(user->pw_dir);
+
+ return home;
}
char *wexpandpath(char *path)
--
1.7.0.4
--
[-]
mkdir /nonexistentFrom e393bd79143463bf96bede5a5596fc65288c7ecc Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Tue, 28 Sep 2010 03:40:35 +0200
Subject: [PATCH] Do not look static information up every time
Signed-off-by: Tamas TEVESZ <[email protected]>
---
WINGs/findfile.c | 36 ++++++++++++++++++++++++------------
1 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/WINGs/findfile.c b/WINGs/findfile.c
index b5b4348..28fa256 100644
--- a/WINGs/findfile.c
+++ b/WINGs/findfile.c
@@ -35,38 +35,50 @@
char *wgethomedir()
{
- char *home = getenv("HOME");
+ static char *home = NULL;
struct passwd *user;
if (home)
return home;
+ home = getenv("HOME");
+ if (home)
+ return home;
+
user = getpwuid(getuid());
if (!user) {
werror(_("could not get password entry for UID %i"), getuid());
- return "/";
- }
- if (!user->pw_dir) {
- return "/";
- } else {
- return user->pw_dir;
+ home = "/";
}
+
+ if (!user->pw_dir)
+ home = "/";
+ else
+ home = wstrdup(user->pw_dir);
+
+out:
+ return home;
}
static char *getuserhomedir(const char *username)
{
+ static char *home = NULL;
struct passwd *user;
+ if (home)
+ return home;
+
user = getpwnam(username);
if (!user) {
werror(_("could not get password entry for user %s"), username);
return NULL;
}
- if (!user->pw_dir) {
- return "/";
- } else {
- return user->pw_dir;
- }
+ if (!user->pw_dir)
+ home = "/";
+ else
+ home = wstrdup(user->pw_dir);
+
+ return home;
}
char *wexpandpath(char *path)
--
1.7.0.4