+static int path_open(const char *name, const char *search)
+{
+ char buf[2*NAME_MAX+2];
+ const char *s, *z;
+ int l, fd;
+ for (s=search; *s; s+=l+!!z) {
+ z = strchr(s, ':');
+ l = z ? z-s : strlen(s);
+ snprintf(buf, sizeof buf, "%.*s/%s", l, s, name);
+ if ((fd = open(buf, O_RDONLY))>=0) return fd;
+ }
+ return -1;
+}
+