apps: Fix O_ACCMODE bitmask checks after Linux flag alignment

After aligning NuttX open() flag constants with Linux (O_RDONLY=0,
O_WRONLY=1, O_RDWR=2), code that used '(flags & O_RDONLY)' or
'(flags & O_WRONLY)' as a bitmask check is broken because O_RDONLY
is now 0.  Fix by using '(flags & O_ACCMODE)' comparisons instead.

  - usrsocktest: replace 'flags & O_RDWR' with 'flags & O_ACCMODE'
    in fcntl F_GETFL assertions
  - dd: verify mode used '(oflags & O_RDONLY)' to detect verify;
    replace with '(oflags & O_ACCMODE) == O_RDWR'
  - dpopen: replace '(oflag & O_RDWR) == O_RDWR' with
    '(oflag & O_ACCMODE) == O_RDWR'
  - usbmsc: replace 'flags & O_WRONLY' with
    '(flags & O_ACCMODE) == O_RDONLY'
  - fcntl_test: replace '(flags & O_WRONLY) == 0' with
    '(flags & O_ACCMODE) == O_RDONLY'

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2026-06-28 02:21:28 +08:00 committed by Matteo Golin
parent fc25af7cd7
commit 5ead824fff
9 changed files with 55 additions and 53 deletions

View file

@ -356,7 +356,7 @@ int main(int argc, FAR char **argv)
}
else if (strncmp(argv[i], "verify", 6) == 0)
{
dd.oflags |= O_RDONLY;
dd.oflags = (dd.oflags & ~O_ACCMODE) | O_RDWR;
}
else if (strncmp(argv[i], "conv=", 5) == 0)
{
@ -409,7 +409,8 @@ int main(int argc, FAR char **argv)
/* If verify enabled, infile and outfile are mandatory */
if ((dd.oflags & O_RDONLY) && (infile == NULL || outfile == NULL))
if ((dd.oflags & O_ACCMODE) == O_RDWR &&
(infile == NULL || outfile == NULL))
{
fprintf(stderr, "%s: invalid parameters: %s\n", g_dd,
strerror(EINVAL));
@ -519,7 +520,7 @@ int main(int argc, FAR char **argv)
/ ((double)elapsed / USEC_PER_SEC)));
#endif
if (ret == 0 && (dd.oflags & O_RDONLY) != 0)
if (ret == 0 && (dd.oflags & O_ACCMODE) == O_RDWR)
{
ret = dd_verify(&dd);
}

View file

@ -112,7 +112,7 @@ int dpopen(FAR const char *command, int oflag, FAR pid_t *pid)
* pipe; fd[1] refers to the write end of the pipe.
*/
if ((oflag & O_RDWR) == O_RDWR)
if ((oflag & O_ACCMODE) == O_RDWR)
{
#if defined(CONFIG_NET_LOCAL) && defined(CONFIG_NET_LOCAL_STREAM)
/* Create a socketpair for bidirectional communication */
@ -215,7 +215,7 @@ int dpopen(FAR const char *command, int oflag, FAR pid_t *pid)
/* Redirect child's stdin or stdout to the pipe */
if ((oflag & O_RDWR) == O_RDWR)
if ((oflag & O_ACCMODE) == O_RDWR)
{
errcode = posix_spawn_file_actions_adddup2(&file_actions, childfd,
STDIN_FILENO);

View file

@ -581,7 +581,7 @@ int main(int argc, FAR char *argv[])
num_luns, luns[num_luns].path);
ret = usbmsc_bindlun(handle, luns[num_luns].path, 0, 0, 0,
luns[num_luns].flags & O_WRONLY ? false : true);
(luns[num_luns].flags & O_ACCMODE) == O_RDONLY);
if (ret < 0)
{
printf("mcsonn_main: usbmsc_bindlun failed for LUN %d using %s: "