/* Modified to run with the GNU shell by bfox. */
-/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2003 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
test_exit (SHELL_BOOLEAN (FALSE));
}
-/* A wrapper for stat () which disallows pathnames that are empty strings. */
-static int
-test_stat (char *path, struct stat *finfo)
-{
- if (*path == '\0')
- {
- errno = ENOENT;
- return (-1);
- }
- return (stat (path, finfo));
-}
-
/* Do the same thing access(2) does, but use the effective uid and gid,
and don't make the mistake of telling root that any file is executable.
But this loses when the containing filesystem is mounted e.g. read-only. */
struct stat st;
static uid_t euid = -1;
- if (test_stat (path, &st) < 0)
+ if (stat (path, &st) < 0)
return (-1);
if (euid == (uid_t) -1)
age_of (char *filename, time_t *age)
{
struct stat finfo;
- int r = test_stat (filename, &finfo);
+ int r = stat (filename, &finfo);
if (r == 0)
*age = finfo.st_mtime;
return r;
case 'a': /* file exists in the file system? */
case 'e':
unary_advance ();
- value = -1 != test_stat (argv[pos - 1], &stat_buf);
+ value = -1 != stat (argv[pos - 1], &stat_buf);
return (TRUE == value);
case 'r': /* file is readable? */
case 'O': /* File is owned by you? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (geteuid () == stat_buf.st_uid));
case 'G': /* File is owned by your group? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (getegid () == stat_buf.st_gid));
case 'f': /* File is a file? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
/* Under POSIX, -f is true if the given file exists
case 'd': /* File is a directory? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (S_ISDIR (stat_buf.st_mode)));
case 's': /* File has something in it? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (stat_buf.st_size > (off_t) 0));
#else
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (S_ISSOCK (stat_buf.st_mode)));
case 'c': /* File is character special? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (S_ISCHR (stat_buf.st_mode)));
case 'b': /* File is block special? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (S_ISBLK (stat_buf.st_mode)));
#ifndef S_ISFIFO
return (FALSE);
#else
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (S_ISFIFO (stat_buf.st_mode)));
#endif /* S_ISFIFO */
#ifndef S_ISUID
return (FALSE);
#else
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (0 != (stat_buf.st_mode & S_ISUID)));
#ifndef S_ISGID
return (FALSE);
#else
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
return (TRUE == (0 != (stat_buf.st_mode & S_ISGID)));
case 'k': /* File has sticky bit set? */
unary_advance ();
- if (test_stat (argv[pos - 1], &stat_buf) < 0)
+ if (stat (argv[pos - 1], &stat_buf) < 0)
return (FALSE);
#ifndef S_ISVTX
/* This is not Posix, and is not defined on some Posix systems. */