implement SetEndOfFile, CreateDirectoryA, RemoveDirectoryA, SetFileAttributesA (#6)

* implement SetEndOfFile, CreateDirectoryA, RemoveDirectoryA, SetFileAttributesA

* call fflush before ftruncate
This commit is contained in:
camthesaxman 2022-07-05 21:26:24 -05:00 committed by GitHub
parent a8b9452f33
commit 97c946fd86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>

View File

@ -438,6 +438,31 @@ namespace kernel32 {
return r;
}
int WIN_FUNC SetEndOfFile(void *hFile) {
DEBUG_LOG("SetEndOfFile\n");
FILE *fp = files::fpFromHandle(hFile);
fflush(fp);
return ftruncate(fileno(fp), ftell(fp)) == 0;
}
int WIN_FUNC CreateDirectoryA(const char *lpPathName, void *lpSecurityAttributes) {
std::string path = files::pathFromWindows(lpPathName);
DEBUG_LOG("CreateDirectoryA(%s, %p)\n", path.c_str(), lpSecurityAttributes);
return mkdir(path.c_str(), 0755) == 0;
}
int WIN_FUNC RemoveDirectoryA(const char *lpPathName) {
std::string path = files::pathFromWindows(lpPathName);
DEBUG_LOG("RemoveDirectoryA(%s)\n", path.c_str());
return rmdir(path.c_str()) == 0;
}
int WIN_FUNC SetFileAttributesA(const char *lpPathName, unsigned int dwFileAttributes) {
std::string path = files::pathFromWindows(lpPathName);
DEBUG_LOG("SetFileAttributesA(%s, %u)\n", path.c_str(), dwFileAttributes);
return 1;
}
/*
* Time
*/
@ -879,6 +904,10 @@ void *wibo::resolveKernel32(const char *name) {
if (strcmp(name, "CreateFileA") == 0) return (void *) kernel32::CreateFileA;
if (strcmp(name, "DeleteFileA") == 0) return (void *) kernel32::DeleteFileA;
if (strcmp(name, "SetFilePointer") == 0) return (void *) kernel32::SetFilePointer;
if (strcmp(name, "SetEndOfFile") == 0) return (void *) kernel32::SetEndOfFile;
if (strcmp(name, "CreateDirectoryA") == 0) return (void *) kernel32::CreateDirectoryA;
if (strcmp(name, "RemoveDirectoryA") == 0) return (void *) kernel32::RemoveDirectoryA;
if (strcmp(name, "SetFileAttributesA") == 0) return (void *) kernel32::SetFileAttributesA;
if (strcmp(name, "GetFileSize") == 0) return (void *) kernel32::GetFileSize;
if (strcmp(name, "GetFileTime") == 0) return (void *) kernel32::GetFileTime;
if (strcmp(name, "GetSystemTime") == 0) return (void *) kernel32::GetSystemTime;