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 /sys/fio/close.x | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/fio/close.x')
-rw-r--r-- | sys/fio/close.x | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/sys/fio/close.x b/sys/fio/close.x new file mode 100644 index 00000000..622557c5 --- /dev/null +++ b/sys/fio/close.x @@ -0,0 +1,70 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <syserr.h> +include <config.h> +include <fio.h> + +# CLOSE -- Close a file, after possibly flushing the output buffer, and +# returning the file buffer (if any) and file descriptor. + +procedure close (fd_arg) + +int fd_arg, fd +int status +errchk flush, mfree, frtnfd +include <fio.com> + +begin + fp = fiodes[fd_arg] + if (fp == NULL) + return + else + call fcanpb (fd_arg) # cancel any pushback + + if (redir_fd[fd_arg] > 0) { + # If the stream was redirected locally onto a new file by FREDIR, + # swap streams back to their original order and close the redir + # file. + + fd = redir_fd[fd_arg] + call flush (fd_arg) + call fswapfd (fd, fd_arg) + redir_fd[fd_arg] = 0 + } else + fd = fd_arg + + switch (fd) { + case STDIN, CLIN: + return + case STDOUT, STDERR, CLOUT, STDGRAPH, STDIMAGE, STDPLOT: + call flush (fd) + + default: + call flush (fd) + status = OK + + switch (FTYPE(fp)) { + case TEXT_FILE: + call zcall2 (ZCLSTX(fp), FCHAN(fp), status) + call frtnfd (fd) + case STRING_FILE: + call strclose (fd) + case SPOOL_FILE: + call frtnfd (fd) + + default: + FREFCNT(fp) = FREFCNT(fp) - 1 + if (FREFCNT(fp) <= 0) { + if (FCHAN(fp) != ERR) + call zcall2 (ZCLSBF(fp), FCHAN(fp), status) + + if (FCD(fp) != FLCD(fp)) # separate chandes? + call mfree (FCD(fp), TY_STRUCT) + } + call frtnfd (fd) + } + + if (status == ERR) + call filerr (FNAME(fp), SYS_FCLOSE) + } +end |