Changeset bd5414e in mainline for uspace/lib/c/generic/io/io.c
- Timestamp:
- 2015-09-21T21:05:26Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c70703a
- Parents:
- bea710f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/io.c
rbea710f rbd5414e 64 64 .buf_head = NULL, 65 65 .buf_tail = NULL, 66 .buf_state = _bs_empty 66 .buf_state = _bs_empty, 67 67 }; 68 68 … … 466 466 return 0; 467 467 468 bytes_left = size * nmemb; 469 total_read = 0; 470 dp = (uint8_t *) dest; 471 472 /* Bytes from ungetc() buffer */ 473 while (stream->ungetc_chars > 0 && bytes_left > 0) { 474 *dp++ = stream->ungetc_buf[--stream->ungetc_chars]; 475 ++total_read; 476 } 477 468 478 /* If not buffered stream, read in directly. */ 469 479 if (stream->btype == _IONBF) { 470 now = _fread(dest, size, nmemb, stream);471 return now;480 total_read += _fread(dest, 1, bytes_left, stream); 481 return total_read / size; 472 482 } 473 483 … … 481 491 return 0; /* Errno set by _fallocbuf(). */ 482 492 } 483 484 bytes_left = size * nmemb;485 total_read = 0;486 dp = (uint8_t *) dest;487 493 488 494 while ((!stream->error) && (!stream->eof) && (bytes_left > 0)) { … … 674 680 } 675 681 682 int ungetc(int c, FILE *stream) 683 { 684 if (c == EOF) 685 return EOF; 686 687 if (stream->ungetc_chars >= UNGETC_MAX) 688 return EOF; 689 690 stream->ungetc_buf[stream->ungetc_chars++] = 691 (uint8_t)c; 692 693 stream->eof = false; 694 return (uint8_t)c; 695 } 696 676 697 int fseek(FILE *stream, off64_t offset, int whence) 677 698 { … … 679 700 680 701 _fflushbuf(stream); 702 stream->ungetc_chars = 0; 681 703 682 704 rc = lseek(stream->fd, offset, whence); … … 693 715 { 694 716 _fflushbuf(stream); 695 return lseek(stream->fd, 0, SEEK_CUR) ;717 return lseek(stream->fd, 0, SEEK_CUR) - stream->ungetc_chars; 696 718 } 697 719
Note:
See TracChangeset
for help on using the changeset viewer.