blob: 4e6da42b3d8f2584b7073540e72925b9a7ad0e81 [file] [log] [blame] [raw]
#include <windows.h>
#include <nt.h>
#include <sys/stat.h>
#include <pathname.h>
#include <stdio.h>
int mkdir(const char *pathname, mode_t mode) {
unsigned long int file_access = SYNCHRONIZE;
unsigned long int file_attrib = 0;
unsigned long int file_share = 0;
unsigned long int file_create_disposition = FILE_CREATE;
unsigned long int file_create_options = FILE_DIRECTORY_FILE;
switch(mode & (S_IREAD | S_IWRITE | S_IEXEC)) {
case 0: // XXX
case S_IREAD:
file_attrib |= FILE_ATTRIBUTE_READONLY;
break;
case S_IWRITE: // XXX
case S_IREAD | S_IWRITE:
file_attrib |= FILE_ATTRIBUTE_NORMAL;
break;
case S_IEXEC:
//file_access |= FILE_TRAVERSE;
file_attrib |= FILE_ATTRIBUTE_READONLY; // ?
break;
case S_IREAD | S_IEXEC:
//file_access |= FILE_LIST_DIRECTORY;
file_attrib |= FILE_ATTRIBUTE_READONLY;
break;
case S_IREAD | S_IWRITE | S_IEXEC:
//file_access |= FILE_LIST_DIRECTORY;
case S_IWRITE | S_IEXEC:
//file_access |= FILE_TRAVERSE;
file_attrib |= FILE_ATTRIBUTE_NORMAL;
break;
default:
puts(__FILE__": Unexpected code path");
abort();
}
UNICODE_STRING ntpathname;
RtlCreateUnicodeStringFromAsciiz(&ntpathname, pathname);
PATHNAME_UNIX2NT_UTF16_STRUCT(ntpathname);
OBJECT_ATTRIBUTES objectattrib = { sizeof(OBJECT_ATTRIBUTES), NULL, &ntpathname, 0, NULL, NULL };
void *dir;
IO_STATUS_BLOCK io_status;
long int status = NtCreateFile(&dir, file_access, &objectattrib, &io_status, NULL, file_attrib, file_share, file_create_disposition, file_create_options, NULL, 0);
//printf("nativelibc debug: mkdir: status = 0x%lx\n", status);
RtlFreeUnicodeString(&ntpathname);
//if(ntstatus_to_errno(status)) return -1;
if(status < 0) return -1; // TODO: implemente the errno
status = NtClose(dir);
//return ntstatus_to_errno(status) ? -1 : 0;
return status ? -1 : 0; // TODO: implemente the errno
}