aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/await.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/fio/await.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/fio/await.x')
-rw-r--r--sys/fio/await.x56
1 files changed, 56 insertions, 0 deletions
diff --git a/sys/fio/await.x b/sys/fio/await.x
new file mode 100644
index 00000000..64deeb40
--- /dev/null
+++ b/sys/fio/await.x
@@ -0,0 +1,56 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <syserr.h>
+include <config.h>
+include <mach.h>
+include <fio.h>
+
+# AWAIT -- Wait for any pending i/o operations on a file to complete.
+# Must be called after an AREAD or AWRITE (to check for an i/o error
+# and for synchronization) or an abort will result.
+
+int procedure await (fd)
+
+int fd
+pointer bufp
+int nbytes, nchars, nfill, loc_Mem, zero, mode
+int awaitb()
+include <fio.com>
+
+data loc_Mem /0/, zero /0/
+errchk syserr
+
+begin
+ fp = fiodes[fd]
+ if (fd <= 0 || fp == NULL)
+ call syserr (SYS_FILENOTOPEN)
+
+ # Read the i/o mode before awaitb clears it.
+ mode = FFIOMODE(fp)
+
+ # Wait for i/o.
+ nbytes = awaitb (fd)
+ if (nbytes <= 0)
+ return (nbytes)
+
+ # Zero fill the last char of the output buffer if the last transfer was
+ # a read and the number of bytes read was not commensurate with the
+ # size of a char.
+
+ if (mode == READ_IN_PROGRESS && nbytes > 0) {
+ nchars = (nbytes + SZB_CHAR-1) / SZB_CHAR
+ nfill = nchars * SZB_CHAR - nbytes
+
+ if (nfill > 0) {
+ if (loc_Mem == 0)
+ call zlocva (Memc, loc_Mem)
+ bufp = FLOCBUF(fp) - loc_Mem + 1
+ call bytmov (zero, 1, Memc[bufp], nbytes + 1, nfill)
+ }
+ }
+
+ # On exit from AWAITB, fp.filstat contains the number of chars
+ # transferred in the last aread or awrite, or ERR.
+
+ return (FILSTAT(fp))
+end