* fs.h: Only redefine S_IS* macros if they are undefined, and

then define them to 0.  S_IF* constants should be avoided.
* util.c : Whenever possible, use standard POSIX macros to test
for the file type.
Reported by Andrew V. Samoilov <sav@bcs.zp.ua>
This commit is contained in:
Pavel Roskin 2002-09-06 19:23:45 +00:00
parent 04c7da6358
commit ca90bd204f
3 changed files with 61 additions and 55 deletions

View File

@ -1,3 +1,11 @@
2002-09-06 Pavel Roskin <proski@gnu.org>
* fs.h: Only redefine S_IS* macros if they are undefined, and
then define them to 0. S_IF* constants should be avoided.
* util.c : Whenever possible, use standard POSIX macros to test
for the file type.
Reported by Andrew V. Samoilov <sav@bcs.zp.ua>
2002-09-05 Pavel Roskin <proski@gnu.org>
* cmd.c (nice_cd): Fix conditions when this function is

View File

@ -11,53 +11,29 @@
/* Replacement for permission bits missing in sys/stat.h */
#ifndef S_IFLNK
# define S_IFLNK 0
#endif
#ifndef S_ISLNK
# define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
#endif
#ifndef S_IFSOCK
# define S_IFSOCK 0
# define S_ISLNK(x) 0
#endif
#ifndef S_ISSOCK
# define S_ISSOCK(x) (((x) & S_IFMT) == S_IFSOCK)
#endif
#ifndef S_IFIFO
# define S_IFIFO 0
# define S_ISSOCK(x) 0
#endif
#ifndef S_ISFIFO
# define S_ISFIFO(x) (((x) & S_IFMT) == S_IFIFO)
#endif
#ifndef S_IFCHR
# define S_IFCHR 0
# define S_ISFIFO(x) 0
#endif
#ifndef S_ISCHR
# define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
#endif
#ifndef S_IFBLK
# define S_IFBLK 0
# define S_ISCHR(x) 0
#endif
#ifndef S_ISBLK
# define S_ISBLK(x) (((x) & S_IFMT) == S_IFBLK)
# define S_ISBLK(x) 0
#endif
/* Door is something that only exists on Solaris */
#ifndef S_IFDOOR
# define S_IFDOOR 0
#endif
#ifndef S_ISDOOR
# define S_ISDOOR(x) (((x) & S_IFMT) == S_IFDOOR)
# define S_ISDOOR(x) 0
#endif

View File

@ -319,34 +319,56 @@ int is_exe (mode_t mode)
#define ismode(n,m) ((n & m) == m)
char *string_perm (mode_t mode_bits)
char *
string_perm (mode_t mode_bits)
{
static char mode [11];
static char mode[11];
strcpy (mode, "----------");
if (ismode (mode_bits, S_IFDIR)) mode [0] = 'd';
if (ismode (mode_bits, S_IFSOCK)) mode [0] = 's';
if (ismode (mode_bits, S_IXOTH)) mode [9] = 'x';
if (ismode (mode_bits, S_IWOTH)) mode [8] = 'w';
if (ismode (mode_bits, S_IROTH)) mode [7] = 'r';
if (ismode (mode_bits, S_IXGRP)) mode [6] = 'x';
if (ismode (mode_bits, S_IWGRP)) mode [5] = 'w';
if (ismode (mode_bits, S_IRGRP)) mode [4] = 'r';
if (ismode (mode_bits, S_IXUSR)) mode [3] = 'x';
if (ismode (mode_bits, S_IWUSR)) mode [2] = 'w';
if (ismode (mode_bits, S_IRUSR)) mode [1] = 'r';
#ifndef OS2_NT
if (ismode (mode_bits, S_ISUID)) mode [3] = (mode [3] == 'x') ? 's' : 'S';
if (ismode (mode_bits, S_ISGID)) mode [6] = (mode [6] == 'x') ? 's' : 'S';
if (ismode (mode_bits, S_IFCHR)) mode [0] = 'c';
if (ismode (mode_bits, S_IFBLK)) mode [0] = 'b';
if (ismode (mode_bits, S_ISVTX)) mode [9] = (mode [9] == 'x') ? 't' : 'T';
if (ismode (mode_bits, S_IFLNK)) mode [0] = 'l';
if (ismode (mode_bits, S_IFIFO)) mode [0] = 'p';
#ifdef S_IFDOOR
if (ismode (mode_bits, S_IFDOOR)) mode [0] = 'D';
#endif /* S_IFDOOR */
#endif /* !OS2_NT */
if (S_ISDIR (mode_bits))
mode[0] = 'd';
if (S_ISCHR (mode_bits))
mode[0] = 'c';
if (S_ISBLK (mode_bits))
mode[0] = 'b';
if (S_ISLNK (mode_bits))
mode[0] = 'l';
if (S_ISFIFO (mode_bits))
mode[0] = 'p';
if (S_ISSOCK (mode_bits))
mode[0] = 's';
if (S_ISDOOR (mode_bits))
mode[0] = 'D';
if (ismode (mode_bits, S_IXOTH))
mode[9] = 'x';
if (ismode (mode_bits, S_IWOTH))
mode[8] = 'w';
if (ismode (mode_bits, S_IROTH))
mode[7] = 'r';
if (ismode (mode_bits, S_IXGRP))
mode[6] = 'x';
if (ismode (mode_bits, S_IWGRP))
mode[5] = 'w';
if (ismode (mode_bits, S_IRGRP))
mode[4] = 'r';
if (ismode (mode_bits, S_IXUSR))
mode[3] = 'x';
if (ismode (mode_bits, S_IWUSR))
mode[2] = 'w';
if (ismode (mode_bits, S_IRUSR))
mode[1] = 'r';
#ifdef S_ISUID
if (ismode (mode_bits, S_ISUID))
mode[3] = (mode[3] == 'x') ? 's' : 'S';
#endif /* S_ISUID */
#ifdef S_ISGID
if (ismode (mode_bits, S_ISGID))
mode[6] = (mode[6] == 'x') ? 's' : 'S';
#endif /* S_ISGID */
#ifdef S_ISVTX
if (ismode (mode_bits, S_ISVTX))
mode[9] = (mode[9] == 'x') ? 't' : 'T';
#endif /* S_ISVTX */
return mode;
}