diff options
| author | Erik Andersen <andersen@codepoet.org> | 2000-02-07 05:29:42 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 2000-02-07 05:29:42 +0000 |
| commit | fac10d7c59f7db0facd5fb94de273310b9ec86e6 (patch) | |
| tree | dccf8f905fc5807239883da9fca6597037d487fc /coreutils/ln.c | |
| parent | 50bc101b7d6e847a9a0621ca3eb28c7117d095e5 (diff) | |
| download | busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.gz busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.bz2 busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.zip | |
A few minor updates. ;-)
Seriously though, read the Changelog for busybox 0.42,
which this is about to become...
-Erik
Diffstat (limited to 'coreutils/ln.c')
| -rw-r--r-- | coreutils/ln.c | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c index 60fe39438..f20b340ea 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c | |||
| @@ -22,26 +22,32 @@ | |||
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | #include "internal.h" | 24 | #include "internal.h" |
| 25 | #define BB_DECLARE_EXTERN | ||
| 26 | #define bb_need_name_too_long | ||
| 27 | #define bb_need_not_a_directory | ||
| 28 | #include "messages.c" | ||
| 29 | |||
| 25 | #include <stdio.h> | 30 | #include <stdio.h> |
| 26 | #include <dirent.h> | 31 | #include <dirent.h> |
| 27 | #include <errno.h> | 32 | #include <errno.h> |
| 33 | #include <sys/param.h> /* for PATH_MAX */ | ||
| 28 | 34 | ||
| 29 | 35 | static const char ln_usage[] = | |
| 30 | static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n" | 36 | "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n" |
| 31 | "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n" | 37 | "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n" |
| 32 | "Options:\n" | 38 | "Options:\n" |
| 33 | "\t-s\tmake symbolic links instead of hard links\n" | 39 | "\t-s\tmake symbolic links instead of hard links\n" |
| 34 | "\t-f\tremove existing destination files\n"; | 40 | "\t-f\tremove existing destination files\n" |
| 35 | 41 | "\t-n\tno dereference symlinks - treat like normal file\n"; | |
| 36 | 42 | ||
| 37 | static int symlinkFlag = FALSE; | 43 | static int symlinkFlag = FALSE; |
| 38 | static int removeoldFlag = FALSE; | 44 | static int removeoldFlag = FALSE; |
| 39 | 45 | static int followLinks = TRUE; | |
| 40 | 46 | ||
| 41 | extern int ln_main(int argc, char **argv) | 47 | extern int ln_main(int argc, char **argv) |
| 42 | { | 48 | { |
| 43 | int status; | 49 | char *linkName; |
| 44 | static char* linkName; | 50 | int linkIntoDirFlag; |
| 45 | 51 | ||
| 46 | if (argc < 3) { | 52 | if (argc < 3) { |
| 47 | usage (ln_usage); | 53 | usage (ln_usage); |
| @@ -59,6 +65,9 @@ extern int ln_main(int argc, char **argv) | |||
| 59 | case 'f': | 65 | case 'f': |
| 60 | removeoldFlag = TRUE; | 66 | removeoldFlag = TRUE; |
| 61 | break; | 67 | break; |
| 68 | case 'n': | ||
| 69 | followLinks = FALSE; | ||
| 70 | break; | ||
| 62 | default: | 71 | default: |
| 63 | usage (ln_usage); | 72 | usage (ln_usage); |
| 64 | } | 73 | } |
| @@ -66,30 +75,54 @@ extern int ln_main(int argc, char **argv) | |||
| 66 | argv++; | 75 | argv++; |
| 67 | } | 76 | } |
| 68 | 77 | ||
| 69 | |||
| 70 | linkName = argv[argc - 1]; | 78 | linkName = argv[argc - 1]; |
| 71 | 79 | ||
| 72 | if ((argc > 3) && !(isDirectory(linkName))) { | 80 | if (strlen(linkName) > PATH_MAX) { |
| 73 | fprintf(stderr, "%s: not a directory\n", linkName); | 81 | fprintf(stderr, name_too_long, "ln"); |
| 74 | exit (FALSE); | 82 | exit FALSE; |
| 83 | } | ||
| 84 | |||
| 85 | linkIntoDirFlag = isDirectory(linkName, TRUE); | ||
| 86 | |||
| 87 | if ((argc > 3) && !linkIntoDirFlag) { | ||
| 88 | fprintf(stderr, not_a_directory, "ln", linkName); | ||
| 89 | exit FALSE; | ||
| 75 | } | 90 | } |
| 76 | 91 | ||
| 77 | while (argc-- >= 2) { | 92 | while (argc-- >= 2) { |
| 78 | if (removeoldFlag==TRUE ) { | 93 | char srcName[PATH_MAX + 1]; |
| 94 | int nChars, status; | ||
| 95 | |||
| 96 | if (strlen(*argv) > PATH_MAX) { | ||
| 97 | fprintf(stderr, name_too_long, "ln"); | ||
| 98 | exit FALSE; | ||
| 99 | } | ||
| 100 | |||
| 101 | if (followLinks == FALSE) { | ||
| 102 | strcpy(srcName, *argv); | ||
| 103 | } else { | ||
| 104 | /* Warning! This can silently truncate if > PATH_MAX, but | ||
| 105 | I don't think that there can be one > PATH_MAX anyway. */ | ||
| 106 | nChars = readlink(*argv, srcName, PATH_MAX); | ||
| 107 | srcName[nChars] = '\0'; | ||
| 108 | } | ||
| 109 | |||
| 110 | if (removeoldFlag == TRUE) { | ||
| 79 | status = ( unlink(linkName) && errno != ENOENT ); | 111 | status = ( unlink(linkName) && errno != ENOENT ); |
| 80 | if ( status != 0 ) { | 112 | if (status != 0) { |
| 81 | perror(linkName); | 113 | perror(linkName); |
| 82 | exit( FALSE); | 114 | exit FALSE; |
| 83 | } | 115 | } |
| 84 | } | 116 | } |
| 85 | if ( symlinkFlag==TRUE) | 117 | |
| 86 | status = symlink(*argv, linkName); | 118 | if (symlinkFlag == TRUE) |
| 119 | status = symlink(*argv, linkName); | ||
| 87 | else | 120 | else |
| 88 | status = link(*argv, linkName); | 121 | status = link(*argv, linkName); |
| 89 | if ( status != 0 ) { | 122 | if (status != 0) { |
| 90 | perror(linkName); | 123 | perror(linkName); |
| 91 | exit( FALSE); | 124 | exit FALSE; |
| 92 | } | 125 | } |
| 93 | } | 126 | } |
| 94 | exit( TRUE); | 127 | exit TRUE; |
| 95 | } | 128 | } |
