aboutsummaryrefslogtreecommitdiff
path: root/sys/fmio/fmnextlf.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/fmio/fmnextlf.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/fmio/fmnextlf.x')
-rw-r--r--sys/fmio/fmnextlf.x48
1 files changed, 48 insertions, 0 deletions
diff --git a/sys/fmio/fmnextlf.x b/sys/fmio/fmnextlf.x
new file mode 100644
index 00000000..0747a799
--- /dev/null
+++ b/sys/fmio/fmnextlf.x
@@ -0,0 +1,48 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <syserr.h>
+include "fmio.h"
+
+# FM_NEXTLFILE -- Return the next available (empty) lfile. An error action
+# is taken if all lfiles are currently in use. Deleted lfiles will be reused
+# if no unused lfiles are found.
+
+int procedure fm_nextlfile (fm)
+
+pointer fm #I FMIO descriptor
+
+pointer ft, lf
+int nlfiles, flags, fn, i
+errchk syserrs, fmio_bind, fmio_errchk
+
+begin
+ call fmio_bind (fm)
+ call fmio_errchk (fm)
+
+ fn = FM_FTLASTNF(fm)
+ ft = FM_FTABLE(fm)
+ nlfiles = FM_NLFILES(fm)
+
+ # Travel once around the file table and abort if all entries are used.
+ # New files are normally returned in sequence. Deleted files can be
+ # reused.
+
+ do i = 1, nlfiles {
+ fn = fn + 1
+ if (fn > nlfiles)
+ fn = 1
+ lf = ft + fn * LEN_FTE
+ flags = LF_FLAGS(lf)
+ if (and(flags,LFF_ALLOCATED) == 0 || and(flags,LFF_DELETED) != 0)
+ break
+ }
+
+ if (i > nlfiles)
+ call syserrs (SYS_FMOOF, FM_DFNAME(fm))
+
+ FM_FTLASTNF(fm) = fn
+ FM_DHMODIFIED(fm) = YES
+ call fmio_tick (fm)
+
+ return (fn)
+end