aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/ffilsz.x
blob: 2a8a2926cd69090c51ce59121fa7cbc30bc17e50 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<mach.h>
include	<config.h>
include	<fio.h>

# FFILSZ -- Return file size in chars.  When first called, the status
# z-routine for the channel is called to get the file size.  Thereafter,
# FIO keeps track of the file size.

long procedure ffilsz (fd)

int	fd
long	file_size
include	<fio.com>

begin
	fp = fiodes[fd]
	UPDATE_IOP(fd)					# update i/o pointers

	switch  (FTYPE(fp)) {
	case TEXT_FILE:
	    call zcall3 (ZSTTTX(fp), FCHAN(fp), FSTT_FILSIZE, file_size)
	    file_size = file_size + (otop[fd] - bufptr[fd])

	case STRING_FILE, SPOOL_FILE:
	    file_size = otop[fd] - bufptr[fd]

	default:
	    # Call channel status z-routine to get file size if this is the
	    # first request.  Thereafter, FIO keeps track of file size.
	    # Beware that FILSIZE (updated by AWRITE or by us) does not
	    # necessarily include data just recently written into the current
	    # buffer.

	    if (FILSIZE(fp) < 0) {
		call zcall3 (ZSTTBF(fp), FCHAN(fp), FSTT_FILSIZE, file_size)
		file_size = (file_size + SZB_CHAR-1) / SZB_CHAR
	    } else
		file_size = FILSIZE(fp)

	    # If writing at EOF (or first block of a new file), and the file
	    # buffer has not yet been flushed, the file size is the buffer
	    # offset minus one (number of chars written to disk) plus the
	    # number of chars in the file buffer.

	    if (BUF_MODIFIED(fd))
		file_size = max (file_size,
		    boffset[fd]-1 + (itop[fd] - bufptr[fd]))
	}

	FILSIZE(fp) = file_size				# update fildes
	return (file_size)
end