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

Changeset 84439d7 in mainline for uspace/lib/c/generic/device/char.c


Ignore:
Timestamp:
2010-12-05T09:34:46Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
75732da
Parents:
56b962d (diff), 35537a7 (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 with development/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/device/char.c

    r56b962d r84439d7  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28  
     28
    2929 /** @addtogroup libc
    3030 * @{
     
    4040#include <stdio.h>
    4141
    42 /** Read to or write from the device using its character interface.
    43  *
    44  * Helper function.
    45  *
    46  * @param dev_phone phone to the device.
    47  * @param buf the buffer for the data read from or written to the device.
    48  * @param len the maximum length of the data to be read or written.
    49  * @param read read from the device if true, write to it otherwise.
    50  *
    51  * @return non-negative number of bytes actually read from or written to the device on success,
    52  * negative error number otherwise.
    53  *
     42/** Read to or write from device.
     43 *
     44 * Helper function to read to or write from a device
     45 * using its character interface.
     46 *
     47 * @param dev_phone Phone to the device.
     48 * @param buf       Buffer for the data read
     49 *                  from or written to the device.
     50 * @param len       Maximum length of the data to be
     51 *                  read or written.
     52 * @param read      Read from the device if true,
     53 *                  write to it otherwise.
     54 *
     55 * @return Non-negative number of bytes actually read
     56 *         from or written to the device on success,
     57 *         negative error number otherwise.
     58 *
    5459 */
    55 static int rw_dev(int dev_phone, void *buf, size_t len, bool read)
     60static ssize_t rw_dev(int dev_phone, void *buf, size_t len, bool read)
    5661{
    57         ipc_call_t answer;
    58        
    5962        async_serialize_start();
    6063       
     64        ipc_call_t answer;
    6165        aid_t req;
    6266        int ret;
    6367       
    6468        if (read) {
    65                 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer);
    66                 ret = async_data_read_start(dev_phone, buf, len);               
     69                req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),
     70                    CHAR_READ_DEV, &answer);
     71                ret = async_data_read_start(dev_phone, buf, len);
    6772        } else {
    68                 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_WRITE_DEV, &answer);
     73                req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),
     74                    CHAR_WRITE_DEV, &answer);
    6975                ret = async_data_write_start(dev_phone, buf, len);
    7076        }
    7177       
    7278        ipcarg_t rc;
    73         if (ret != EOK) {               
     79        if (ret != EOK) {
    7480                async_wait_for(req, &rc);
    7581                async_serialize_end();
    76                 if (rc == EOK) {
    77                         return ret;
    78                 }
    79                 else {
    80                         return (int) rc;
    81                 }
     82                if (rc == EOK)
     83                        return (ssize_t) ret;
     84                       
     85                return (ssize_t) rc;
    8286        }
    8387       
     
    8589        async_serialize_end();
    8690       
    87         ret = (int)rc;
    88         if (EOK != ret) {
    89                 return ret;
    90         }
     91        ret = (int) rc;
     92        if (ret != EOK)
     93                return (ssize_t) ret;
    9194       
    92         return IPC_GET_ARG1(answer);   
     95        return (ssize_t) IPC_GET_ARG1(answer);
    9396}
    9497
    95 /** Read from the device using its character interface.
    96  *
    97  * @param dev_phone phone to the device.
    98  * @param buf the output buffer for the data read from the device.
    99  * @param len the maximum length of the data to be read.
    100  *
    101  * @return non-negative number of bytes actually read from the device on success, negative error number otherwise.
     98/** Read from device using its character interface.
     99 *
     100 * @param dev_phone Phone to the device.
     101 * @param buf       Output buffer for the data
     102 *                  read from the device.
     103 * @param len       Maximum length of the data to be read.
     104 *
     105 * @return Non-negative number of bytes actually read
     106 *         from the device on success, negative error
     107 *         number otherwise.
     108 *
    102109 */
    103 int read_dev(int dev_phone, void *buf, size_t len)
    104 {       
     110ssize_t read_dev(int dev_phone, void *buf, size_t len)
     111{
    105112        return rw_dev(dev_phone, buf, len, true);
    106113}
    107114
    108 /** Write to the device using its character interface.
    109  *
    110  * @param dev_phone phone to the device.
    111  * @param buf the input buffer containg the data to be written to the device.
    112  * @param len the maximum length of the data to be written.
    113  *
    114  * @return non-negative number of bytes actually written to the device on success, negative error number otherwise.
     115/** Write to device using its character interface.
     116 *
     117 * @param dev_phone Phone to the device.
     118 * @param buf       Input buffer containg the data
     119 *                  to be written to the device.
     120 * @param len       Maximum length of the data to be written.
     121 *
     122 * @return Non-negative number of bytes actually written
     123 *         to the device on success, negative error number
     124 *         otherwise.
     125 *
    115126 */
    116 int write_dev(int dev_phone, void *buf, size_t len)
     127ssize_t write_dev(int dev_phone, void *buf, size_t len)
    117128{
    118129        return rw_dev(dev_phone, buf, len, false);
    119130}
    120131
    121  
    122  /** @}
     132/** @}
    123133 */
Note: See TracChangeset for help on using the changeset viewer.