This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: process_mode question


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]