OSDN Git Service

FileUtils.java: Don't treat open access modes as flags
authorNick Kralevich <nnk@google.com>
Mon, 17 Dec 2018 20:46:08 +0000 (12:46 -0800)
committerNick Kralevich <nnk@google.com>
Mon, 17 Dec 2018 21:24:46 +0000 (13:24 -0800)
commit52671a787bbd94d14ac3bf7641c3976f4472ba30
treed0bdf9e6a8f65d62146580222d7164f33395a814
parentf98c2c41bd4e390756be5d057da165237323da99
FileUtils.java: Don't treat open access modes as flags

O_RDONLY, O_WRONLY, and O_RDWR are not flags. Rather, they are the
integer values 0, 1, and 2, respectively.

  #define O_RDONLY 00000000
  #define O_WRONLY 00000001
  #define O_RDWR 00000002

Quoting "man 2 open"

  * File access mode *

  Unlike  the  other  values  that  can  be  specified in flags,
  the access mode values O_RDONLY, O_WRONLY, and O_RDWR do not
  specify individual bits.  Rather, they define the low order
  two bits of flags, and are defined respectively as 0, 1, and
  2. In other words, the combination O_RDONLY | O_WRONLY is a
  logical error, and certainly does not have the same meaning
  as O_RDWR.

  Linux reserves the special, nonstandard access mode 3
  (binary 11) in flags to mean: check for read and write
  permission on the file and return a file descriptor that
  can't be used for reading or writing. This nonstandard access
  mode is used by some Linux drivers to return a file
  descriptor that is to be used only for device-specific
  ioctl(2) operations.

Rather than treat these values like flags, use O_ACCMODE to extract the
values and then perform the comparisons.

Introduced in 63280e06fc64672ab36d14f852b13df2274cc328.

Test: android compiles and boots.
Change-Id: I4d3185e835615ffba3a7854d3d58351e124599d0
core/java/android/os/FileUtils.java
core/tests/coretests/src/android/os/FileUtilsTest.java