summaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/misc.c b/src/misc.c
index b19a253..f9f0201 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -33,7 +33,7 @@
#include <grp.h>
#endif
-__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.299 2020/05/16 22:19:58 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.302 2020/08/27 19:52:45 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@@ -1328,7 +1328,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
if (go->flags & GF_ERROR)
bi_errorfz();
}
- return ('?');
+ return (ORD('?'));
}
/**
* : means argument must be present, may be part of option argument
@@ -1347,7 +1347,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
if (optionsp[0] == ':') {
go->buf[0] = c;
go->optarg = go->buf;
- return (':');
+ return (ORD(':'));
}
warningf(true, Tf_optfoo,
(go->flags & GF_NONAME) ? "" : argv[0],
@@ -1355,7 +1355,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
c, Treq_arg);
if (go->flags & GF_ERROR)
bi_errorfz();
- return ('?');
+ return (ORD('?'));
}
go->p = 0;
} else if (*o == ',') {
@@ -1383,7 +1383,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
go->optarg = NULL;
}
}
- return (c);
+ return (ord(c));
}
/*
@@ -1927,7 +1927,7 @@ do_realpath(const char *upath)
* - if file starts with '/', append file to result & set cdpathp to NULL
* - if file starts with ./ or ../ append cwd and file to result
* and set cdpathp to NULL
- * - if the first element of cdpathp doesnt start with a '/' xx or '.' xx
+ * - if the first element of cdpathp doesn't start with a '/' xx or '.' xx
* then cwd is appended to result.
* - the first element of cdpathp is appended to result
* - file is appended to result
@@ -1983,16 +1983,18 @@ make_path(const char *cwd, const char *file,
XcheckN(*xsp, xp, len);
memcpy(xp, cwd, len);
xp += len;
- if (!mksh_cdirsep(cwd[len - 1]))
- Xput(*xsp, xp, '/');
+ if (mksh_cdirsep(xp[-1]))
+ xp--;
+ *xp++ = '/';
}
*phys_pathp = Xlength(*xsp, xp);
if (use_cdpath && plen) {
XcheckN(*xsp, xp, plen);
memcpy(xp, plist, plen);
xp += plen;
- if (!mksh_cdirsep(plist[plen - 1]))
- Xput(*xsp, xp, '/');
+ if (mksh_cdirsep(xp[-1]))
+ xp--;
+ *xp++ = '/';
rval = 1;
}
}
@@ -2056,9 +2058,14 @@ simplify_path(char *p)
case '\\':
#endif
/* exactly two leading slashes? (SUSv4 3.266) */
- if (p[1] == p[0] && !mksh_cdirsep(p[2]))
+ if (p[1] == p[0] && !mksh_cdirsep(p[2])) {
/* keep them, e.g. for UNC pathnames */
+#ifdef MKSH_DOSPATH
+ *p++ = '/';
+#else
++p;
+#endif
+ }
needslash = true;
break;
default:
@@ -2189,26 +2196,26 @@ c_cd(const char **wp)
oldpwd_s = global(TOLDPWD);
if (!wp[0]) {
- /* No arguments - go home */
+ /* no arguments; go home */
if ((dir = str_val(global("HOME"))) == null) {
bi_errorf("no home directory (HOME not set)");
return (2);
}
} else if (!wp[1]) {
- /* One argument: - or dir */
- strdupx(allocd, wp[0], ATEMP);
- if (ksh_isdash((dir = allocd))) {
- afree(allocd, ATEMP);
- allocd = NULL;
+ /* one argument: - or dir */
+ if (ksh_isdash(wp[0])) {
dir = str_val(oldpwd_s);
if (dir == null) {
bi_errorf(Tno_OLDPWD);
return (2);
}
printpath = true;
+ } else {
+ strdupx(allocd, wp[0], ATEMP);
+ dir = allocd;
}
} else if (!wp[2]) {
- /* Two arguments - substitute arg1 in PWD for arg2 */
+ /* two arguments; substitute arg1 in PWD for arg2 */
size_t ilen, olen, nlen, elen;
char *cp;
@@ -2217,10 +2224,9 @@ c_cd(const char **wp)
return (2);
}
/*
- * substitute arg1 for arg2 in current path.
- * if the first substitution fails because the cd fails
- * we could try to find another substitution. For now
- * we don't
+ * Substitute arg1 for arg2 in current path. If the first
+ * substitution fails because the cd fails we could try to
+ * find another substitution. For now, we don't.
*/
if ((cp = strstr(current_wd, wp[0])) == NULL) {
bi_errorf(Tbadsubst);