aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/cd.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/cd.c')
-rw-r--r--bin/sh/cd.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 1330c850c7fb..fa6f4925acee 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -79,7 +79,7 @@ static char *prevdir; /* previous working directory */
static char *cdcomppath;
int
-cdcmd(int argc, char **argv)
+cdcmd(int argc __unused, char **argv __unused)
{
const char *dest;
const char *path;
@@ -89,9 +89,8 @@ cdcmd(int argc, char **argv)
int rc;
int errno1 = ENOENT;
- optreset = 1; optind = 1; opterr = 0; /* initialize getopt */
phys = Pflag;
- while ((ch = getopt(argc, argv, "eLP")) != -1) {
+ while ((ch = nextopt("eLP")) != '\0') {
switch (ch) {
case 'e':
getcwderr = 1;
@@ -102,18 +101,13 @@ cdcmd(int argc, char **argv)
case 'P':
phys = 1;
break;
- default:
- error("unknown option: -%c", optopt);
- break;
}
}
- argc -= optind;
- argv += optind;
- if (argc > 1)
+ if (*argptr != NULL && argptr[1] != NULL)
error("too many arguments");
- if ((dest = *argv) == NULL && (dest = bltinlookup("HOME", 1)) == NULL)
+ if ((dest = *argptr) == NULL && (dest = bltinlookup("HOME", 1)) == NULL)
error("HOME not set");
if (*dest == '\0')
dest = ".";
@@ -330,14 +324,13 @@ updatepwd(char *dir)
}
int
-pwdcmd(int argc, char **argv)
+pwdcmd(int argc __unused, char **argv __unused)
{
char *p;
int ch, phys;
- optreset = 1; optind = 1; opterr = 0; /* initialize getopt */
phys = Pflag;
- while ((ch = getopt(argc, argv, "LP")) != -1) {
+ while ((ch = nextopt("LP")) != '\0') {
switch (ch) {
case 'L':
phys = 0;
@@ -345,15 +338,10 @@ pwdcmd(int argc, char **argv)
case 'P':
phys = 1;
break;
- default:
- error("unknown option: -%c", optopt);
- break;
}
}
- argc -= optind;
- argv += optind;
- if (argc != 0)
+ if (*argptr != NULL)
error("too many arguments");
if (!phys && getpwd()) {