* @brief This function will write some data to a device. * * @param dev is the pointer of device driver structure. * * @param pos is the position when writing. * * @param buffer is the data buffer to be written to device. * * @param size is the size of buffer. * * @return the actually written size on successful, otherwise 0 will be returned. * * @note the unit of size/pos is a block fo
| 378 | * @note the unit of size/pos is a block for block device. |
| 379 | */ |
| 380 | rt_ssize_t rt_device_write(rt_device_t dev, |
| 381 | rt_off_t pos, |
| 382 | const void *buffer, |
| 383 | rt_size_t size) |
| 384 | { |
| 385 | /* parameter check */ |
| 386 | RT_ASSERT(dev != RT_NULL); |
| 387 | RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); |
| 388 | |
| 389 | if (dev->ref_count == 0) |
| 390 | { |
| 391 | rt_set_errno(-RT_ERROR); |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | /* call device_write interface */ |
| 396 | if (device_write != RT_NULL) |
| 397 | { |
| 398 | return device_write(dev, pos, buffer, size); |
| 399 | } |
| 400 | |
| 401 | /* set error code */ |
| 402 | rt_set_errno(-RT_ENOSYS); |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | RTM_EXPORT(rt_device_write); |
| 407 | |
| 408 | /** |