Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 5d50c419 in mainline for uspace/lib/c/generic/io/chardev.c


Ignore:
Timestamp:
2017-11-19T21:14:19Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
c657bd7
Parents:
75fcf9b
Message:

Chardev API should separate error code from number of bytes transferred. This is cleaner, allows the code to be more independent of Exxx sign and allows for partial success (some bytes successfully transferred and then an error occurred.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/chardev.c

    r75fcf9b r5d50c419  
    4040#include <io/chardev.h>
    4141#include <ipc/chardev.h>
     42#include <stddef.h>
    4243#include <stdlib.h>
    4344
     
    7677}
    7778
    78 ssize_t chardev_read(chardev_t *chardev, void *data, size_t size)
     79int chardev_read(chardev_t *chardev, void *data, size_t size, size_t *nread)
    7980{
    8081        if (size > 4 * sizeof(sysarg_t))
     
    8889        if (ret > 0 && (size_t)ret <= size)
    8990                memcpy(data, message, size);
    90         return ret;
     91
     92        if (ret < 0) {
     93                *nread = 0;
     94                return ret;
     95        }
     96
     97        *nread = ret;
     98        return EOK;
    9199}
    92100
    93 ssize_t chardev_write(chardev_t *chardev, const void *data, size_t size)
     101int chardev_write(chardev_t *chardev, const void *data, size_t size,
     102    size_t *nwritten)
    94103{
    95104        int ret;
     
    104113            message[0], message[1], message[2]);
    105114        async_exchange_end(exch);
    106         return ret;
     115
     116        if (ret < 0) {
     117                *nwritten = 0;
     118                return ret;
     119        }
     120
     121        *nwritten = ret;
     122        return EOK;
    107123}
    108124
Note: See TracChangeset for help on using the changeset viewer.