ReactOS 0.4.16-dev-927-g467dec4
lseek.cpp File Reference
#include <corecrt_internal_lowio.h>
#include <corecrt_internal_ptd_propagation.h>
#include <stdlib.h>
Include dependency graph for lseek.cpp:

Go to the source code of this file.

Functions

static long __cdecl common_lseek_do_seek_nolock (HANDLE const os_handle, long const offset, int const origin, __crt_cached_ptd_host &ptd) throw ()
 
static __int64 __cdecl common_lseek_do_seek_nolock (HANDLE const os_handle, __int64 const offset, int const origin, __crt_cached_ptd_host &ptd) throw ()
 
template<typename Integer >
static Integer __cdecl common_lseek_nolock (int const fh, Integer const offset, int const origin, __crt_cached_ptd_host &ptd) throw ()
 
template<typename Integer >
static Integer __cdecl common_lseek (int const fh, Integer const offset, int const origin, __crt_cached_ptd_host &ptd) throw ()
 
long __cdecl _lseek_internal (int const fh, long const offset, int const origin, __crt_cached_ptd_host &ptd)
 
__int64 __cdecl _lseeki64_internal (int const fh, __int64 const offset, int const origin, __crt_cached_ptd_host &ptd)
 
long __cdecl _lseek_nolock_internal (int const fh, long const offset, int const origin, __crt_cached_ptd_host &ptd)
 
__int64 __cdecl _lseeki64_nolock_internal (int const fh, __int64 const offset, int const origin, __crt_cached_ptd_host &ptd)
 
long __cdecl _lseek (int const fh, long const offset, int const origin)
 
__int64 __cdecl _lseeki64 (int const fh, __int64 const offset, int const origin)
 
long __cdecl _lseek_nolock (int const fh, long const offset, int const origin)
 
__int64 __cdecl _lseeki64_nolock (int const fh, __int64 const offset, int const origin)
 

Function Documentation

◆ _lseek()

long __cdecl _lseek ( int const  fh,
long const  offset,
int const  origin 
)

Definition at line 150 of file lseek.cpp.

151{
152 __crt_cached_ptd_host ptd;
153 return common_lseek(fh, offset, origin, ptd);
154}
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355
GLintptr offset
Definition: glext.h:5920
voidpf uLong int origin
Definition: ioapi.h:144
static Integer __cdecl common_lseek(int const fh, Integer const offset, int const origin, __crt_cached_ptd_host &ptd)
Definition: lseek.cpp:102

◆ _lseek_internal()

long __cdecl _lseek_internal ( int const  fh,
long const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)

Definition at line 130 of file lseek.cpp.

131{
132 return common_lseek(fh, offset, origin, ptd);
133}

◆ _lseek_nolock()

long __cdecl _lseek_nolock ( int const  fh,
long const  offset,
int const  origin 
)

Definition at line 162 of file lseek.cpp.

163{
164 __crt_cached_ptd_host ptd;
165 return common_lseek_nolock(fh, offset, origin, ptd);
166}
static Integer __cdecl common_lseek_nolock(int const fh, Integer const offset, int const origin, __crt_cached_ptd_host &ptd)
Definition: lseek.cpp:69

◆ _lseek_nolock_internal()

long __cdecl _lseek_nolock_internal ( int const  fh,
long const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)

Definition at line 140 of file lseek.cpp.

141{
142 return common_lseek_nolock(fh, offset, origin, ptd);
143}

◆ _lseeki64()

__int64 __cdecl _lseeki64 ( int const  fh,
__int64 const  offset,
int const  origin 
)

Definition at line 156 of file lseek.cpp.

157{
158 __crt_cached_ptd_host ptd;
159 return common_lseek(fh, offset, origin, ptd);
160}

◆ _lseeki64_internal()

__int64 __cdecl _lseeki64_internal ( int const  fh,
__int64 const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)

Definition at line 135 of file lseek.cpp.

136{
137 return common_lseek(fh, offset, origin, ptd);
138}

◆ _lseeki64_nolock()

__int64 __cdecl _lseeki64_nolock ( int const  fh,
__int64 const  offset,
int const  origin 
)

Definition at line 168 of file lseek.cpp.

169{
170 __crt_cached_ptd_host ptd;
171 return common_lseek_nolock(fh, offset, origin, ptd);
172}

◆ _lseeki64_nolock_internal()

__int64 __cdecl _lseeki64_nolock_internal ( int const  fh,
__int64 const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)

Definition at line 145 of file lseek.cpp.

146{
147 return common_lseek_nolock(fh, offset, origin, ptd);
148}

◆ common_lseek()

template<typename Integer >
static Integer __cdecl common_lseek ( int const  fh,
Integer const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)
throw (
)
static

Definition at line 102 of file lseek.cpp.

103{
105 _UCRT_VALIDATE_CLEAR_OSSERR_RETURN(ptd, fh >= 0 && (unsigned)fh < (unsigned)_nhandle, EBADF, -1);
107
109 Integer result = -1;
110 __try
111 {
112 if ((_osfile(fh) & FOPEN) == 0)
113 {
114 ptd.get_errno().set(EBADF);
115 ptd.get_doserrno().set(0);
116 _ASSERTE(("Invalid file descriptor. File possibly closed by a different thread",0));
117 __leave;
118 }
119
121 }
123 {
125 }
127 return result;
128}
#define EBADF
Definition: acclib.h:82
int _nhandle
Definition: ioinit.cpp:34
void __cdecl __acrt_lowio_lock_fh(_In_ int _FileHandle)
void __cdecl __acrt_lowio_unlock_fh(_In_ int _FileHandle)
#define _UCRT_VALIDATE_CLEAR_OSSERR_RETURN(ptd, expr, errorcode, retexpr)
#define _UCRT_CHECK_FH_CLEAR_OSSERR_RETURN(ptd, handle, errorcode, retexpr)
#define _ASSERTE(expr)
Definition: crtdbg.h:114
#define FOPEN
GLuint64EXT * result
Definition: glext.h:11304
#define __try
Definition: pseh2_64.h:188
#define __leave
Definition: pseh2_64.h:192
#define __endtry
Definition: pseh2_64.h:191
#define __finally
Definition: pseh2_64.h:190
#define _osfile(i)
Definition: internal.h:72

Referenced by _lseek(), _lseek_internal(), _lseeki64(), and _lseeki64_internal().

◆ common_lseek_do_seek_nolock() [1/2]

static __int64 __cdecl common_lseek_do_seek_nolock ( HANDLE const  os_handle,
__int64 const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)
throw (
)
static

Definition at line 55 of file lseek.cpp.

56{
57 LARGE_INTEGER new_pos;
58 if (!SetFilePointerEx(os_handle, *reinterpret_cast<LARGE_INTEGER const*>(&offset), &new_pos, origin))
59 {
61 return -1;
62 }
63
64 return new_pos.QuadPart;
65}
BOOL WINAPI SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
Definition: fileinfo.c:177
void __cdecl __acrt_errno_map_os_error_ptd(unsigned long const oserrno, __crt_cached_ptd_host &ptd)
Definition: errno.cpp:97
LONGLONG QuadPart
Definition: typedefs.h:114
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define const
Definition: zconf.h:233

◆ common_lseek_do_seek_nolock() [2/2]

static long __cdecl common_lseek_do_seek_nolock ( HANDLE const  os_handle,
long const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)
throw (
)
static

Definition at line 21 of file lseek.cpp.

22{
23 LARGE_INTEGER const origin_pos = { 0 };
24
25 LARGE_INTEGER saved_pos;
26 if (!SetFilePointerEx(os_handle, origin_pos, &saved_pos, FILE_CURRENT))
27 {
29 return -1;
30 }
31
32 LARGE_INTEGER seek_pos = { 0 };
33 seek_pos.QuadPart = offset;
34
35 LARGE_INTEGER new_pos = { 0 };
36 if (!SetFilePointerEx(os_handle, seek_pos, &new_pos, origin))
37 {
39 return -1;
40 }
41
42 // The call succeeded, but the new file pointer location is too large for
43 // the return type or is a negative value. So, restore the file pointer
44 // to the saved location and return an error:
45 if (new_pos.QuadPart > LONG_MAX)
46 {
47 SetFilePointerEx(os_handle, saved_pos, nullptr, FILE_BEGIN);
48 ptd.get_errno().set(EINVAL);
49 return -1;
50 }
51
52 return static_cast<long>(new_pos.LowPart);
53}
#define EINVAL
Definition: acclib.h:90
#define FILE_BEGIN
Definition: compat.h:761
#define LONG_MAX
Definition: intsafe.h:154
ULONG LowPart
Definition: typedefs.h:106
#define FILE_CURRENT
Definition: winbase.h:114

Referenced by common_lseek_nolock().

◆ common_lseek_nolock()

template<typename Integer >
static Integer __cdecl common_lseek_nolock ( int const  fh,
Integer const  offset,
int const  origin,
__crt_cached_ptd_host &  ptd 
)
throw (
)
static

Definition at line 69 of file lseek.cpp.

70{
71 HANDLE const os_handle = reinterpret_cast<HANDLE>(_get_osfhandle(fh));
72 if (os_handle == reinterpret_cast<HANDLE>(-1))
73 {
74 ptd.get_errno().set(EBADF);
75 _ASSERTE(("Invalid file descriptor",0));
76 return -1;
77 }
78
79 Integer const new_position = common_lseek_do_seek_nolock(os_handle, offset, origin, ptd);
80 if (new_position == -1)
81 {
82 return -1;
83 }
84
85 // The call succeeded, so return success:
86 _osfile(fh) &= ~FEOFLAG; // Clear the Ctrl-Z flag
87 return new_position;
88}
static long __cdecl common_lseek_do_seek_nolock(HANDLE const os_handle, long const offset, int const origin, __crt_cached_ptd_host &ptd)
Definition: lseek.cpp:21
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)

Referenced by _lseek_nolock(), _lseek_nolock_internal(), _lseeki64_nolock(), _lseeki64_nolock_internal(), and common_lseek().