Add ftell() clone to FD_t
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 15 Oct 2009 08:33:18 +0000 (11:33 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 15 Oct 2009 08:33:18 +0000 (11:33 +0300)
rpmio/rpmio.c
rpmio/rpmio.h

index 94747aa..1bc79da 100644 (file)
@@ -2052,6 +2052,21 @@ int Fflush(FD_t fd)
     return 0;
 }
 
+off_t Ftell(FD_t fd)
+{
+    FDIO_t iot;
+    off_t pos = -2; /* assume not implemented */
+
+    if (fd == NULL) return -1;
+    iot = fdGetIo(fd);
+    /* this wont work correctly for compressed types */
+    if (iot == fpio || iot == fdio || iot == ufdio) {
+       pos = lseek(Fileno(fd), 0, SEEK_CUR);
+    }
+
+    return pos;
+}
+
 int Ferror(FD_t fd)
 {
     int i, rc = 0;
index ca05d15..a313371 100644 (file)
@@ -65,6 +65,11 @@ ssize_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd);
 int Fseek(FD_t fd, _libio_off_t offset, int whence);
 
 /** \ingroup rpmio
+ * ftell(3) clone.
+ */
+off_t Ftell(FD_t fd);
+
+/** \ingroup rpmio
  * fclose(3) clone.
  */
 int Fclose( FD_t fd);