aboutsummaryrefslogtreecommitdiff
path: root/unix/os/zfchdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/os/zfchdr.c')
-rw-r--r--unix/os/zfchdr.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/unix/os/zfchdr.c b/unix/os/zfchdr.c
new file mode 100644
index 00000000..3beae679
--- /dev/null
+++ b/unix/os/zfchdr.c
@@ -0,0 +1,57 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <stdio.h>
+#define import_kernel
+#define import_knames
+#define import_spp
+#include <iraf.h>
+
+extern char oscwd[];
+
+
+/* ZFCHDR -- Change the current working directory. Save directory name,
+ * excluding the trailing "/", in oscwd so that a subsequent call to ZFGCWD
+ * will be able to return directory name without a big hassle.
+ */
+int
+ZFCHDR (
+ PKCHAR *newdir,
+ XINT *status
+)
+{
+ register char *ip, *op;
+ char dirname[SZ_PATHNAME];
+
+
+ /* Change pathnames like "a/b/c/" to "a/b/c".
+ */
+ for (ip=(char *)newdir, op=dirname; (*op = *ip++) != EOS; op++)
+ ;
+ if ((*(op-1) == '/') && (op - dirname > 1))
+ *(op-1) = EOS;
+
+ /* Ask UNIX to change the cwd to newdir.
+ */
+ if (chdir (dirname) == ERR) {
+ *status = XERR;
+
+ } else if (dirname[0] == '/') {
+ /* Save pathname of directory.
+ */
+ strcpy (oscwd, dirname);
+ *status = XOK;
+
+ } else {
+ /* Concatenate subdir name to current directory pathname.
+ */
+ for (op=oscwd; *op; op++)
+ ;
+ if (*(op-1) != '/')
+ *op++ = '/';
+ for (ip=dirname; (*op++ = *ip++); )
+ ;
+ }
+
+ return (*status);
+}