aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/getlline.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/getlline.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/fio/getlline.x')
-rw-r--r--sys/fio/getlline.x42
1 files changed, 42 insertions, 0 deletions
diff --git a/sys/fio/getlline.x b/sys/fio/getlline.x
new file mode 100644
index 00000000..e8e25d77
--- /dev/null
+++ b/sys/fio/getlline.x
@@ -0,0 +1,42 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+# GETLLINE -- Get a logical line of text, i.e., an arbitrarily long line
+# possibly broken up into multiple segments of size SZ_LINE. Accumulation
+# stops when the indicated number of chars have been read, or newline is
+# detected. MAXCH must be at least SZ_LINE characters greater than the
+# longest line to be read.
+
+int procedure getlline (fd, obuf, maxch)
+
+int fd #I input file
+char obuf[ARB] #O output buffer
+int maxch #I max chars out, >= SZ_LINE
+
+int op, status
+int getline()
+errchk getline
+
+begin
+ op = 1
+
+ while (maxch - op + 1 >= SZ_LINE) {
+ # Get next physical line from the file.
+ status = getline (fd, obuf[op])
+ if (status == EOF) {
+ if (op == 1)
+ return (EOF)
+ else
+ return (op - 1)
+ } else
+ op = op + status
+
+ # If the last physical line read ends in a newline we are done.
+ # If no newline we get another line, thereby reconstructing long
+ # lines broken by the SZ_LINE limit of getline().
+
+ if (obuf[op-1] == '\n')
+ break
+ }
+
+ return (op - 1)
+end