Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: POSIX file mode macros
- X-seq: zsh-workers 3875
- From: Andrew Main <zefram@xxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx
- Subject: PATCH: POSIX file mode macros
- Date: Mon, 27 Apr 1998 10:24:43 +0100
-----BEGIN PGP SIGNED MESSAGE-----
This patch makes zsh use the POSIX S_I* macros for permission bits in all
cases, rather than the usual octal values. However, where an octal value
is read from or output to the user, the standard octal values are used
(as required by POSIX for chmod), with a portable conversion function.
There were also a coule of places testing bit S_IXUSR, which should have
been S_IXUGO.
-zefram
*** Src/cond.c 1998/04/26 13:56:32 1.15
--- Src/cond.c 1998/04/26 15:31:54
***************
*** 95,102 ****
return (doaccess(c->left, W_OK));
case 'x':
if (privasserted()) {
! unsigned short mode = dostat(c->left);
! return (mode & 0111) || S_ISDIR(mode);
}
return doaccess(c->left, X_OK);
case 'z':
--- 95,102 ----
return (doaccess(c->left, W_OK));
case 'x':
if (privasserted()) {
! mode_t mode = dostat(c->left);
! return (mode & S_IXUGO) || S_ISDIR(mode);
}
return doaccess(c->left, X_OK);
case 'z':
***************
*** 185,191 ****
/**/
! static unsigned short
dostat(char *s)
{
struct stat *statp;
--- 185,191 ----
/**/
! static mode_t
dostat(char *s)
{
struct stat *statp;
***************
*** 199,205 ****
/* pem@xxxxxxx; needed since dostat now uses "stat" */
/**/
! static unsigned short
dolstat(char *s)
{
if (lstat(unmeta(s), &st) < 0)
--- 199,205 ----
/* pem@xxxxxxx; needed since dostat now uses "stat" */
/**/
! static mode_t
dolstat(char *s)
{
if (lstat(unmeta(s), &st) < 0)
*** Src/glob.c 1998/04/26 15:14:50 1.46
--- Src/glob.c 1998/04/26 15:37:58
***************
*** 1323,1329 ****
else if(S_ISLNK(filemode))
return '@';
else if(S_ISREG(filemode))
! return (filemode & 0111) ? '*' : ' ';
else if(S_ISSOCK(filemode))
return '=';
else
--- 1323,1329 ----
else if(S_ISLNK(filemode))
return '@';
else if(S_ISREG(filemode))
! return (filemode & S_IXUGO) ? '*' : ' ';
else if(S_ISSOCK(filemode))
return '=';
else
***************
*** 2655,2661 ****
static int
qualflags(struct stat *buf, long mod)
{
! return buf->st_mode & mod;
}
/* mode matches number supplied exactly */
--- 2655,2661 ----
static int
qualflags(struct stat *buf, long mod)
{
! return mode_to_octal(buf->st_mode) & mod;
}
/* mode matches number supplied exactly */
***************
*** 2664,2670 ****
static int
qualeqflags(struct stat *buf, long mod)
{
! return (buf->st_mode & 07777) == mod;
}
/* regular executable file? */
--- 2664,2670 ----
static int
qualeqflags(struct stat *buf, long mod)
{
! return mode_to_octal(buf->st_mode) == mod;
}
/* regular executable file? */
***************
*** 2673,2679 ****
static int
qualiscom(struct stat *buf, long mod)
{
! return S_ISREG(buf->st_mode) && (buf->st_mode & S_IXUSR);
}
/* size in required range? */
--- 2673,2679 ----
static int
qualiscom(struct stat *buf, long mod)
{
! return S_ISREG(buf->st_mode) && (buf->st_mode & S_IXUGO);
}
/* size in required range? */
*** Src/system.h 1998/04/26 15:14:52 1.21
--- Src/system.h 1998/04/26 15:20:29
***************
*** 517,522 ****
--- 517,579 ----
# define S_ISSOCK(m) ((void)(m), 0)
#endif
+ /* file mode permission bits */
+
+ #ifndef S_ISUID
+ # define S_ISUID 04000
+ #endif
+ #ifndef S_ISGID
+ # define S_ISGID 02000
+ #endif
+ #ifndef S_ISVTX
+ # define S_ISVTX 01000
+ #endif
+ #ifndef S_IRUSR
+ # define S_IRUSR 00400
+ #endif
+ #ifndef S_IWUSR
+ # define S_IWUSR 00200
+ #endif
+ #ifndef S_IXUSR
+ # define S_IXUSR 00100
+ #endif
+ #ifndef S_IRGRP
+ # define S_IRGRP 00040
+ #endif
+ #ifndef S_IWGRP
+ # define S_IWGRP 00020
+ #endif
+ #ifndef S_IXGRP
+ # define S_IXGRP 00010
+ #endif
+ #ifndef S_IROTH
+ # define S_IROTH 00004
+ #endif
+ #ifndef S_IWOTH
+ # define S_IWOTH 00002
+ #endif
+ #ifndef S_IXOTH
+ # define S_IXOTH 00001
+ #endif
+ #ifndef S_IRWXU
+ # define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
+ #endif
+ #ifndef S_IRWXG
+ # define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
+ #endif
+ #ifndef S_IRWXO
+ # define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
+ #endif
+ #ifndef S_IRUGO
+ # define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
+ #endif
+ #ifndef S_IWUGO
+ # define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH)
+ #endif
+ #ifndef S_IXUGO
+ # define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
+ #endif
+
#ifndef HAVE_LSTAT
# define lstat stat
#endif
*** Src/utils.c 1998/04/25 18:14:34 1.89
--- Src/utils.c 1998/04/26 15:35:34
***************
*** 3634,3637 ****
fprintf(stderr, "%s\n", message);
fflush(stderr);
}
! #endif
--- 3634,3671 ----
fprintf(stderr, "%s\n", message);
fflush(stderr);
}
!
! #endif /* DEBUG */
!
! /**/
! int
! mode_to_octal(mode_t mode)
! {
! int m = 0;
!
! if(mode & S_ISUID)
! m |= 04000;
! if(mode & S_ISGID)
! m |= 02000;
! if(mode & S_ISVTX)
! m |= 01000;
! if(mode & S_IRUSR)
! m |= 00400;
! if(mode & S_IWUSR)
! m |= 00200;
! if(mode & S_IXUSR)
! m |= 00100;
! if(mode & S_IRGRP)
! m |= 00040;
! if(mode & S_IWGRP)
! m |= 00020;
! if(mode & S_IXGRP)
! m |= 00010;
! if(mode & S_IROTH)
! m |= 00004;
! if(mode & S_IWOTH)
! m |= 00002;
! if(mode & S_IXOTH)
! m |= 00001;
! return m;
! }
*** Src/Modules/files.c 1998/04/26 13:56:42 1.21
--- Src/Modules/files.c 1998/04/26 15:34:53
***************
*** 297,304 ****
nicezputs(nam, stderr);
fputs(": replace `", stderr);
nicezputs(q, stderr);
! fprintf(stderr, "', overriding mode %04lo? ",
! (unsigned long) (st.st_mode & 07777));
fflush(stderr);
if(!ask())
return 0;
--- 297,304 ----
nicezputs(nam, stderr);
fputs(": replace `", stderr);
nicezputs(q, stderr);
! fprintf(stderr, "', overriding mode %04o? ",
! mode_to_octal(st.st_mode));
fflush(stderr);
if(!ask())
return 0;
***************
*** 406,413 ****
nicezputs(nam, stderr);
fputs(": remove `", stderr);
nicezputs(arg, stderr);
! fprintf(stderr, "', overriding mode %04lo? ",
! (unsigned long) (st.st_mode & 07777));
fflush(stderr);
if(!ask())
return 0;
--- 406,413 ----
nicezputs(nam, stderr);
fputs(": remove `", stderr);
nicezputs(arg, stderr);
! fprintf(stderr, "', overriding mode %04o? ",
! mode_to_octal(st.st_mode));
fflush(stderr);
if(!ask())
return 0;
*** Src/Modules/stat.c 1998/04/26 13:56:43 1.10
--- Src/Modules/stat.c 1998/04/26 15:28:26
***************
*** 78,102 ****
else if (S_ISSOCK(mode))
*pm = 's';
! /* too much hassle using macros for the following which should be
! * standardish.
! */
! ioff = 1;
! for (itest = 64; itest > 0; itest /= 8) {
! if (mode & (4*itest))
! pm[ioff] = 'r';
! if (mode & (2*itest))
! pm[ioff+1] = 'w';
! if (mode & itest)
! pm[ioff+2] = 'x';
! ioff += 3;
! }
! if (mode & 04000) /* setuid */
! pm[3] = (pm[3] == 'x') ? 's' : 'S';
! if (mode & 02000) /* setgid */
! pm[6] = (pm[6] == 'x') ? 's' : 'S';
! if (mode & 01000) /* sticky bit */
! pm[9] = (pm[9] == 'x') ? 't' : 'T';
strcat(outbuf, pm);
if (flags & STF_RAW)
--- 78,107 ----
else if (S_ISSOCK(mode))
*pm = 's';
! if(mode & S_IRUSR)
! pm[1] = 'r';
! if(mode & S_IWUSR)
! pm[2] = 'w';
! if(mode & S_IXUSR)
! pm[3] = 'x';
! if(mode & S_IRGRP)
! pm[4] = 'r';
! if(mode & S_IWGRP)
! pm[5] = 'w';
! if(mode & S_IXGRP)
! pm[6] = 'x';
! if(mode & S_IROTH)
! pm[7] = 'r';
! if(mode & S_IWOTH)
! pm[8] = 'w';
! if(mode & S_IXOTH)
! pm[9] = 'x';
! if (mode & S_ISUID)
! pm[3] = (mode & S_IXUSR) ? 's' : 'S';
! if (mode & S_ISGID)
! pm[6] = (mode & S_IXGRP) ? 's' : 'S';
! if (mode & S_ISVTX)
! pm[9] = (mode & S_IXOTH) ? 't' : 'T';
strcat(outbuf, pm);
if (flags & STF_RAW)
*** Src/Zle/zle_tricky.c 1998/04/26 13:56:45 1.44
--- Src/Zle/zle_tricky.c 1998/04/26 15:29:52
***************
*** 2091,2097 ****
}
if (all ||
(dirs && S_ISDIR(buf.st_mode)) ||
! (execs && S_ISREG(buf.st_mode) && (buf.st_mode&S_IXUSR))) {
/* If we want all files or the file has the right type... */
if (*psuf) {
/* We have to test for a path suffix. */
--- 2091,2097 ----
}
if (all ||
(dirs && S_ISDIR(buf.st_mode)) ||
! (execs && S_ISREG(buf.st_mode) && (buf.st_mode&S_IXUGO))) {
/* If we want all files or the file has the right type... */
if (*psuf) {
/* We have to test for a path suffix. */
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
Charset: ascii
iQEVAwUBNUNafJmk9GeOHh7BAQGpPgf/czyhnxMGu54DkKN06jlFj6Oe9+tDQpkP
0RGHGaaB1G509bNuLNGImSx1kNP7Ys56K9pHa+oUDqnpSzpoG3YL35OBFA9aSFkh
kE4ecH1+VB3i4+czFLnj81dNB3nMBbtJhIXSme4MJqaoUheoaI0IGqCuW9OVHr3y
23nHqmqpXYO1U2e90o9WFuwjuRyt/d+gvqyER1zlcsSr245POZ7hDfWHHw6ph/G6
S+N54PWy1tU4q4FYVYvh+8dt+tOoOz6EZBcFqqm4cusMmSTE2xWjHOJZFrS2x6sV
+8klmqZ4Ypn93FrXn5YvhhgkRdVlb6GMwdlP/k8s63WsIahpRGKe9g==
=H7IV
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author