Mercurial > ecos-v3_0-branch
changeset 1557:0ef97dc5b090
* src/common/fopen.cxx:
* src/common/stream.cxx:
* include/io.inl:
* include/stream.hxx:
Split CYGSTREAM_READWRITE into CYGSTREAM_READWRITE_CREATE and
CYGSTREAM_READWRITE_NOCREATE. This fixes fopen() with mode 'w+'
which previously did not allow file creation.
| author | asl |
|---|---|
| date | Mon, 29 Mar 2004 11:24:37 +0000 |
| parents | 956d016d5e0e |
| children | 374f08d35ab1 |
| files | packages/language/c/libc/stdio/current/ChangeLog packages/language/c/libc/stdio/current/include/io.inl packages/language/c/libc/stdio/current/include/stream.hxx packages/language/c/libc/stdio/current/include/stream.inl packages/language/c/libc/stdio/current/src/common/fopen.cxx packages/language/c/libc/stdio/current/src/common/stream.cxx |
| diffstat | 6 files changed, 43 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/language/c/libc/stdio/current/ChangeLog +++ b/packages/language/c/libc/stdio/current/ChangeLog @@ -1,3 +1,13 @@ +2004-03-29 Kelvin Lawson <klawson@ad-holdings.co.uk> + + * src/common/fopen.cxx: + * src/common/stream.cxx: + * include/io.inl: + * include/stream.hxx: + Split CYGSTREAM_READWRITE into CYGSTREAM_READWRITE_CREATE and + CYGSTREAM_READWRITE_NOCREATE. This fixes fopen() with mode 'w+' + which previously did not allow file creation. + 2004-03-15 Jonathan Larmour <jifl@eCosCentric.com> * src/common/fileops.cxx (tmpnam): Only close if open() succeded.
--- a/packages/language/c/libc/stdio/current/include/io.inl +++ b/packages/language/c/libc/stdio/current/include/io.inl @@ -84,9 +84,12 @@ inline Cyg_ErrNo cyg_stdio_open( const c case Cyg_StdioStream::CYG_STREAM_READ: mode = O_RDONLY; break; - case Cyg_StdioStream::CYG_STREAM_READWRITE: + 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 )
--- a/packages/language/c/libc/stdio/current/include/stream.hxx +++ b/packages/language/c/libc/stdio/current/include/stream.hxx @@ -157,7 +157,8 @@ public: typedef enum { CYG_STREAM_READ, CYG_STREAM_WRITE, - CYG_STREAM_READWRITE + CYG_STREAM_READWRITE_NOCREATE, + CYG_STREAM_READWRITE_CREATE } OpenMode; // CONSTRUCTORS @@ -168,8 +169,8 @@ public: // dev is a valid Cyg_Device_Table_t, although it does not have to // be a member of the device table object itself // - // open_mode is one of CYG_STREAM_READ, CYG_STREAM_WRITE or - // CYG_STREAM_READWRITE + // open_mode is one of CYG_STREAM_READ, CYG_STREAM_WRITE, + // CYG_STREAM_READWRITE_NOCREATE or CYG_STREAM_READWRITE_CREATE // // append is true if the file position should be set at EOF on opening //
--- a/packages/language/c/libc/stdio/current/include/stream.inl +++ b/packages/language/c/libc/stdio/current/include/stream.inl @@ -446,27 +446,32 @@ Cyg_StdioStream::set_position( fpos_t po } //endif (whence != SEEK_END) Cyg_ErrNo err; - off_t newpos=pos; - err = cyg_stdio_lseek( my_device, &newpos, whence ); + // Flush output if any present. + err = flush_output_unlocked(); if( err == ENOERR ) { - // Clean out the buffer. Flush output if any present, - // and clear any input out of input buffer and any ungot - // chars from unread buffer. + off_t newpos=pos; + + // Clear any input out of input buffer and any ungot chars + // from unread buffer. + io_buf.drain_buffer(); - err = flush_output_unlocked(); - io_buf.drain_buffer(); #ifdef CYGFUN_LIBC_STDIO_ungetc flags.unread_char_buf_in_use = false; #endif // Clear EOF indicator. flags.at_eof = false; - - // update stream pos - position = newpos; + + // Seek the file to the correct place + err = cyg_stdio_lseek( my_device, &newpos, whence ); + + if ( err == ENOERR) { + // update stream pos + position = newpos; + } } unlock_me();
--- a/packages/language/c/libc/stdio/current/src/common/fopen.cxx +++ b/packages/language/c/libc/stdio/current/src/common/fopen.cxx @@ -112,7 +112,10 @@ process_mode( const char *mode, Cyg_Stdi *binary = true; break; case '+': - *rw = Cyg_StdioStream::CYG_STREAM_READWRITE; + if (mode[0] == 'r') + *rw = Cyg_StdioStream::CYG_STREAM_READWRITE_NOCREATE; + else + *rw = Cyg_StdioStream::CYG_STREAM_READWRITE_CREATE; break; default: return false; @@ -123,7 +126,10 @@ process_mode( const char *mode, Cyg_Stdi *binary = true; break; case '+': - *rw = Cyg_StdioStream::CYG_STREAM_READWRITE; + if (mode[0] == 'r') + *rw = Cyg_StdioStream::CYG_STREAM_READWRITE_NOCREATE; + else + *rw = Cyg_StdioStream::CYG_STREAM_READWRITE_CREATE; break; default: return false;
--- a/packages/language/c/libc/stdio/current/src/common/stream.cxx +++ b/packages/language/c/libc/stdio/current/src/common/stream.cxx @@ -107,7 +107,8 @@ void Cyg_StdioStream::initialize(cyg_std case CYG_STREAM_WRITE: flags.opened_for_write = true; break; - case CYG_STREAM_READWRITE: + case CYG_STREAM_READWRITE_NOCREATE: + case CYG_STREAM_READWRITE_CREATE: flags.opened_for_read = true; flags.opened_for_write = true; break;
