summaryrefslogtreecommitdiff
path: root/coreutils/ln.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-02-15 20:12:05 +0000
committerEric Andersen <andersen@codepoet.org>2001-02-15 20:12:05 +0000
commitd69d2da165d46f8ba237fe1a3080ee05fe9c5319 (patch)
tree6f4c87cd7e6929f4d0d310e3132878bf4b847bd9 /coreutils/ln.c
parentb50d707633df4857aa3ade51611edaef2792a61b (diff)
downloadbusybox-w32-d69d2da165d46f8ba237fe1a3080ee05fe9c5319.tar.gz
busybox-w32-d69d2da165d46f8ba237fe1a3080ee05fe9c5319.tar.bz2
busybox-w32-d69d2da165d46f8ba237fe1a3080ee05fe9c5319.zip
use perror_msg instead of perror to print the applet name.
-Erik
Diffstat (limited to 'coreutils/ln.c')
-rw-r--r--coreutils/ln.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 9dc7f5d8c..e35bf7a03 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -41,42 +41,47 @@ static const int LN_NODEREFERENCE = 4;
41 * linkDestName is where the link points to, 41 * linkDestName is where the link points to,
42 * linkSrcName is the name of the link to be created. 42 * linkSrcName is the name of the link to be created.
43 */ 43 */
44static int fs_link(const char *link_DestName, const char *link_SrcName, const int flag) 44static int fs_link(const char *link_destname, const char *link_srcname,
45 const int flag)
45{ 46{
46 int status; 47 int status;
47 int srcIsDir; 48 int src_is_dir;
48 char *srcName; 49 char *src_name;
49 50
50 if (link_DestName==NULL) 51 if (link_destname==NULL)
51 return(FALSE); 52 return(FALSE);
52 53
53 srcName = (char *) malloc(strlen(link_SrcName)+strlen(link_DestName)+1); 54 src_name = (char *) xmalloc(strlen(link_srcname)+strlen(link_destname)+1);
54 55
55 if (link_SrcName==NULL) 56 if (link_srcname==NULL)
56 strcpy(srcName, link_DestName); 57 strcpy(src_name, link_destname);
57 else 58 else
58 strcpy(srcName, link_SrcName); 59 strcpy(src_name, link_srcname);
59 60
60 if (flag&LN_NODEREFERENCE) 61 if (flag&LN_NODEREFERENCE)
61 srcIsDir = is_directory(srcName, TRUE, NULL); 62 src_is_dir = is_directory(src_name, TRUE, NULL);
62 else 63 else
63 srcIsDir = is_directory(srcName, FALSE, NULL); 64 src_is_dir = is_directory(src_name, FALSE, NULL);
64 65
65 if ((srcIsDir==TRUE)&&((flag&LN_NODEREFERENCE)==0)) { 66 if ((src_is_dir==TRUE)&&((flag&LN_NODEREFERENCE)==0)) {
66 strcat(srcName, "/"); 67 char* srcdir_name;
67 strcat(srcName, link_DestName); 68
69 srcdir_name = xstrdup(link_destname);
70 strcat(src_name, "/");
71 strcat(src_name, get_last_path_component(srcdir_name));
72 free(srcdir_name);
68 } 73 }
69 74
70 if (flag&LN_FORCE) 75 if (flag&LN_FORCE)
71 unlink(srcName); 76 unlink(src_name);
72 77
73 if (flag&LN_SYMLINK) 78 if (flag&LN_SYMLINK)
74 status = symlink(link_DestName, srcName); 79 status = symlink(link_destname, src_name);
75 else 80 else
76 status = link(link_DestName, srcName); 81 status = link(link_destname, src_name);
77 82
78 if (status != 0) { 83 if (status != 0) {
79 perror(srcName); 84 perror_msg(src_name);
80 return(FALSE); 85 return(FALSE);
81 } 86 }
82 return(TRUE); 87 return(TRUE);
@@ -104,12 +109,20 @@ extern int ln_main(int argc, char **argv)
104 show_usage(); 109 show_usage();
105 } 110 }
106 } 111 }
112 if (optind > (argc-1)) {
113 show_usage();
114 }
115 if (optind == (argc-1)) {
116 if (fs_link(argv[optind],
117 get_last_path_component(argv[optind]), flag)==FALSE)
118 status = EXIT_FAILURE;
119 }
107 while(optind<(argc-1)) { 120 while(optind<(argc-1)) {
108 if (fs_link(argv[optind], argv[argc-1], flag)==FALSE) 121 if (fs_link(argv[optind], argv[argc-1], flag)==FALSE)
109 status = EXIT_FAILURE; 122 status = EXIT_FAILURE;
110 optind++; 123 optind++;
111 } 124 }
112 return(status); 125 exit(status);
113} 126}
114 127
115/* 128/*