Fixing the last patch to the surf style.

This commit is contained in:
Christoph Lohmann 2016-06-03 15:14:53 +02:00
parent 1308872b8b
commit 31ec0fb93d

33
surf.c
View file

@ -115,6 +115,8 @@ static void addaccelgroup(Client *c);
static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, static void beforerequest(WebKitWebView *w, WebKitWebFrame *f,
WebKitWebResource *r, WebKitNetworkRequest *req, WebKitWebResource *r, WebKitNetworkRequest *req,
WebKitNetworkResponse *resp, Client *c); WebKitNetworkResponse *resp, Client *c);
static const char *getuserhomedir(const char *user);
static const char *getcurrentuserhomedir(void);
static char *buildfile(const char *path); static char *buildfile(const char *path);
static char *buildpath(const char *path); static char *buildpath(const char *path);
static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c); static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c);
@ -288,34 +290,35 @@ buildfile(const char *path)
} }
static const char* static const char*
get_user_homedir(const char *user) { getuserhomedir(const char *user)
{
struct passwd *pw = getpwnam(user); struct passwd *pw = getpwnam(user);
if (!pw) {
die("Can't get user `%s' home directory.\n", user); if (!pw)
} die("Can't get user %s login information.\n", user);
return pw->pw_dir; return pw->pw_dir;
} }
static const char* static const char*
get_current_user_homedir() { getcurrentuserhomedir(void)
{
const char *homedir; const char *homedir;
const char *user; const char *user;
struct passwd *pw; struct passwd *pw;
homedir = getenv("HOME"); homedir = getenv("HOME");
if (homedir) { if (homedir)
return homedir; return homedir;
}
user = getenv("USER"); user = getenv("USER");
if (user) { if (user)
return get_user_homedir(user); return getuserhomedir(user);
}
pw = getpwuid(getuid()); pw = getpwuid(getuid());
if (!pw) { if (!pw)
die("Can't get current user home directory\n"); die("Can't get current user home directory\n");
}
return pw->pw_dir; return pw->pw_dir;
} }
@ -323,19 +326,19 @@ char *
buildpath(const char *path) buildpath(const char *path)
{ {
char *apath, *name, *p, *fpath; char *apath, *name, *p, *fpath;
const char *homedir;
if (path[0] == '~') { if (path[0] == '~') {
const char *homedir;
if (path[1] == '/' || path[1] == '\0') { if (path[1] == '/' || path[1] == '\0') {
p = (char *)&path[1]; p = (char *)&path[1];
homedir = get_current_user_homedir(); homedir = getcurrentuserhomedir();
} else { } else {
if ((p = strchr(path, '/'))) if ((p = strchr(path, '/')))
name = g_strndup(&path[1], --p - path); name = g_strndup(&path[1], --p - path);
else else
name = g_strdup(&path[1]); name = g_strdup(&path[1]);
homedir = get_user_homedir(name); homedir = getuserhomedir(name);
g_free(name); g_free(name);
} }
apath = g_build_filename(homedir, p, NULL); apath = g_build_filename(homedir, p, NULL);