Move mch_can_exe, executable_file to os/fs.c.

* Rename executable_file to is_executable.
This commit is contained in:
Thomas Wienecke
2014-03-06 14:21:02 +01:00
committed by Thiago de Arruda
parent 1468c12fd1
commit d5b223afe2
5 changed files with 102 additions and 91 deletions

View File

@@ -1319,71 +1319,6 @@ void mch_hide(char_u *name)
/* can't hide a file */
}
int executable_file(char_u *name);
/*
* Return 1 if "name" is an executable file, 0 if not or it doesn't exist.
*/
int executable_file(char_u *name)
{
struct stat st;
if (stat((char *)name, &st))
return 0;
return S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0;
}
/*
* Return 1 if "name" can be found in $PATH and executed, 0 if not.
* Return -1 if unknown.
*/
int mch_can_exe(char_u *name)
{
char_u *buf;
char_u *p, *e;
int retval;
/* If it's an absolute or relative path don't need to use $PATH. */
if (mch_is_absolute_path(name) || (name[0] == '.' && (name[1] == '/'
|| (name[1] == '.' &&
name[2] == '/'))))
return executable_file(name);
p = (char_u *)mch_getenv("PATH");
if (p == NULL || *p == NUL)
return -1;
buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2));
if (buf == NULL)
return -1;
/*
* Walk through all entries in $PATH to check if "name" exists there and
* is an executable file.
*/
for (;; ) {
e = (char_u *)strchr((char *)p, ':');
if (e == NULL)
e = p + STRLEN(p);
if (e - p <= 1) /* empty entry means current dir */
STRCPY(buf, "./");
else {
vim_strncpy(buf, p, e - p);
add_pathsep(buf);
}
STRCAT(buf, name);
retval = executable_file(buf);
if (retval == 1)
break;
if (*e != ':')
break;
p = e + 1;
}
vim_free(buf);
return retval;
}
/*
* Check what "name" is:
* NODE_NORMAL: file or directory (or doesn't exist)