blob: 1753c89c8975bd0e470512af588c1095eec84e16 [file] [log] [blame] [raw]
#include <windows.h>
#include <nt.h>
//#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <pathname.h>
int unlink(const char *name) {
int fd = open(name, O_RDONLY);
//if(fd == -1) return ntstatus_to_errno(status) ? -1 : 0;
//if(close(fd) == -1) return ntstatus_to_errno(status) ? -1 : 0;
if(fd == -1 || close(fd) == -1) return -1;
UNICODE_STRING name1;
RtlCreateUnicodeStringFromAsciiz(&name1, name);
PATHNAME_UNIX2NT_UTF16_STRUCT(name1);
OBJECT_ATTRIBUTES o = { sizeof(OBJECT_ATTRIBUTES), NULL, &name1, 0, NULL, NULL };
long int status = NtDeleteFile(&o);
RtlFreeUnicodeString(&name1);
printf("status = 0x%lx\n", status);
//return ntstatus_to_errno(status) ? -1 : 0;
return status ? -1 : 0;
}