From 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Tue, 11 Aug 2015 16:51:37 -0400 Subject: Repatch (from linux) of OSX IRAF --- unix/boot/bootlib/osfcopy.c | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 unix/boot/bootlib/osfcopy.c (limited to 'unix/boot/bootlib/osfcopy.c') diff --git a/unix/boot/bootlib/osfcopy.c b/unix/boot/bootlib/osfcopy.c new file mode 100644 index 00000000..037d6eff --- /dev/null +++ b/unix/boot/bootlib/osfcopy.c @@ -0,0 +1,84 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#include +#include +#include +#include +#include "bootlib.h" + +extern int os_access (char *fname, int mode, int type); + + +/* OS_FCOPY -- Copy a file. Used by RTAR to resolve links. + */ +int +os_fcopy ( + char *oldfile, + char *newfile +) +{ + XCHAR buf[SZ_FBUF]; + XINT status, junk, maxch = SZ_FBUF, mode = 0, in, out, n, nw; + + extern int ZOPNTX(), ZGETTX(), ZCLSTX(), ZPUTTX(); + + + if (os_access (oldfile,0,0) == NO) + return (ERR); + + if (os_access (oldfile, 0, TEXT_FILE) == YES) { + if (bdebug) + fprintf (stderr, "copy text file '%s' -> '%s'\n", + oldfile, newfile); + + mode = READ_ONLY; + ZOPNTX ((PKCHAR *)vfn2osfn(oldfile,0), &mode, &in); + if (in == XERR) + return (ERR); + + mode = NEW_FILE; + ZOPNTX ((PKCHAR *)vfn2osfn(newfile,1), &mode, &out); + if (out == XERR) { + ZCLSTX (&in, &status); + return (ERR); + } + + while (ZGETTX (&in, buf, &maxch, &n), n != XEOF) { + if (n != XERR) + ZPUTTX (&out, buf, &n, &status); + if (n == XERR || status == XERR) { + ZCLSTX (&in, &junk); + ZCLSTX (&out, &junk); + return (ERR); + } + } + + ZCLSTX (&in, &status); + ZCLSTX (&out, &status); + + return (status); + + } else { + if (bdebug) + fprintf (stderr, "copy binary file `%s' -> `%s'\n", + oldfile, newfile); + + if ((in = open (vfn2osfn(oldfile,0), 0)) == ERR) + return (ERR); + if ((out = creat (vfn2osfn(newfile,1), 0644)) == ERR) { + close (in); + return (ERR); + } + + while ((n = read (in, (char *)buf, SZ_FBUF)) > 0) + nw = write (out, (char *)buf, n); + + close (in); + close (out); + if (n < 0) + return (ERR); + } + + return (ERR); +} -- cgit