This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: process_mode question
- From: Jonathan Larmour <jifl at eCosCentric dot com>
- To: Slide <slide dot o dot mix at gmail dot com>
- Cc: ecos-discuss <ecos-discuss at ecos dot sourceware dot org>
- Date: Mon, 18 Aug 2008 15:13:19 +0100
- Subject: Re: [ECOS] process_mode question
- Openpgp: id=A5FB74E6
- References: <a623f7d10806261456t76b422bdk196e226587638afd@mail.gmail.com>
Slide wrote:
> In packages/language/c/libc/stdio/current/src/common/fopen.cxx fopen
> is defined as the following:
>
> externC FILE *
> fopen( const char *filename, const char *mode ) __THROW
> {
> cyg_stdio_handle_t dev = 0;
> Cyg_ErrNo err;
> Cyg_StdioStream::OpenMode open_mode = Cyg_StdioStream::CYG_STREAM_READ;
> cyg_bool binary, append;
>
> // process_mode returns true on error
> if (process_mode( mode, &open_mode, &binary, &append )) {
[snip]
> You can see that open_mode is passed into process_mode initialized to
> CYG_STREAM_READ.
>
> If I call fopen("myfile.txt", "a") process_mode will have left
> open_mode as CYG_STREAM_READ and set the append parameter to true.
Actually it doesn't quite work like that:
The relevant bit is:
switch (mode[0]) {
case 'r':
*rw = Cyg_StdioStream::CYG_STREAM_READ;
break;
case 'a':
*append = true;
case 'w':
*rw = Cyg_StdioStream::CYG_STREAM_WRITE;
break;
default:
return true;
} // switch
Note that there is no 'break;' in the 'a' case, so it drops through.
But to make this clearer for readers I'll add a /* DROPTHROUGH */ comment.
Jifl
--
eCosCentric Limited http://www.eCosCentric.com/ The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------ Opinions==mine
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss