diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /unix/os/zfchdr.c | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'unix/os/zfchdr.c')
-rw-r--r-- | unix/os/zfchdr.c | 57 |
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); +} |