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

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


Ignore:
Timestamp:
2017-11-20T10:06:59Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
19ea61d
Parents:
5d50c419
git-author:
Jiri Svoboda <jiri@…> (2017-11-19 22:05:26)
git-committer:
Jiri Svoboda <jiri@…> (2017-11-20 10:06:59)
Message:

Less is sometimes more. Need chardev_read to be able to return less bytes than requested if less is available. Otherwise cannot read variable-sized packets except yte-by-byte.

File:
1 edited

Legend:

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

    r5d50c419 rc657bd7  
    7777}
    7878
    79 int chardev_read(chardev_t *chardev, void *data, size_t size, size_t *nread)
     79/** Read from character device.
     80 *
     81 * Read as much data as is available from character device up to @a size
     82 * bytes into @a buf. On success EOK is returned and at least one byte
     83 * is read (if no byte is available the function blocks). The number
     84 * of bytes read is stored in @a *nread.
     85 *
     86 * On error a non-zero error code is returned and @a *nread is filled with
     87 * the number of bytes that were successfully transferred.
     88 *
     89 * @param chardev Character device
     90 * @param buf Destination buffer
     91 * @param size Maximum number of bytes to read
     92 * @param nread Place to store actual number of bytes read
     93 *
     94 * @return EOK on success or non-zero error code
     95 */
     96int chardev_read(chardev_t *chardev, void *buf, size_t size, size_t *nread)
    8097{
    8198        if (size > 4 * sizeof(sysarg_t))
     
    88105        async_exchange_end(exch);
    89106        if (ret > 0 && (size_t)ret <= size)
    90                 memcpy(data, message, size);
     107                memcpy(buf, message, size);
    91108
    92109        if (ret < 0) {
     
    99116}
    100117
     118/** Write to character device.
     119 *
     120 * Write @a size bytes from @a data to character device. On success EOK
     121 * is returned, all bytes were written and @a *nwritten is set to @a size.
     122 *
     123 * On error a non-zero error code is returned and @a *nwritten is filled with
     124 * the number of bytes that were successfully transferred.
     125 *
     126 * @param chardev Character device
     127 * @param buf Destination buffer
     128 * @param size Maximum number of bytes to read
     129 * @param nwritten Place to store actual number of bytes written
     130 *
     131 * @return EOK on success or non-zero error code
     132 */
    101133int chardev_write(chardev_t *chardev, const void *data, size_t size,
    102134    size_t *nwritten)
Note: See TracChangeset for help on using the changeset viewer.