From ca90bd204ffd8870e36ce7413be9143e43404e15 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Fri, 6 Sep 2002 19:23:45 +0000 Subject: [PATCH] * 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 --- src/ChangeLog | 8 ++++++ src/fs.h | 36 +++++--------------------- src/util.c | 72 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6763aee06..65810bae8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2002-09-06 Pavel Roskin + + * 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 + 2002-09-05 Pavel Roskin * cmd.c (nice_cd): Fix conditions when this function is diff --git a/src/fs.h b/src/fs.h index 17d597f32..c01163d06 100644 --- a/src/fs.h +++ b/src/fs.h @@ -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 diff --git a/src/util.c b/src/util.c index bc0bf050f..950bf04a5 100644 --- a/src/util.c +++ b/src/util.c @@ -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; }