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/oswrite.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 unix/boot/bootlib/oswrite.c (limited to 'unix/boot/bootlib/oswrite.c') diff --git a/unix/boot/bootlib/oswrite.c b/unix/boot/bootlib/oswrite.c new file mode 100644 index 00000000..3c59f8cd --- /dev/null +++ b/unix/boot/bootlib/oswrite.c @@ -0,0 +1,49 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#include +#include "bootlib.h" + +/* OS_WRITE -- Write to the output file. If the output file is a text file + * we must convert the binary input (text) stream to the record structured + * stream required by the host. + */ +int +os_write ( + int fd, /* output file */ + char *buf, /* data to be written */ + int nbytes /* num bytes to be written */ +) +{ + register char *ip; + register XCHAR *op, *otop; + register int ch, n; + XINT nchars, status, xfd=fd; + extern int ZPUTTX(); + + + if (osfiletype == BINARY_FILE) + return (write (fd, buf, nbytes)); + + n = nbytes; + ip = buf; + op = txop; + otop = &text[SZ_FBUF]; + + /* Accumulate an output line of text and pass it on to the system when + * newline is seen or when the output buffer fills (unlikely). + */ + while (--n >= 0) { + *op++ = ch = *ip++; + if (ch == '\n' || op >= otop) { + nchars = op - text; + ZPUTTX (&xfd, text, &nchars, &status); + op = txop = text; + if (status == XERR) + return (ERR); + } + } + + txop = op; + return (nbytes); +} -- cgit