aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/flsbuf.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/flsbuf.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/fio/flsbuf.x')
-rw-r--r--sys/fio/flsbuf.x69
1 files changed, 69 insertions, 0 deletions
diff --git a/sys/fio/flsbuf.x b/sys/fio/flsbuf.x
new file mode 100644
index 00000000..6f651577
--- /dev/null
+++ b/sys/fio/flsbuf.x
@@ -0,0 +1,69 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <config.h>
+include <syserr.h>
+include <fio.h>
+
+# FLSBUF -- Flush the file buffer. Called by PUTC, PUTLINE, and WRITE
+# when the i/o pointer no longer points into the file buffer. Prior to
+# the first write to a buffer, the OTOP pointer will be set to the
+# beginning of the buffer. The first call to FLSBUF advances OTOP to the
+# end of the buffer. The next call to FLSBUF finds the buffer "dirty",
+# and flushes the buffer, leaving the buffer ready to be written into
+# (OTOP left pointing at the end of the buffer). A seek on a binary file
+# will usually leave the i/o pointer pointing outside the buffer, which
+# requires a call to FFAULT (file fault).
+
+procedure flsbuf (fd, nreserve)
+
+int fd, nreserve
+pointer bp
+bool iop_in_range
+int nchars_written, ffault(), and()
+errchk fmkbfs, syserr, filerr, ffault
+include <fio.com>
+
+begin
+ fp = fiodes[fd]
+ bp = bufptr[fd]
+
+ if (fd <= 0 || fp == NULL) # verification
+ call syserr (SYS_FILENOTOPEN)
+ else if (and (FF_WRITE, fflags[fd]) == 0) {
+ if (FTYPE(fp) == SPOOL_FILE) {
+ if (otop[fd] < buftop[fd])
+ otop[fd] = buftop[fd]
+ else
+ call fexbuf (fd)
+ return
+ } else
+ call filerr (FNAME(fp), SYS_FNOWRITEPERM)
+ }
+
+ iop_in_range = iop[fd] >= bufptr[fd] && iop[fd] < buftop[fd]
+
+ if (bp == NULL) { # no buffer yet
+ call fmkbfs (fd)
+ bp = bufptr[fd]
+ itop[fd] = bp
+ if (FTYPE(fp) == BINARY_FILE)
+ nchars_written = ffault (fd, LNOTE(fd), nreserve, FF_WRITE)
+ else
+ nchars_written = 0
+
+ } else if (iop_in_range && otop[fd] < buftop[fd]) {
+ nchars_written = 0 # buffer not full yet?
+
+ } else if (FTYPE(fp) == TEXT_FILE) { # text files
+ call fputtx (fd, Memc[bp], iop[fd] - bp, nchars_written)
+ iop[fd] = bp
+ itop[fd] = bp
+
+ } else # binary files
+ nchars_written = ffault (fd, LNOTE(fd), nreserve, FF_WRITE)
+
+ otop[fd] = buftop[fd] # make space available
+
+ if (nchars_written == ERR)
+ call filerr (FNAME(fp), SYS_FWRITE)
+end