aboutsummaryrefslogtreecommitdiff
path: root/jim-file.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2020-04-18 10:40:05 +1000
committerSteve Bennett <steveb@workware.net.au>2020-05-04 21:57:37 +1000
commit6b7b6b8c9fb6c203e99847a1114825504599b9f9 (patch)
tree7d925901ff77722e73d2432bdfacb8fced239c28 /jim-file.c
parentda82368c816c8d06f425aa3f25a2a918fdba1df1 (diff)
downloadjimtcl-6b7b6b8c9fb6c203e99847a1114825504599b9f9.zip
jimtcl-6b7b6b8c9fb6c203e99847a1114825504599b9f9.tar.gz
jimtcl-6b7b6b8c9fb6c203e99847a1114825504599b9f9.tar.bz2
file: rootname, dirname fixes to match Tcl
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-file.c')
-rw-r--r--jim-file.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/jim-file.c b/jim-file.c
index 24f39e5..49bd331 100644
--- a/jim-file.c
+++ b/jim-file.c
@@ -254,11 +254,13 @@ static int file_cmd_dirname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
const char *path = Jim_String(objPtr);
const char *p = strrchr(path, '/');
- if (!p && path[0] == '.' && path[1] == '.' && path[2] == '\0') {
- Jim_SetResultString(interp, "..", -1);
- } else if (!p) {
+ if (!p) {
Jim_SetResultString(interp, ".", -1);
}
+ else if (p[1] == 0) {
+ /* Trailing slash so do nothing */
+ Jim_SetResult(interp, objPtr);
+ }
else if (p == path) {
Jim_SetResultString(interp, "/", -1);
}
@@ -306,18 +308,16 @@ static int file_cmd_split(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int file_cmd_rootname(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
- Jim_Obj *objPtr = JimStripTrailingSlashes(interp, argv[0]);
- const char *path = Jim_String(objPtr);
+ const char *path = Jim_String(argv[0]);
const char *lastSlash = strrchr(path, '/');
const char *p = strrchr(path, '.');
if (p == NULL || (lastSlash != NULL && lastSlash > p)) {
- Jim_SetResult(interp, objPtr);
+ Jim_SetResult(interp, argv[0]);
}
else {
Jim_SetResultString(interp, path, p - path);
}
- Jim_DecrRefCount(interp, objPtr);
return JIM_OK;
}