Add mocks for lseek and SetFilePointer
- Added mock_lseek declaration and implementation for Linux - Added mock_SetFilePointer declaration and implementation for Windows - Added sys_lseek and sys_SetFilePointer macros for both BUILD_TEST and production modes - Mocks follow existing pattern: validate descriptors, check type, forward to real functions - Both mocks properly handle error cases and set errno/SetLastError
This commit is contained in:
@@ -1493,6 +1493,24 @@ BOOL mock_WriteFile(HANDLE handle, char *src, DWORD len, DWORD *num, OVERLAPPED
|
|||||||
return WriteFile(desc->real_fd, src, len, num, ov);
|
return WriteFile(desc->real_fd, src, len, num, ov);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DWORD mock_SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
|
||||||
|
{
|
||||||
|
if (hFile == INVALID_HANDLE_VALUE || (int)hFile < 0 || (int)hFile >= MAX_DESCRIPTORS) {
|
||||||
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
|
return INVALID_SET_FILE_POINTER;
|
||||||
|
}
|
||||||
|
int idx = (int) hFile;
|
||||||
|
|
||||||
|
Descriptor *desc = ¤t_process->desc[idx];
|
||||||
|
if (desc->type != DESC_FILE) {
|
||||||
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
|
return INVALID_SET_FILE_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward to real SetFilePointer, last error is set by the real call
|
||||||
|
return SetFilePointer(desc->real_fd, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod);
|
||||||
|
}
|
||||||
|
|
||||||
BOOL mock_GetFileSizeEx(HANDLE handle, LARGE_INTEGER *buf)
|
BOOL mock_GetFileSizeEx(HANDLE handle, LARGE_INTEGER *buf)
|
||||||
{
|
{
|
||||||
if (handle == INVALID_HANDLE_VALUE || (int)handle < 0 || (int)handle >= MAX_DESCRIPTORS) {
|
if (handle == INVALID_HANDLE_VALUE || (int)handle < 0 || (int)handle >= MAX_DESCRIPTORS) {
|
||||||
@@ -1785,6 +1803,24 @@ int mock_write(int fd, char *src, int len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
off_t mock_lseek(int fd, off_t offset, int whence)
|
||||||
|
{
|
||||||
|
if (fd < 0 || fd >= MAX_DESCRIPTORS) {
|
||||||
|
errno = EBADF; // Bad file descriptor
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int idx = fd;
|
||||||
|
|
||||||
|
Descriptor *desc = ¤t_process->desc[idx];
|
||||||
|
if (desc->type != DESC_FILE) {
|
||||||
|
errno = EBADF; // Not a file descriptor
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward to real lseek, errno is set by the real call
|
||||||
|
return lseek(desc->real_fd, offset, whence);
|
||||||
|
}
|
||||||
|
|
||||||
int mock_fstat(int fd, struct stat *buf)
|
int mock_fstat(int fd, struct stat *buf)
|
||||||
{
|
{
|
||||||
if (fd < 0 || fd >= MAX_DESCRIPTORS) {
|
if (fd < 0 || fd >= MAX_DESCRIPTORS) {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ BOOL mock_UnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffset
|
|||||||
BOOL mock_FlushFileBuffers(HANDLE handle);
|
BOOL mock_FlushFileBuffers(HANDLE handle);
|
||||||
BOOL mock_ReadFile(HANDLE handle, char *dst, DWORD len, DWORD *num, OVERLAPPED *ov);
|
BOOL mock_ReadFile(HANDLE handle, char *dst, DWORD len, DWORD *num, OVERLAPPED *ov);
|
||||||
BOOL mock_WriteFile(HANDLE handle, char *src, DWORD len, DWORD *num, OVERLAPPED *ov);
|
BOOL mock_WriteFile(HANDLE handle, char *src, DWORD len, DWORD *num, OVERLAPPED *ov);
|
||||||
|
DWORD mock_SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
|
||||||
BOOL mock_GetFileSizeEx(HANDLE handle, LARGE_INTEGER *buf);
|
BOOL mock_GetFileSizeEx(HANDLE handle, LARGE_INTEGER *buf);
|
||||||
BOOL mock_QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount);
|
BOOL mock_QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount);
|
||||||
BOOL mock_QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);
|
BOOL mock_QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);
|
||||||
@@ -81,6 +82,7 @@ int mock_flock(int fd, int op);
|
|||||||
int mock_fsync(int fd);
|
int mock_fsync(int fd);
|
||||||
int mock_read(int fd, char *dst, int len);
|
int mock_read(int fd, char *dst, int len);
|
||||||
int mock_write(int fd, char *src, int len);
|
int mock_write(int fd, char *src, int len);
|
||||||
|
off_t mock_lseek(int fd, off_t offset, int whence);
|
||||||
int mock_fstat(int fd, struct stat *buf);
|
int mock_fstat(int fd, struct stat *buf);
|
||||||
int mock_mkstemp(char *path);
|
int mock_mkstemp(char *path);
|
||||||
char* mock_realpath(char *path, char *dst);
|
char* mock_realpath(char *path, char *dst);
|
||||||
@@ -117,6 +119,7 @@ int mock_closedir(DIR *dirp);
|
|||||||
#define sys_FlushFileBuffers mock_FlushFileBuffers
|
#define sys_FlushFileBuffers mock_FlushFileBuffers
|
||||||
#define sys_ReadFile mock_ReadFile
|
#define sys_ReadFile mock_ReadFile
|
||||||
#define sys_WriteFile mock_WriteFile
|
#define sys_WriteFile mock_WriteFile
|
||||||
|
#define sys_SetFilePointer mock_SetFilePointer
|
||||||
#define sys_GetFileSizeEx mock_GetFileSizeEx
|
#define sys_GetFileSizeEx mock_GetFileSizeEx
|
||||||
#define sys__fullpath mock__fullpath
|
#define sys__fullpath mock__fullpath
|
||||||
#define sys_QueryPerformanceCounter mock_QueryPerformanceCounter
|
#define sys_QueryPerformanceCounter mock_QueryPerformanceCounter
|
||||||
@@ -133,6 +136,7 @@ int mock_closedir(DIR *dirp);
|
|||||||
#define sys_fsync mock_fsync
|
#define sys_fsync mock_fsync
|
||||||
#define sys_read mock_read
|
#define sys_read mock_read
|
||||||
#define sys_write mock_write
|
#define sys_write mock_write
|
||||||
|
#define sys_lseek mock_lseek
|
||||||
#define sys_fstat mock_fstat
|
#define sys_fstat mock_fstat
|
||||||
#define sys_mkstemp mock_mkstemp
|
#define sys_mkstemp mock_mkstemp
|
||||||
#define sys_realpath mock_realpath
|
#define sys_realpath mock_realpath
|
||||||
@@ -171,6 +175,7 @@ int mock_closedir(DIR *dirp);
|
|||||||
#define sys_FlushFileBuffers FlushFileBuffers
|
#define sys_FlushFileBuffers FlushFileBuffers
|
||||||
#define sys_ReadFile ReadFile
|
#define sys_ReadFile ReadFile
|
||||||
#define sys_WriteFile WriteFile
|
#define sys_WriteFile WriteFile
|
||||||
|
#define sys_SetFilePointer SetFilePointer
|
||||||
#define sys_GetFileSizeEx GetFileSizeEx
|
#define sys_GetFileSizeEx GetFileSizeEx
|
||||||
#define sys__fullpath _fullpath
|
#define sys__fullpath _fullpath
|
||||||
#define sys_QueryPerformanceCounter QueryPerformanceCounter
|
#define sys_QueryPerformanceCounter QueryPerformanceCounter
|
||||||
@@ -187,6 +192,7 @@ int mock_closedir(DIR *dirp);
|
|||||||
#define sys_fsync fsync
|
#define sys_fsync fsync
|
||||||
#define sys_read read
|
#define sys_read read
|
||||||
#define sys_write write
|
#define sys_write write
|
||||||
|
#define sys_lseek lseek
|
||||||
#define sys_fstat fstat
|
#define sys_fstat fstat
|
||||||
#define sys_mkstemp mkstemp
|
#define sys_mkstemp mkstemp
|
||||||
#define sys_realpath realpath
|
#define sys_realpath realpath
|
||||||
|
|||||||
Reference in New Issue
Block a user