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

Function lseek

components/dfs/dfs_v1/src/dfs_posix.c:287–334  ·  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

285 * @return the resulting read/write position in the file, or -1 on failed.
286 */
287off_t lseek(int fd, off_t offset, int whence)
288{
289 int result;
290 struct dfs_file *d;
291
292 d = fd_get(fd);
293 if (d == NULL)
294 {
295 rt_set_errno(-EBADF);
296
297 return -1;
298 }
299
300 switch (whence)
301 {
302 case SEEK_SET:
303 break;
304
305 case SEEK_CUR:
306 offset += d->pos;
307 break;
308
309 case SEEK_END:
310 offset += d->vnode->size;
311 break;
312
313 default:
314 rt_set_errno(-EINVAL);
315
316 return -1;
317 }
318
319 if (offset < 0)
320 {
321 rt_set_errno(-EINVAL);
322
323 return -1;
324 }
325 result = dfs_file_lseek(d, offset);
326 if (result < 0)
327 {
328 rt_set_errno(result);
329
330 return -1;
331 }
332
333 return offset;
334}
335RTM_EXPORT(lseek);
336
337#ifndef _WIN32

Callers 15

cmd_tailFunction · 0.50
dtb_node_load_from_fsFunction · 0.50
_readfileFunction · 0.50
elf_file_readFunction · 0.50
sys_lseekFunction · 0.50
dlmodule_loadFunction · 0.50
dlmodule_load_customFunction · 0.50
mmapFunction · 0.50
aio_read_workFunction · 0.50
aio_write_workFunction · 0.50
__lseekFunction · 0.50

Calls 3

rt_set_errnoFunction · 0.85
fd_getFunction · 0.70
dfs_file_lseekFunction · 0.70

Tested by 3

test_posix_writeFunction · 0.40
test_posix_readFunction · 0.40
test_posix_lseekFunction · 0.40