aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/await.x
blob: 64deeb40371f56c5fc5e1a48655c22a803b072ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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