mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-04-20 05:49:10 +00:00
attempt to support windows
This commit is contained in:
parent
a55b586df2
commit
0a3f40d5e7
2 changed files with 61 additions and 5 deletions
54
ioutil.c
54
ioutil.c
|
@ -2,6 +2,9 @@
|
|||
#include <string.h>
|
||||
#include "types.h"
|
||||
#include "ioutil.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -51,6 +54,52 @@ int closefile(FH fd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int createdir(const char *path,int secret)
|
||||
{
|
||||
return mkdir(path,secret ? 0700 : 0777);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int writeall(FH fd,const u8 *data,size_t len)
|
||||
{
|
||||
DWORD wrote;
|
||||
BOOL success;
|
||||
while (len) {
|
||||
success = WriteFile(fd,data,
|
||||
len <= (DWORD)-1 ? (DWORD)len : (DWORD)-1,&wrote,0);
|
||||
if (!success)
|
||||
return -1;
|
||||
data += wrote;
|
||||
if (len >= wrote)
|
||||
len -= wrote;
|
||||
else
|
||||
len = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FH createfile(const char *path,int secret)
|
||||
{
|
||||
// XXX no support for non-ascii chars
|
||||
// XXX don't know how to handle secret argument
|
||||
(void) secret;
|
||||
return CreateFileA(path,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0);
|
||||
}
|
||||
|
||||
int closefile(FH fd)
|
||||
{
|
||||
return CloseHandle(fd) ? 0 : -1;
|
||||
}
|
||||
|
||||
int createdir(const char *path,int secret)
|
||||
{
|
||||
// XXX don't know how to handle secret argument
|
||||
return CreateDirectoryA(path,0) ? 0 : -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int writetofile(const char *path,const u8 *data,size_t len,int secret)
|
||||
{
|
||||
FH fd = createfile(path,secret);
|
||||
|
@ -60,8 +109,3 @@ int writetofile(const char *path,const u8 *data,size_t len,int secret)
|
|||
return -1;
|
||||
return wret;
|
||||
}
|
||||
|
||||
int createdir(const char *path,int secret)
|
||||
{
|
||||
return mkdir(path,secret ? 0700 : 0777);
|
||||
}
|
||||
|
|
12
ioutil.h
12
ioutil.h
|
@ -1,6 +1,18 @@
|
|||
|
||||
#ifndef _WIN32
|
||||
|
||||
typedef int FH;
|
||||
#define FH_invalid -1
|
||||
|
||||
#else
|
||||
|
||||
#define UNICODE 1
|
||||
#include <windows.h>
|
||||
typedef HANDLE FH;
|
||||
#define FH_invalid INVALID_HANDLE_VALUE
|
||||
|
||||
#endif
|
||||
|
||||
FH createfile(const char *path,int secret);
|
||||
int closefile(FH fd);
|
||||
int writeall(FH,const u8 *data,size_t len);
|
||||
|
|
Loading…
Add table
Reference in a new issue