Consider executable extensions in case of some test commands on OS/2

-r, -w, -x, -a, -e, -f.
This commit is contained in:
KO Myung-Hun 2015-05-11 13:43:56 +09:00
parent fdd0831a58
commit a03cf65602
4 changed files with 24 additions and 4 deletions

4
expr.c
View File

@ -906,12 +906,16 @@ int
ksh_access(const char *fn, int mode) ksh_access(const char *fn, int mode)
{ {
int rv; int rv;
#ifndef __OS2__
struct stat sb; struct stat sb;
if ((rv = access(fn, mode)) == 0 && kshuid == 0 && (mode & X_OK) && if ((rv = access(fn, mode)) == 0 && kshuid == 0 && (mode & X_OK) &&
(rv = stat(fn, &sb)) == 0 && !S_ISDIR(sb.st_mode) && (rv = stat(fn, &sb)) == 0 && !S_ISDIR(sb.st_mode) &&
(sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) == 0) (sb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) == 0)
rv = -1; rv = -1;
#else
rv = access_ex(access, fn, mode);
#endif
return (rv); return (rv);
} }

16
funcs.c
View File

@ -2943,6 +2943,14 @@ test_isop(Test_meta meta, const char *s)
return (TO_NONOP); return (TO_NONOP);
} }
#ifdef __OS2__
#define test_access(name, mode) access_ex(access, (name), (mode))
#define test_stat(name, buffer) stat_ex((name), (buffer))
#else
#define test_access(name, mode) access((name), (mode))
#define test_stat(name, buffer) stat((name), (buffer))
#endif
int int
test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
bool do_eval) bool do_eval)
@ -3008,12 +3016,12 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
/* -r */ /* -r */
case TO_FILRD: case TO_FILRD:
/* LINTED use of access */ /* LINTED use of access */
return (access(opnd1, R_OK) == 0); return (test_access(opnd1, R_OK) == 0);
/* -w */ /* -w */
case TO_FILWR: case TO_FILWR:
/* LINTED use of access */ /* LINTED use of access */
return (access(opnd1, W_OK) == 0); return (test_access(opnd1, W_OK) == 0);
/* -x */ /* -x */
case TO_FILEX: case TO_FILEX:
@ -3023,11 +3031,11 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
case TO_FILAXST: case TO_FILAXST:
/* -e */ /* -e */
case TO_FILEXST: case TO_FILEXST:
return (stat(opnd1, &b1) == 0); return (test_stat(opnd1, &b1) == 0);
/* -r */ /* -r */
case TO_FILREG: case TO_FILREG:
return (stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode)); return (test_stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode));
/* -d */ /* -d */
case TO_FILID: case TO_FILID:

7
os2.c
View File

@ -108,6 +108,13 @@ access_ex(int (*fn)(const char *, int), const char *name, int mode)
return access_stat_ex(fn, name, (void *)mode); return access_stat_ex(fn, name, (void *)mode);
} }
/* stat() version */
int
stat_ex(const char *name, struct stat *buffer)
{
return access_stat_ex(stat, name, buffer);
}
static int static int
test_exec_exist(const char *name, char *real_name) test_exec_exist(const char *name, char *real_name)
{ {

1
sh.h
View File

@ -1926,6 +1926,7 @@ int unbksl(bool, int (*)(void), void (*)(int));
#ifdef __OS2__ #ifdef __OS2__
/* os2.c */ /* os2.c */
int access_ex(int (*)(const char *, int), const char *, int); int access_ex(int (*)(const char *, int), const char *, int);
int stat_ex(const char *, struct stat *);
const char *real_exec_name(const char *); const char *real_exec_name(const char *);
#endif #endif
/* shf.c */ /* shf.c */