| #include <windows.h> |
| #include <nt.h> |
| #include <errno.h> |
| #include <pathname.h> |
| |
| int symlink(const char *oldpath, const char *newpath) { |
| void *handle; |
| UNICODE_STRING old_path; |
| UNICODE_STRING new_path; |
| RtlCreateUnicodeStringFromAsciiz(&old_path, oldpath); |
| RtlCreateUnicodeStringFromAsciiz(&new_path, newpath); |
| PATHNAME_UNIX2NT_UTF16_STRUCT(old_path); |
| PATHNAME_UNIX2NT_UTF16_STRUCT(new_path); |
| OBJECT_ATTRIBUTES new_object = { sizeof(OBJECT_ATTRIBUTES), NULL, &new_path, 0, NULL, NULL }; |
| long int status = NtCreateSymbolicLinkObject(&handle, SYMBOLIC_LINK_ALL_ACCESS, &new_object, &old_path); |
| RtlFreeUnicodeString(&old_path); |
| RtlFreeUnicodeString(&new_path); |
| //printf("nativelibc debug: symlink: status = 0x%lx\n", status); |
| //if(ntstatus_to_errno(status)) return -1; |
| //if(ntstatus_to_errno(NtClose(handle))) return -1; |
| if(status) return -1; |
| if(NtClose(handle)) return -1; |
| return 0; |
| } |