PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, PHYSFS_uint64 len) { const int fd = *((int *) opaque); ssize_t rc = 0; if (!__PHYSFS_ui64FitsAddressSpace(len)) BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); rc = write(fd, (void *) buffer, (size_t) len); BAIL_IF_MACRO(rc == -1, errcodeFromErrno(), rc); assert(rc >= 0); assert(rc <= len); return (PHYSFS_sint64) rc; } /* __PHYSFS_platformWrite */
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len) { HANDLE Handle = ((WinApiFile *)opaque)->handle; PHYSFS_sint64 totalRead = 0; if (!__PHYSFS_ui64FitsAddressSpace(len)) BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); while (len > 0) { const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len; DWORD numRead = 0; if (!ReadFile(Handle, buf, thislen, &numRead, NULL)) BAIL_MACRO(errcodeFromWinApi(), -1); len -= (PHYSFS_uint64)numRead; totalRead += (PHYSFS_sint64)numRead; if (numRead != thislen) break; } /* while */ return totalRead; } /* __PHYSFS_platformRead */
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, PHYSFS_uint64 len) { HANDLE Handle = ((WinApiFile *)opaque)->handle; PHYSFS_sint64 totalWritten = 0; if (!__PHYSFS_ui64FitsAddressSpace(len)) BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); while (len > 0) { const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len; DWORD numWritten = 0; if (!WriteFile(Handle, buffer, thislen, &numWritten, NULL)) BAIL_MACRO(errcodeFromWinApi(), -1); len -= (PHYSFS_uint64)numWritten; totalWritten += (PHYSFS_sint64)numWritten; if (numWritten != thislen) break; } /* while */ return totalWritten; } /* __PHYSFS_platformWrite */
void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); #undef realloc return(realloc(ptr, (size_t) s)); } /* __PHYSFS_platformRealloc */
void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s) { BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); #undef malloc return(malloc((size_t) s)); } /* __PHYSFS_platformMalloc */