[En-Nut-Discussion] is there a better set of definitons for fcntl.h ???
Douglas Pearless
Douglas.Pearless at pearless.co.nz
Tue Nov 23 07:08:50 CET 2004
Hi,
When working on updating the fat.c driver for the MMC cards, I noticed that
_O_RDONLY in fcntl.h was set to 0x0000.
I noticed that there was no 0x0004 in the sequence either, can I suggest
rather than:
#define _O_RDONLY 0x0000 /*!< Read only. */
#define _O_WRONLY 0x0001 /*!< Write only. */
#define _O_RDWR 0x0002 /*!< Read and write. */
#define _O_APPEND 0x0008 /*!< Start writing at the end. */
#define _O_CREAT 0x0100 /*!< Create file if it does not exist. */
#define _O_TRUNC 0x0200 /*!< Truncate file if it exists. */
#define _O_EXCL 0x0400 /*!< Open only if it does not exist. */
#define _O_TEXT 0x4000 /*!< EOL translation. */
#define _O_BINARY 0x8000 /*!< Raw mode. */
Would it not be better to have:
#define _O_RDONLY 0x0004 /*!< Read only. */
#define _O_WRONLY 0x0001 /*!< Write only. */
#define _O_RDWR 0x0002 /*!< Read and write. */
#define _O_APPEND 0x0008 /*!< Start writing at the end. */
#define _O_CREAT 0x0100 /*!< Create file if it does not exist. */
#define _O_TRUNC 0x0200 /*!< Truncate file if it exists. */
#define _O_EXCL 0x0400 /*!< Open only if it does not exist. */
#define _O_TEXT 0x4000 /*!< EOL translation. */
#define _O_BINARY 0x8000 /*!< Raw mode. */
Which would simplify the checking of _O_RDONLY in code, and make it more
readable?
I noticed that in UART.c and USART.c they use a test like:
"if ((mode & 0x0003) != _O_RDONLY) {"
And
"if ((mode & 0x0003) != _O_WRONLY) {"
Which means that you have to know the value of _O_RDONLY and _O_WRONLY in
order to understand the code (from a novices point of view). Also if the
values of _O_aaaaa ever change, then the code in UART.c and USART.c will
break!
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?
These appear to be the only places affected in NutOS
Douglas
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.799 / Virus Database: 543 - Release Date: 19/11/2004
More information about the En-Nut-Discussion
mailing list