]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/link.c
xfsprogs: convert to SPDX license tags
[thirdparty/xfsprogs-dev.git] / io / link.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2014 Christoph Hellwig.
4 * All Rights Reserved.
5 */
6
7 #include "command.h"
8 #include "input.h"
9 #include "init.h"
10 #include "io.h"
11
12 #ifndef AT_EMPTY_PATH
13 #define AT_EMPTY_PATH 0x1000
14 #endif
15
16 static cmdinfo_t flink_cmd;
17
18 static void
19 flink_help(void)
20 {
21 printf(_(
22 "\n"
23 "link the open file descriptor to the supplied filename\n"
24 "\n"
25 "\n"));
26 }
27
28 static int
29 flink_f(
30 int argc,
31 char **argv)
32 {
33 if (argc != 2)
34 return command_usage(&flink_cmd);
35
36 if (linkat(file->fd, "", AT_FDCWD, argv[1], AT_EMPTY_PATH) < 0) {
37 perror("flink");
38 return 0;
39 }
40 return 0;
41 }
42
43 void
44 flink_init(void)
45 {
46 flink_cmd.name = "flink";
47 flink_cmd.cfunc = flink_f;
48 flink_cmd.argmin = 1;
49 flink_cmd.argmax = 1;
50 flink_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK | CMD_FLAG_ONESHOT;
51 flink_cmd.args = _("filename");
52 flink_cmd.oneline =
53 _("link the open file descriptor to the supplied filename");
54 flink_cmd.help = flink_help;
55
56 add_command(&flink_cmd);
57 }