Changeset 341
- Timestamp:
- 09/06/09 21:18:06 (11 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/stdio_rewrite/internals/_PDCLIB_glue.h
r294 r341 38 38 /* stdio.h */ 39 39 40 /* A system call that writes a stream's buffer. */ 40 /* A system call that writes a stream's buffer. 41 Returns 0 on success, <0 on write error. 42 */ 41 43 int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ); 42 44 43 /* A system call that fills a stream's buffer. */ 45 /* A system call that fills a stream's buffer. 46 Returns >0 on success, 0 on EOF, and <0 on read error. 47 */ 44 48 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ); 45 49 branches/stdio_rewrite/platform/example/functions/_PDCLIB/fillbuffer.c
r340 r341 22 22 23 23 /* Refill read buffer of a given stream. 24 Returns 0 on success, EOFon failure.24 Returns >0 on success, 0 on EOF, <0 on failure. 25 25 */ 26 26 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) … … 32 32 } 33 33 /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */ 34 /* Keep trying to retrieve data until data is retrieved, an error 35 occurs, or the defined number of retries is exceeded. 36 FIXME: EOF? 37 */ 38 /* TODO: cleanup / wait function */ 39 for ( unsigned int retries = _PDCLIB_IO_RETRIES; retries > 0; --retries ) 34 ssize_t rc = read( stream->handle, stream->buffer, stream->bufsize ); 35 if ( rc > 0 ) 40 36 { 41 ssize_t rc = read( stream->handle, stream->buffer, stream->bufsize ); 42 if ( rc > 0 ) 37 /* Reading successful. */ 38 /* TODO: If text and binary streams are not identical, translation 39 needs to be done here. 40 */ 41 stream->bufend = rc; 42 stream->bufidx = 0; 43 return rc; 44 } 45 if ( rc < 0 ) 46 { 47 /* Reading error */ 48 switch ( errno ) 43 49 { 44 /* TODO: If text and binary streams are not identical, translation 45 needs to be done here. 46 */ 47 stream->bufend = rc; 48 stream->bufidx = 0; 49 return 0; 50 case EBADF: 51 case EFAULT: 52 case EINTR: 53 case EINVAL: 54 case EIO: 55 _PDCLIB_errno = _PDCLIB_EIO; 56 break; 57 default: 58 _PDCLIB_errno = _PDCLIB_EUNKNOWN; 59 break; 50 60 } 51 if ( rc < 0 ) 52 { 53 switch ( errno ) 54 { 55 case EBADF: 56 case EFAULT: 57 case EINTR: 58 case EINVAL: 59 case EIO: 60 _PDCLIB_errno = _PDCLIB_EIO; 61 break; 62 default: 63 _PDCLIB_errno = _PDCLIB_EUNKNOWN; 64 break; 65 } 66 return EOF; 67 } 61 stream->status |= _PDCLIB_ERRORFLAG; 62 return EOF; 68 63 } 69 _PDCLIB_errno = _PDCLIB_ERETRY;70 /* TODO: Should a retry timeout set the error flag of the stream? */71 return EOF;64 /* End-of-File */ 65 stream->status |= _PDCLIB_EOFFLAG; 66 return 0; 72 67 } 73 68
