14cc295c30c0fbaf2a57c7bd1478e98a8f2b60c9
Enhanced the deterministic simulation framework with comprehensive error handling: **Socket Operations:** - mock_socket: Set EAFNOSUPPORT, EMFILE - mock_bind: Set EBADF, ENOTSOCK, EINVAL, EADDRINUSE (with address collision detection) - mock_listen: Set EBADF, ENOTSOCK, EDESTADDRREQ (check socket is bound) - mock_accept: Set EBADF, EINVAL, EWOULDBLOCK, ECONNABORTED, EMFILE - mock_connect: Set EBADF, EISCONN, EINVAL, EINPROGRESS - mock_recv: Set EBADF, EOPNOTSUPP, ENOTCONN, ECONNRESET, EWOULDBLOCK - mock_send: Set EBADF, EOPNOTSUPP, ENOTCONN, EPIPE, EWOULDBLOCK - mock_getsockopt: Set EBADF, ENOPROTOOPT, EINVAL (implemented SO_ERROR) - mock_setsockopt: Set EBADF, ENOPROTOOPT (no-op but validates input) **File Operations (Linux):** - mock_close: Set EBADF with bounds checking - mock_flock: Set EBADF with validation - mock_fsync: Set EBADF, EINVAL - mock_read: Set EBADF with descriptor type checking - mock_write: Set EBADF with descriptor type checking - mock_fstat: Set EBADF with validation - All file ops forward errno from real syscalls when appropriate **File Operations (Windows):** - mock_CloseHandle: SetLastError ERROR_INVALID_HANDLE - mock_LockFile/UnlockFile: SetLastError ERROR_INVALID_HANDLE - mock_FlushFileBuffers: SetLastError ERROR_INVALID_HANDLE - mock_ReadFile/WriteFile: SetLastError ERROR_INVALID_HANDLE - mock_GetFileSizeEx: SetLastError ERROR_INVALID_HANDLE - All Windows file ops forward errors from real API calls **Simulated Clock:** - Implemented mock_clock_gettime with proper errno handling - Returns simulated time for deterministic behavior - Validates clock ID (CLOCK_REALTIME, CLOCK_MONOTONIC) - Sets EFAULT for NULL pointer, EINVAL for invalid clock ID **Improvements:** - Added comprehensive bounds checking on all file descriptors - Proper descriptor type validation before operations - Peer connection validation in socket operations - Address-in-use detection for bind operations - Consistent error code semantics matching POSIX/Windows standards All file I/O operations continue to forward to real OS as intended, with mocking layer providing precise error simulation and validation.
Languages
C
98.4%
Shell
1%
Zig
0.4%
Batchfile
0.2%