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

Function lseek

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

* this function is a POSIX compliant version, which will Reposition the file offset for * an open file descriptor. * * The `lseek` function sets the file offset for the file descriptor `fd` * to a new value, determined by the `offset` and `whence` parameters. * It can be used to seek to specific positions in a file for reading or writing. * * @param fd the file descriptor. * @param offset

Source from the content-addressed store, hash-verified

418 * @return the resulting read/write position in the file, or -1 on failed.
419 */
420off_t lseek(int fd, off_t offset, int whence)
421{
422 off_t result;
423 struct dfs_file *file;
424
425 file = fd_get(fd);
426 if (file == NULL)
427 {
428 rt_set_errno(-EBADF);
429
430 return -1;
431 }
432
433 result = dfs_file_lseek(file, offset, whence);
434 if (result < 0)
435 {
436 rt_set_errno(-EPERM);
437
438 return -1;
439 }
440
441 return result;
442}
443RTM_EXPORT(lseek);
444
445/**

Callers

nothing calls this directly

Calls 3

rt_set_errnoFunction · 0.85
fd_getFunction · 0.70
dfs_file_lseekFunction · 0.70

Tested by

no test coverage detected