MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pread

Function pread

components/dfs/dfs_v2/src/dfs_posix.c:1385–1418  ·  view source on GitHub ↗

* 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,

Source from the content-addressed store, hash-verified

1383 * may be reach the end of file, please check errno.
1384 */
1385ssize_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}
1419RTM_EXPORT(pread);
1420
1421/**

Callers 1

sys_pread64Function · 0.85

Calls 5

rt_set_errnoFunction · 0.85
dfs_file_get_fposFunction · 0.85
dfs_file_preadFunction · 0.85
dfs_file_set_fposFunction · 0.85
fd_getFunction · 0.70

Tested by

no test coverage detected