mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-09 18:39:25 +01:00
ee3bb10df4
- Added wut_rules and wut/rpx/rpl.specs to share/ - Replaced wut's CMake-based buildsystem with a standard Makefile - Conflated all wut libraries into a single libwut.a library - wut's old buildsystems (CMake & plain make) are broken as a result, this will be fixed in the future - Docs, tests and samples are not buildable either at the moment - wutcrt/wutnewlib: - RPX start function is __rpx_start, while RPL is __rpl_start - __init/fini_wut_* functions are no longer weak - __init_wut/__fini_wut are instead weak - Removed _exit implementation - exit syscall now points to _Exit instead of pointing to itself - wutstdc++: - Renamed .cc files to .cpp - Temporarily disabled, due to an issue that will be addressed shortly - wutdevoptab: - Fixed uninitialized variable warnings in __wut_fs_read/write
71 lines
1.6 KiB
C
71 lines
1.6 KiB
C
#include "devoptab_fs.h"
|
|
|
|
ssize_t
|
|
__wut_fs_read(struct _reent *r,
|
|
void *fd,
|
|
char *ptr,
|
|
size_t len)
|
|
{
|
|
FSStatus status = 0;
|
|
FSCmdBlock cmd;
|
|
uint8_t *alignedReadBuffer;
|
|
uint32_t bytes, bytesRead;
|
|
__wut_fs_file_t *file;
|
|
|
|
if (!fd || !ptr) {
|
|
r->_errno = EINVAL;
|
|
return -1;
|
|
}
|
|
|
|
FSInitCmdBlock(&cmd);
|
|
file = (__wut_fs_file_t *)fd;
|
|
bytesRead = 0;
|
|
|
|
// Check that the file was opened with read access
|
|
if ((file->flags & O_ACCMODE) == O_WRONLY) {
|
|
r->_errno = EBADF;
|
|
return -1;
|
|
}
|
|
|
|
// Copy to internal buffer due to alignment requirement and read in chunks.
|
|
alignedReadBuffer = memalign(0x40, 8192);
|
|
while (len > 0) {
|
|
size_t toRead = len > 8192 ? 8192 : len;
|
|
|
|
// Write the data
|
|
status = FSReadFile(__wut_devoptab_fs_client, &cmd, alignedReadBuffer, 1,
|
|
toRead, file->fd, 0, -1);
|
|
if (status <= 0) {
|
|
break;
|
|
}
|
|
|
|
// Copy to internal buffer
|
|
bytes = (uint32_t)status;
|
|
memcpy(ptr, alignedReadBuffer, bytes);
|
|
|
|
file->offset += bytes;
|
|
bytesRead += bytes;
|
|
ptr += bytes;
|
|
len -= bytes;
|
|
|
|
if (bytes < toRead) {
|
|
// If we did not read the full requested toRead bytes then we reached
|
|
// the end of the file.
|
|
break;
|
|
}
|
|
}
|
|
free(alignedReadBuffer);
|
|
|
|
// Return partial read
|
|
if (bytesRead > 0) {
|
|
return bytesRead;
|
|
}
|
|
|
|
if (status < 0) {
|
|
r->_errno = __wut_fs_translate_error(status);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|