* this function is a POSIX compliant version, which will read specified data * buffer length for an open file descriptor. * * @param fd the file descriptor. * @param buf the buffer to save the read data. * @param len the maximal length of data buffer * @param offset the file pos * * @return the actual read data buffer length. If the returned value is 0, it * may be reach the end of file,
| 1383 | * may be reach the end of file, please check errno. |
| 1384 | */ |
| 1385 | ssize_t pread(int fd, void *buf, size_t len, off_t offset) |
| 1386 | { |
| 1387 | ssize_t result; |
| 1388 | off_t fpos; |
| 1389 | struct dfs_file *file; |
| 1390 | |
| 1391 | if (buf == NULL) |
| 1392 | { |
| 1393 | rt_set_errno(-EBADF); |
| 1394 | return -1; |
| 1395 | } |
| 1396 | |
| 1397 | file = fd_get(fd); |
| 1398 | if (file == NULL) |
| 1399 | { |
| 1400 | rt_set_errno(-EBADF); |
| 1401 | |
| 1402 | return -1; |
| 1403 | } |
| 1404 | |
| 1405 | /* fpos lock */ |
| 1406 | fpos = dfs_file_get_fpos(file); |
| 1407 | result = dfs_file_pread(file, buf, len, offset); |
| 1408 | /* fpos unlock */ |
| 1409 | dfs_file_set_fpos(file, fpos); |
| 1410 | if (result < 0) |
| 1411 | { |
| 1412 | rt_set_errno(result); |
| 1413 | |
| 1414 | return -1; |
| 1415 | } |
| 1416 | |
| 1417 | return result; |
| 1418 | } |
| 1419 | RTM_EXPORT(pread); |
| 1420 | |
| 1421 | /** |
no test coverage detected