| #include <windows.h> |
| #include <nt.h> |
| //#include <errno.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); |
| int i; |
| for(i=0; i<old_path.Length; i++) if(old_path.Buffer[i] == L'/') old_path.Buffer[i] = L'\\'; |
| for(i=0; i<new_path.Length; i++) if(new_path.Buffer[i] == L'/') new_path.Buffer[i] = L'\\'; |
| OBJECT_ATTRIBUTES orig_object = { sizeof(OBJECT_ATTRIBUTES), NULL, &new_path, 0, NULL, NULL }; |
| long int status = NtCreateSymbolicLinkObject(&handle, SYMBOLIC_LINK_ALL_ACCESS, &orig_object, &old_path); |
| RtlFreeUnicodeString(&old_path); |
| RtlFreeUnicodeString(&new_path); |
| //printf("nativelibc debug: symlink: status = 0x%lx\n", status); |
| //return ((errno = ntstatus_to_errno(status))) ? -1 : 0; |
| return status ? -1 : 0; |
| } |