From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/fio/await.x | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sys/fio/await.x (limited to 'sys/fio/await.x') 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 +include +include +include + +# 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 + +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 -- cgit