[En-Nut-Discussion] is there a better set of definitons for fcntl.h ???
Harald Kipp
harald.kipp at egnite.de
Tue Nov 23 09:59:02 CET 2004
Hi Douglas,
>Would it not be better to have:
>
>#define _O_RDONLY 0x0004 /*!< Read only. */
...
>That code could to change to (check my code unless I made an error):
>"if (!(mode & _O_RDONLY)) {"
>and
>"if (!(mode & _O_WRONLY)) {"
>
>Which IMHO is more readable and 'safer' as
>Is this a better idea?
I'd agree, but almost all desktop systems define _O_RDONLY
as zero. Assuming any of the flags being non-zero would
make the code less portable.
Typically the value of 4 is assigned to _O_NONBLOCK,
but this is not used in Nut/OS yet.
How about
#define FRWMASK (_O_RDONLY | _O_WRONLY | _O_RDWR)
if((mode & FRWMASK) == _O_RDONLY)...
which would make the code fully independent from defined
values?
Btw. Rich Salz, the author of INN, sometime somewhere stated,
that he very much dislikes using
if(!(num-expr))
instead of
if((num-expr) != 0)
He argued, that ! is a boolean operator and should be used
on boolean expressions only. I learned a lot from Rich'
source codes and respect him very much.
Harald
More information about the En-Nut-Discussion
mailing list