Changeset b910455 in mainline for uspace/srv/devman/util.c


Ignore:
Timestamp:
2011-04-07T09:46:11Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6639ae1
Parents:
f6bffee (diff), 8e80d3f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/util.c

    rf6bffee rb910455  
    111111}
    112112
     113ssize_t safe_read(int fd, void *buffer, size_t size)
     114{
     115        if (size == 0) {
     116                return 0;
     117        }
     118
     119        uint8_t *buf_ptr = (uint8_t *) buffer;
     120
     121        size_t total_read = 0;
     122        while (total_read < size) {
     123                ssize_t bytes_read = read(fd, buf_ptr, size - total_read);
     124                if (bytes_read < 0) {
     125                        /* Error. */
     126                        return bytes_read;
     127                } else if (bytes_read == 0) {
     128                        /* Possibly end of file. */
     129                        break;
     130                } else {
     131                        /* Read at least something. */
     132                        buf_ptr += bytes_read;
     133                        total_read += bytes_read;
     134                }
     135        }
     136
     137        return (ssize_t) total_read;
     138}
     139
    113140/** @}
    114141 */
Note: See TracChangeset for help on using the changeset viewer.