1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2015-01-28     Bernard      first version
9  */
10 
11 #include <rtthread.h>
12 #include <LowLevelIOInterface.h>
13 #include <unistd.h>
14 #include <compiler_private.h>
15 #define DBG_TAG    "dlib.syscall.lseek"
16 #define DBG_LVL    DBG_INFO
17 #include <rtdbg.h>
18 
19 /*
20  * The "__lseek" function makes the next file operation (__read or
21  * __write) act on a new location.  The parameter "whence" specifies
22  * how the "offset" parameter should be interpreted according to the
23  * following table:
24  *
25  *  0 (=SEEK_SET) - Goto location "offset".
26  *  1 (=SEEK_CUR) - Go "offset" bytes from the current location.
27  *  2 (=SEEK_END) - Go to "offset" bytes from the end.
28  *
29  * This function should return the current file position, or -1 on
30  * failure.
31  */
32 
33 #pragma module_name = "?__lseek"
34 
__lseek(int handle,long offset,int whence)35 long __lseek(int handle, long offset, int whence)
36 {
37     if (handle == _LLIO_STDOUT ||
38         handle == _LLIO_STDERR ||
39         handle == _LLIO_STDIN)
40         return _LLIO_ERROR;
41 #ifdef DFS_USING_POSIX
42     return lseek(handle, offset, whence);
43 #else
44     LOG_W(_WARNING_WITHOUT_FS);
45     return _LLIO_ERROR;
46 #endif /* DFS_USING_POSIX */
47 }
48