lookup executable in search path
prepend cwd unless test string is an absolute path
generalize to any search string.

Also includes memory usage improvements.
reduce variable scope
d_namlen is Darwin specific
Add path_lookup for e.g. $PATH exe lookups.

* pull-316:
  d_namlen is Darwin specific
  reduce variable scope
  generalize to any search string.
  prepend cwd unless test string is an absolute path
  lookup executable in search path