mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
2c5a378ccc
It's now possible to create symbolic links! :^) This exposed an issue in Ext2FS where we'd write uninitialized data past the end of an inode's content. Fix this by zeroing out the tail end of the last block in a file.
47 lines
886 B
C++
47 lines
886 B
C++
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <getopt.h>
|
|
#include <stdlib.h>
|
|
|
|
[[noreturn]] static void print_usage_and_exit()
|
|
{
|
|
printf("usage: ln [-s] <target> <link-path>\n");
|
|
exit(0);
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
bool flag_symlink = false;
|
|
int opt;
|
|
while ((opt = getopt(argc, argv, "s")) != -1) {
|
|
switch (opt) {
|
|
case 's':
|
|
flag_symlink = true;
|
|
break;
|
|
default:
|
|
print_usage_and_exit();
|
|
}
|
|
}
|
|
|
|
if ((optind + 1) >= argc)
|
|
print_usage_and_exit();
|
|
|
|
if (flag_symlink) {
|
|
int rc = symlink(argv[optind], argv[optind + 1]);
|
|
if (rc < 0) {
|
|
perror("symlink");
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int rc = link(argv[1], argv[2]);
|
|
if (rc < 0) {
|
|
perror("link");
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|