forked from wiiu-env/libmocha
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevoptab_fsa_truncate.cpp
More file actions
39 lines (32 loc) · 1.17 KB
/
devoptab_fsa_truncate.cpp
File metadata and controls
39 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "devoptab_fsa.h"
#include "logger.h"
#include <mutex>
int __fsa_ftruncate(struct _reent *r,
void *fd,
off_t len) {
FSError status;
// Make sure length is non-negative
if (!fd || len < 0) {
r->_errno = EINVAL;
return -1;
}
auto *file = (__fsa_file_t *) fd;
auto *deviceData = (FSADeviceData *) r->deviceData;
std::lock_guard<MutexWrapper> lock(file->mutex);
// Set the new file size
status = FSASetPosFile(deviceData->clientHandle, file->fd, len);
if (status < 0) {
DEBUG_FUNCTION_LINE_ERR("FSASetPosFile(0x%08X, 0x%08X, 0x%08llX) failed: %s",
deviceData->clientHandle, file->fd, len, FSAGetStatusStr(status));
r->_errno = __fsa_translate_error(status);
return -1;
}
status = FSATruncateFile(deviceData->clientHandle, file->fd);
if (status < 0) {
DEBUG_FUNCTION_LINE_ERR("FSATruncateFile(0x%08X, 0x%08X) failed: %s",
deviceData->clientHandle, file->fd, FSAGetStatusStr(status));
r->_errno = __fsa_translate_error(status);
return -1;
}
return 0;
}