ln: fixed command line parser. Added support for "--"
This commit is contained in:
parent
3f75503fa0
commit
2e965239ee
@ -61,7 +61,8 @@
|
|||||||
* Simplified freeramdisk and added argument checking -- Pavel Roskin.
|
* Simplified freeramdisk and added argument checking -- Pavel Roskin.
|
||||||
* Fixed segfault caused by "touch -c"
|
* Fixed segfault caused by "touch -c"
|
||||||
* Fixed segfault caused by "rm -f"
|
* Fixed segfault caused by "rm -f"
|
||||||
* Fixed segfault caused by "ln -s -s" and similar abuses.
|
* Fixed segfault caused by "ln -s -s" and similar abuses. Further fixes
|
||||||
|
and "--" support from Pavel Roskin.
|
||||||
* Fixed segfault caused by "cp -a -a" and similar abuses.
|
* Fixed segfault caused by "cp -a -a" and similar abuses.
|
||||||
* Implemented "rm -- <foo>". Implementation fixed by Pavel Roskin.
|
* Implemented "rm -- <foo>". Implementation fixed by Pavel Roskin.
|
||||||
* "which" rewritten to use stat(). Fixes to improve its compatability
|
* "which" rewritten to use stat(). Fixes to improve its compatability
|
||||||
|
@ -51,16 +51,14 @@ extern int ln_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
char *linkName;
|
char *linkName;
|
||||||
int linkIntoDirFlag;
|
int linkIntoDirFlag;
|
||||||
|
int stopIt = FALSE;
|
||||||
|
|
||||||
if (argc < 3) {
|
|
||||||
usage(ln_usage);
|
|
||||||
}
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
/* Parse any options */
|
/* Parse any options */
|
||||||
while (--argc >= 0 && *argv && **argv) {
|
while (argc > 0 && stopIt == FALSE) {
|
||||||
while (**argv == '-') {
|
if (**argv == '-') {
|
||||||
while (*++(*argv))
|
while (*++(*argv))
|
||||||
switch (**argv) {
|
switch (**argv) {
|
||||||
case 's':
|
case 's':
|
||||||
@ -72,15 +70,21 @@ extern int ln_main(int argc, char **argv)
|
|||||||
case 'n':
|
case 'n':
|
||||||
followLinks = FALSE;
|
followLinks = FALSE;
|
||||||
break;
|
break;
|
||||||
|
case '-':
|
||||||
|
stopIt = TRUE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(ln_usage);
|
usage(ln_usage);
|
||||||
}
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
argv++;
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 1) {
|
if (argc < 2) {
|
||||||
fatalError("ln: missing file argument\n");
|
usage(ln_usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
linkName = argv[argc - 1];
|
linkName = argv[argc - 1];
|
||||||
|
20
ln.c
20
ln.c
@ -51,16 +51,14 @@ extern int ln_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
char *linkName;
|
char *linkName;
|
||||||
int linkIntoDirFlag;
|
int linkIntoDirFlag;
|
||||||
|
int stopIt = FALSE;
|
||||||
|
|
||||||
if (argc < 3) {
|
|
||||||
usage(ln_usage);
|
|
||||||
}
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
/* Parse any options */
|
/* Parse any options */
|
||||||
while (--argc >= 0 && *argv && **argv) {
|
while (argc > 0 && stopIt == FALSE) {
|
||||||
while (**argv == '-') {
|
if (**argv == '-') {
|
||||||
while (*++(*argv))
|
while (*++(*argv))
|
||||||
switch (**argv) {
|
switch (**argv) {
|
||||||
case 's':
|
case 's':
|
||||||
@ -72,15 +70,21 @@ extern int ln_main(int argc, char **argv)
|
|||||||
case 'n':
|
case 'n':
|
||||||
followLinks = FALSE;
|
followLinks = FALSE;
|
||||||
break;
|
break;
|
||||||
|
case '-':
|
||||||
|
stopIt = TRUE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(ln_usage);
|
usage(ln_usage);
|
||||||
}
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
argv++;
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 1) {
|
if (argc < 2) {
|
||||||
fatalError("ln: missing file argument\n");
|
usage(ln_usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
linkName = argv[argc - 1];
|
linkName = argv[argc - 1];
|
||||||
|
Loading…
Reference in New Issue
Block a user