Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cyg_ErrNo
- Cyg_StdioStream::refill_read_buffer( void )
- {
- Cyg_ErrNo read_err;
- cyg_uint8 *buffer;
- cyg_uint32 len;
- CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
- if (!lock_me())
- return EBADF; // assume file is now invalid
- // first just check that we _can_ read this device!
- if (!flags.opened_for_read) {
- unlock_me();
- return EINVAL;
- }
- #ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
- // If there is pending output to write, then this will check and
- // write it
- if (flags.buffering) {
- read_err = flush_output_unlocked();
- // we're now reading
- flags.last_buffer_op_was_read = true;
- // flush ALL streams
- if (read_err == ENOERR)
- read_err = cyg_libc_stdio_flush_all_but(this);
- if (read_err != ENOERR) {
- unlock_me();
- return read_err;
- } // if
- len = io_buf.get_buffer_addr_to_write( (cyg_uint8**)&buffer );
- if(len <= 0)
- len = 10;
- if (!len) { // no buffer space available
- unlock_me();
- return ENOERR; // isn't an error, just needs user to read out data
- } // if
- }
- else
- #endif
- if (!flags.readbuf_char_in_use) {
- len = 1;
- buffer = &readbuf_char;
- }
- else {
- // no buffer space available
- unlock_me();
- return ENOERR; // isn't an error, just needs user to read out data
- } // else
- read_err = cyg_stdio_read(my_device, buffer, &len);
- #ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
- if (flags.buffering)
- io_buf.set_bytes_written( len );
- else
- #endif
- flags.readbuf_char_in_use = len ? 1 : 0;
- unlock_me();
- if (read_err == ENOERR) {
- if (len == 0) {
- read_err = EAGAIN;
- flags.at_eof = true;
- }
- else
- flags.at_eof = false;
- } // if
- return read_err;
- } // refill_read_buffer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement