| #include <windows.h> |
| #include <nt.h> |
| #include <sys/stat.h> |
| #include <pathname.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: |
| 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); |
| //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 |
| } |