aboutsummaryrefslogtreecommitdiff
path: root/libgloss/m68k/atari/atari-chdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgloss/m68k/atari/atari-chdir.c')
-rw-r--r--libgloss/m68k/atari/atari-chdir.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libgloss/m68k/atari/atari-chdir.c b/libgloss/m68k/atari/atari-chdir.c
new file mode 100644
index 0000000..edb7a70
--- /dev/null
+++ b/libgloss/m68k/atari/atari-chdir.c
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2025 Mikael Hildenborg
+ SPDX-License-Identifier: BSD-2-Clause
+*/
+
+#include <_ansi.h>
+#include "atari-gem_errno.h"
+#include "atari-traps.h"
+
+int chdir(const char *path)
+{
+ int err = GEM_E_OK;
+ if (path != 0)
+ {
+ if (path[1] == ':')
+ {
+ unsigned int drives = 0;
+ unsigned short drive = 0;
+ if (path[0] >= 'A' && path[0] <= 'Z')
+ {
+ drive = (unsigned short)(path[0] - 'A');
+ }
+ else if (path[0] >= 'a' && path[0] <= 'z')
+ {
+ drive = (unsigned short)(path[0] - 'a');
+ }
+ drives = trap1_e(drive);
+ if ((drives & (1 << drive)) == 0)
+ {
+ err = GEM_EDRIVE;
+ }
+ path += 2;
+ }
+ if (err == GEM_E_OK)
+ {
+ err = trap1_3b(path);
+ }
+ }
+ else
+ {
+ err = GEM_EPTHNF;
+ }
+ if (err < 0)
+ {
+ gem_error_to_errno(err);
+ return -1;
+ }
+ return 0;
+} \ No newline at end of file