[ECOS] process_mode question
Slide
slide.o.mix@gmail.com
Fri Jun 27 08:49:00 GMT 2008
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 )) {
errno = EINVAL;
return NULL;
} // if
err = cyg_stdio_open( filename, open_mode, binary, append, &dev );
// if not found
if (err != ENOERR) {
errno = ENOENT;
return NULL;
} // if
return fopen_inner( dev, open_mode, binary, append );
} // fopen()
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.
Then in cyg_stdio_open, it does the following:
inline Cyg_ErrNo cyg_stdio_open( const char *filename,
const Cyg_StdioStream::OpenMode rw,
const cyg_bool binary,
const cyg_bool append,
cyg_stdio_handle_t *dev)
{
mode_t mode = 0;
int fd;
switch( rw )
{
case Cyg_StdioStream::CYG_STREAM_WRITE:
mode = O_WRONLY|O_CREAT|O_TRUNC;
break;
case Cyg_StdioStream::CYG_STREAM_READ:
mode = O_RDONLY;
break;
case Cyg_StdioStream::CYG_STREAM_READWRITE_NOCREATE:
mode = O_RDWR;
break;
case Cyg_StdioStream::CYG_STREAM_READWRITE_CREATE:
mode = O_RDWR|O_CREAT|O_TRUNC;
break;
}
if( append )
{
mode |= O_APPEND;
mode &= ~O_TRUNC;
}
fd = open( filename, mode );
if( fd < 0 )
return errno;
*dev = fd;
return ENOERR;
}
by the time it gets to the call to open(), the mode is now (O_RDONLY |
O_APPEND), if its appending, shouldn't it at least start out as write?
Thanks,
slide
--
slide-o-blog
http://slide-o-blog.blogspot.com/
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss
mailing list