date and time created 80/12/21 16:50:28 by wnj
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 22 Dec 1980 08:50:28 +0000 (00:50 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 22 Dec 1980 08:50:28 +0000 (00:50 -0800)
SCCS-vsn: lib/libc/stdio/ftell.c 4.1

usr/src/lib/libc/stdio/ftell.c [new file with mode: 0644]

diff --git a/usr/src/lib/libc/stdio/ftell.c b/usr/src/lib/libc/stdio/ftell.c
new file mode 100644 (file)
index 0000000..5907ece
--- /dev/null
@@ -0,0 +1,32 @@
+/* @(#)ftell.c 4.1 (Berkeley) %G% */
+/*
+ * Return file offset.
+ * Coordinates with buffering.
+ */
+
+#include       <stdio.h>
+long   lseek();
+
+
+long ftell(iop)
+FILE *iop;
+{
+       long tres;
+       register adjust;
+
+       if (iop->_cnt < 0)
+               iop->_cnt = 0;
+       if (iop->_flag&_IOREAD)
+               adjust = - iop->_cnt;
+       else if (iop->_flag&_IOWRT) {
+               adjust = 0;
+               if (iop->_base && (iop->_flag&_IONBF)==0)
+                       adjust = iop->_ptr - iop->_base;
+       } else
+               return(-1);
+       tres = lseek(fileno(iop), 0L, 1);
+       if (tres<0)
+               return(tres);
+       tres += adjust;
+       return(tres);
+}