Hard link a file

How do you create a hard link to a file?

I was thinking there might be an option to pass to fs.Dir.symLink(), but I didn’t see one nor did I find another function in the fs module.

I also checked to see if fs.Dir.copyFile() had an option you could pass to hard link the file instead of copying it, but there wasn’t one.

Hello @slanden Welcome to ziggit :slight_smile:

For hard links you can call std.posix.link

Thanks @dimdin ! While I was looking up what the flags parameter could be, I saw that this function corresponds to the link function from C. It didn’t appear to need me to link libc in the build, it just worked. Thanks!

3 Likes

It didn’t appear to need me to link libc in the build, it just worked. Thanks!

That’s one cool think about Zig is that linking to LibC isn’t required if you don’t need it, but if you DO link to libc, many of those functions will end up pointing to the libc implementation.

2 Likes