* this function is a POSIX compliant version, which will write specified data * buffer length for an open file descriptor. * * @param fd the file descriptor * @param buf the data buffer to be written. * @param len the data buffer length. * @param offset the file pos * * @return the actual written data buffer length. */
| 1430 | * @return the actual written data buffer length. |
| 1431 | */ |
| 1432 | ssize_t pwrite(int fd, const void *buf, size_t len, off_t offset) |
| 1433 | { |
| 1434 | ssize_t result; |
| 1435 | off_t fpos; |
| 1436 | struct dfs_file *file; |
| 1437 | |
| 1438 | if (buf == NULL) |
| 1439 | { |
| 1440 | rt_set_errno(-EBADF); |
| 1441 | return -1; |
| 1442 | } |
| 1443 | |
| 1444 | file = fd_get(fd); |
| 1445 | if (file == NULL) |
| 1446 | { |
| 1447 | rt_set_errno(-EBADF); |
| 1448 | |
| 1449 | return -1; |
| 1450 | } |
| 1451 | /* fpos lock */ |
| 1452 | fpos = dfs_file_get_fpos(file); |
| 1453 | result = dfs_file_pwrite(file, buf, len, offset); |
| 1454 | /* fpos unlock */ |
| 1455 | dfs_file_set_fpos(file, fpos); |
| 1456 | if (result < 0) |
| 1457 | { |
| 1458 | rt_set_errno(result); |
| 1459 | |
| 1460 | return -1; |
| 1461 | } |
| 1462 | |
| 1463 | return result; |
| 1464 | } |
| 1465 | RTM_EXPORT(pwrite); |
| 1466 | |
| 1467 | /**@}*/ |
no test coverage detected