aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/write.x
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /sys/fio/write.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/fio/write.x')
-rw-r--r--sys/fio/write.x40
1 files changed, 40 insertions, 0 deletions
diff --git a/sys/fio/write.x b/sys/fio/write.x
new file mode 100644
index 00000000..66241ff5
--- /dev/null
+++ b/sys/fio/write.x
@@ -0,0 +1,40 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <syserr.h>
+include <fio.h>
+
+# WRITE -- Write binary chars to a file. The specified number of chars will
+# always be written (with the file buffer being flushed as many times as
+# necessary) unless an error occurs.
+
+procedure write (fd, buffer, maxchars)
+
+int fd
+char buffer[ARB]
+int maxchars
+int nchars, chunk_size
+errchk flsbuf
+include <fio.com>
+
+begin
+ if (fd <= 0 || fiodes[fd] == NULL)
+ call syserr (SYS_FILENOTOPEN)
+
+ nchars = 0
+
+ while (nchars < maxchars) {
+ if (iop[fd] < bufptr[fd] || iop[fd] >= otop[fd])
+ call flsbuf (fd, maxchars - nchars)
+ chunk_size = min (maxchars - nchars, otop[fd] - iop[fd])
+ if (chunk_size <= 0)
+ break
+ else {
+ call amovc (buffer[nchars+1], Memc[iop[fd]], chunk_size)
+ iop[fd] = iop[fd] + chunk_size
+ nchars = nchars + chunk_size
+ }
+ }
+
+ FNCHARS(fiodes[fd]) = nchars
+end