Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in portage-utils/libq: which.c
Date: Tue, 01 Mar 2011 04:58:49
Message-Id: 20110301045839.502E220054@flycatcher.gentoo.org
1 vapier 11/03/01 04:58:39
2
3 Modified: which.c
4 Log:
5 touch up style a bit
6
7 Revision Changes Path
8 1.2 portage-utils/libq/which.c
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/which.c?rev=1.2&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/which.c?rev=1.2&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/which.c?r1=1.1&r2=1.2
13
14 Index: which.c
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/which.c,v
17 retrieving revision 1.1
18 retrieving revision 1.2
19 diff -u -r1.1 -r1.2
20 --- which.c 15 Apr 2007 21:42:20 -0000 1.1
21 +++ which.c 1 Mar 2011 04:58:39 -0000 1.2
22 @@ -2,19 +2,24 @@
23 static char *which(const char *fname)
24 {
25 static char fullpath[BUFSIZ];
26 - char *path, *p;
27 + char *ret, *path, *p;
28 +
29 + ret = NULL;
30 +
31 path = getenv("PATH");
32 if (!path)
33 - return NULL;
34 + return ret;
35 +
36 path = xstrdup(path);
37 while ((p = strrchr(path, ':')) != NULL) {
38 snprintf(fullpath, sizeof(fullpath), "%s/%s", p + 1, fname);
39 *p = 0;
40 - if (access(fullpath, R_OK) != (-1)) {
41 - free(path);
42 - return (char *) fullpath;
43 + if (access(fullpath, R_OK) != -1) {
44 + ret = fullpath;
45 + break;
46 }
47 }
48 free(path);
49 - return NULL;
50 +
51 + return ret;
52 }