fix return value

This commit is contained in:
Adrien Schildknecht 2013-08-01 17:47:01 +02:00
parent 8ff4fd7c25
commit 0d8f847bb9

25
xcwd.c
View File

@ -61,15 +61,15 @@ static Window focusedWindow()
{ {
Atom type; Atom type;
Window focuswin, root, *children; Window focuswin, root, *children;
int format, status, focusrevert; int format, status;
unsigned long nitems, after; unsigned long nitems, after;
unsigned char *data;
unsigned int nchildren; unsigned int nchildren;
unsigned char *data;
dpy = XOpenDisplay (NULL); dpy = XOpenDisplay (NULL);
if (!dpy) if (!dpy)
exit (1); exit(EXIT_FAILURE);
XGetInputFocus (dpy, &focuswin, &focusrevert); XGetInputFocus (dpy, &focuswin, (int[1]){});
root = XDefaultRootWindow(dpy); root = XDefaultRootWindow(dpy);
if(root == focuswin) if(root == focuswin)
return None; return None;
@ -291,17 +291,17 @@ int main(int argc, const char *argv[])
processes_t p; processes_t p;
long pid; long pid;
int ret = EXIT_SUCCESS;
Window w = focusedWindow(); Window w = focusedWindow();
if (w == None) if (w == None)
return getHomeDirectory(); return getHomeDirectory();
pid = windowPid(w); pid = windowPid(w);
p = getProcesses(); p = getProcesses();
if(p == NULL) if(!p)
return getHomeDirectory(); return getHomeDirectory();
if (pid != -1) { if(pid != -1)
qsort(p->ps, p->n, sizeof(struct proc_s), ppidCmp); qsort(p->ps, p->n, sizeof(struct proc_s), ppidCmp);
}
else { else {
long unsigned int size; long unsigned int size;
unsigned int i; unsigned int i;
@ -322,15 +322,12 @@ int main(int argc, const char *argv[])
pid = res->pid; pid = res->pid;
LOG("Found %s (%ld)\n", res->name, res->pid); LOG("Found %s (%ld)\n", res->name, res->pid);
} }
if (size != 0) if (size)
free(strings); free(strings);
} }
if (pid == -1 || !cwdOfDeepestChild(p, pid)) { if (pid == -1 || !cwdOfDeepestChild(p, pid))
LOG("%s", "getenv $HOME...\n"); ret = getHomeDirectory();
fprintf(stdout, "%s\n", getenv("HOME"));
}
freeProcesses(p); freeProcesses(p);
return ret;
return EXIT_SUCCESS;
} }