I'd speculate that it's one or more of the following (unfortunately, I was unable to quickly find any kind of supporting references, so this'll probably remain speculation):
- Kernighan or Ritchie (or whoever came up with the interface for
fopen()
) just happened to like the idea of specifying the mode using a string instead of a bitmap
- They may have wanted the interface to be similar to yet noticeably different from the Unix
open()
system call interface, so it would be at once familiar yet not mistakenly compile with constants defined for Unix instead of by the C library
For example, let's say that the mythical C standard fopen()
that took a bitmapped mode parameter used the identifier OPENMODE_READONLY
to specify that the file what today is specified by the mode string "r". Now, if someone made the following call on a program compiled on a Unix platform (and that the header that defines O_RDONLY
has been included):
fopen( "myfile", O_RDONLY);
There would be no compiler error, but unless OPENMODE_READONLY
and O_RDONLY
were defined to be the same bit you'd get unexpected behavior. Of course it would make sense for the C standard names to be defined the same as the Unix names, but maybe they wanted to preclude requiring this kind of coupling.
Then again, this might not have crossed their minds at all...