1 /* vi: set sw=4 ts=4: */
2 /*
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
4 */
5 #include "libbb.h"
6 #include "bb_archive.h"
7
create_or_remember_link(llist_t ** link_placeholders,const char * target,const char * linkname,int hard_link)8 void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
9 const char *target,
10 const char *linkname,
11 int hard_link)
12 {
13 if (hard_link || target[0] == '/' || strstr(target, "..")) {
14 llist_add_to_end(link_placeholders,
15 xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
16 );
17 return;
18 }
19 if (symlink(target, linkname) != 0) {
20 /* shared message */
21 bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
22 "sym", linkname, target
23 );
24 }
25 }
26
create_links_from_list(llist_t * list)27 void FAST_FUNC create_links_from_list(llist_t *list)
28 {
29 while (list) {
30 char *target;
31
32 target = list->data + 1 + strlen(list->data + 1) + 1;
33 if ((*list->data ? link : symlink) (target, list->data + 1)) {
34 /* shared message */
35 bb_error_msg_and_die("can't create %slink '%s' to '%s'",
36 *list->data ? "hard" : "sym",
37 list->data + 1, target
38 );
39 }
40 list = list->link;
41 }
42 }
43