Function symLink [src]

Creates a symbolic link named sym_link_path which contains the string target_path. A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent one; the latter case is known as a dangling link. If sym_link_path exists, it will not be overwritten. On Windows, both paths should be encoded as WTF-8. On WASI, both paths should be encoded as valid UTF-8. On other platforms, both paths are an opaque sequence of bytes with no particular encoding.

Prototype

pub fn symLink( self: Dir, target_path: []const u8, sym_link_path: []const u8, flags: SymLinkFlags, ) !void

Parameters

self: Dirtarget_path: []const u8sym_link_path: []const u8flags: SymLinkFlags

Source

pub fn symLink( self: Dir, target_path: []const u8, sym_link_path: []const u8, flags: SymLinkFlags, ) !void { if (native_os == .wasi and !builtin.link_libc) { return self.symLinkWasi(target_path, sym_link_path, flags); } if (native_os == .windows) { // Target path does not use sliceToPrefixedFileW because certain paths // are handled differently when creating a symlink than they would be // when converting to an NT namespaced path. CreateSymbolicLink in // symLinkW will handle the necessary conversion. var target_path_w: windows.PathSpace = undefined; if (try std.unicode.checkWtf8ToWtf16LeOverflow(target_path, &target_path_w.data)) { return error.NameTooLong; } target_path_w.len = try std.unicode.wtf8ToWtf16Le(&target_path_w.data, target_path); target_path_w.data[target_path_w.len] = 0; // However, we need to canonicalize any path separators to `\`, since if // the target path is relative, then it must use `\` as the path separator. mem.replaceScalar( u16, target_path_w.data[0..target_path_w.len], mem.nativeToLittle(u16, '/'), mem.nativeToLittle(u16, '\\'), ); const sym_link_path_w = try windows.sliceToPrefixedFileW(self.fd, sym_link_path); return self.symLinkW(target_path_w.span(), sym_link_path_w.span(), flags); } const target_path_c = try posix.toPosixPath(target_path); const sym_link_path_c = try posix.toPosixPath(sym_link_path); return self.symLinkZ(&target_path_c, &sym_link_path_c, flags); }