Changeset 341

Show
Ignore:
Timestamp:
09/06/09 21:18:06 (11 months ago)
Author:
solar
Message:

After all this time, you didn't think it would be 100% first time around, eh?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/stdio_rewrite/internals/_PDCLIB_glue.h

    r294 r341  
    3838/* stdio.h */ 
    3939 
    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*/ 
    4143int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ); 
    4244 
    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*/ 
    4448int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ); 
    4549 
  • branches/stdio_rewrite/platform/example/functions/_PDCLIB/fillbuffer.c

    r340 r341  
    2222 
    2323/* Refill read buffer of a given stream. 
    24    Returns 0 on success, EOF on failure. 
     24   Returns >0 on success, 0 on EOF, <0 on failure. 
    2525*/ 
    2626int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) 
     
    3232    } 
    3333    /* 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 ) 
    4036    { 
    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 ) 
    4349        { 
    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; 
    5060        } 
    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; 
    6863    } 
    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
    7267} 
    7368