Changeset bd5414e in mainline for uspace/lib/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
- Location:
- uspace/lib/c
- Files:
-
- 3 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 -
uspace/lib/c/generic/private/stdio.h
rbea710f rbd5414e 39 39 #include <stdio.h> 40 40 #include <async.h> 41 42 /** Maximum characters that can be pushed back by ungetc() */ 43 #define UNGETC_MAX 1 41 44 42 45 struct _IO_FILE { … … 82 85 /** Points to end of occupied space when in read mode. */ 83 86 uint8_t *buf_tail; 87 88 /** Pushed back characters */ 89 uint8_t ungetc_buf[UNGETC_MAX]; 90 91 /** Number of pushed back characters */ 92 int ungetc_chars; 84 93 }; 85 94 -
uspace/lib/c/include/stdio.h
rbea710f rbd5414e 109 109 extern int puts(const char *); 110 110 111 extern int ungetc(int, FILE *); 112 111 113 /* Formatted string output functions */ 112 114 extern int fprintf(FILE *, const char*, ...)
Note:
See TracChangeset
for help on using the changeset viewer.