blob: 931a572944ea171e8a63f4560f65683241777a23 [file] [log] [blame] [raw]
#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 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 ntstatus_to_errno(status) ? -1 : 0;
return status ? -1 : 0;
}