summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-04-10 10:15:53 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-04-10 10:15:53 (GMT)
commit78e3e645e087d6981615429ced74005fcaa89957 (patch)
tree1c00483d41ab09b78b6a6b446b70d08e830a34ca
parent2daa6ec625c055fc4a58d54d4b44f503bebc000a (diff)
downloadtcl-78e3e645e087d6981615429ced74005fcaa89957.zip
tcl-78e3e645e087d6981615429ced74005fcaa89957.tar.gz
tcl-78e3e645e087d6981615429ced74005fcaa89957.tar.bz2
Use O_ACCMODE in stead of the non-standard RW_MODES. Since O_RDONLY|O_WRONLY|O_RDWR aren't necessary separate flags, this is the standard way.
-rw-r--r--generic/tclIOCmd.c2
-rw-r--r--generic/tclIOUtil.c13
-rw-r--r--generic/tclTest.c2
-rw-r--r--unix/tclUnixChan.c2
-rw-r--r--win/tclWinChan.c2
-rw-r--r--win/tclWinPipe.c2
6 files changed, 10 insertions, 13 deletions
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index be37fbd..5127b99 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -1169,7 +1169,7 @@ Tcl_OpenObjCmd(
} else {
int flags = TCL_STDERR | TCL_ENFORCE_MODE;
- switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) {
+ switch (mode & O_ACCMODE) {
case O_RDONLY:
flags |= TCL_STDOUT;
break;
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index 921714e..e64ba7e 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -1520,7 +1520,6 @@ TclGetOpenModeEx(
{
int mode, modeArgc, c, i, gotRW;
const char **modeArgv, *flag;
-#define RW_MODES (O_RDONLY|O_WRONLY|O_RDWR)
/*
* Check for the simpler fopen-like access modes (e.g. "r"). They are
@@ -1530,7 +1529,7 @@ TclGetOpenModeEx(
*seekFlagPtr = 0;
*binaryPtr = 0;
- mode = 0;
+ mode = O_RDONLY;
/*
* Guard against international characters before using byte oriented
@@ -1541,7 +1540,6 @@ TclGetOpenModeEx(
&& islower(UCHAR(modeString[0]))) { /* INTL: ISO only. */
switch (modeString[0]) {
case 'r':
- mode = O_RDONLY;
break;
case 'w':
mode = O_WRONLY|O_CREAT|O_TRUNC;
@@ -1570,8 +1568,7 @@ TclGetOpenModeEx(
* works. [Bug 1773127]
*/
- mode &= ~(O_RDONLY|O_WRONLY|O_APPEND);
- mode |= O_RDWR;
+ mode = (mode & ~(O_ACCMODE|O_APPEND)) | O_RDWR;
break;
case 'b':
*binaryPtr = 1;
@@ -1618,13 +1615,13 @@ TclGetOpenModeEx(
flag = modeArgv[i];
c = flag[0];
if ((c == 'R') && (strcmp(flag, "RDONLY") == 0)) {
- mode = (mode & ~RW_MODES) | O_RDONLY;
+ mode = (mode & ~O_ACCMODE) | O_RDONLY;
gotRW = 1;
} else if ((c == 'W') && (strcmp(flag, "WRONLY") == 0)) {
- mode = (mode & ~RW_MODES) | O_WRONLY;
+ mode = (mode & ~O_ACCMODE) | O_WRONLY;
gotRW = 1;
} else if ((c == 'R') && (strcmp(flag, "RDWR") == 0)) {
- mode = (mode & ~RW_MODES) | O_RDWR;
+ mode = (mode & ~O_ACCMODE) | O_RDWR;
gotRW = 1;
} else if ((c == 'A') && (strcmp(flag, "APPEND") == 0)) {
mode |= O_APPEND;
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 37b9717..692034b 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -6994,7 +6994,7 @@ SimpleOpenFileChannel(
Tcl_Obj *tempPtr;
Tcl_Channel chan;
- if ((mode != 0) && !(mode & O_RDONLY)) {
+ if ((mode & O_ACCMODE) != O_RDONLY) {
Tcl_AppendResult(interp, "read-only", NULL);
return NULL;
}
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c
index f83a213..5e39cfc 100644
--- a/unix/tclUnixChan.c
+++ b/unix/tclUnixChan.c
@@ -1400,7 +1400,7 @@ TclpOpenFileChannel(
char channelName[16 + TCL_INTEGER_SPACE];
const Tcl_ChannelType *channelTypePtr;
- switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) {
+ switch (mode & O_ACCMODE) {
case O_RDONLY:
channelPermissions = TCL_READABLE;
break;
diff --git a/win/tclWinChan.c b/win/tclWinChan.c
index 6308930..666a0b1 100644
--- a/win/tclWinChan.c
+++ b/win/tclWinChan.c
@@ -873,7 +873,7 @@ TclpOpenFileChannel(
return NULL;
}
- switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) {
+ switch (mode & O_ACCMODE) {
case O_RDONLY:
accessMode = GENERIC_READ;
channelPermissions = TCL_READABLE;
diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c
index 171cf07..229f670 100644
--- a/win/tclWinPipe.c
+++ b/win/tclWinPipe.c
@@ -538,7 +538,7 @@ TclpOpenFile(
* Map the access bits to the NT access mode.
*/
- switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) {
+ switch (mode & O_ACCMODE) {
case O_RDONLY:
accessMode = GENERIC_READ;
break;