[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read() and ftell()

From: Apua Paquola
Subject: read() and ftell()
Date: 16 Sep 2002 22:31:10 -0000


In the program below, when I try to read the file with read() and get
the byte offset with ftell(), ftell always return 1024. When I
replace read() with fread(), ftell returns the correct values.

Is it really a bug? Or is it the expected behavior of ftell?

In a previous version of glibc (sorry, I can't remember the exact
version), this problem was not present.

It may be a kernel bug, no?

Best regards,

Apuã Paquola
Bioinformatics Group
Biochemistry Department, University of São Paulo


Pentium III
Debian unstable distribuition (updated Sep 16 2002).
Linux kernel: 2.4.19
libc6 (glibc) 2.2.5-14.2
Tested with gcc 2.95.4 and gcc 3.1.1

#include <unistd.h>
#include <stdio.h>

main(int argc, char** argv)
  int fd, q;
  FILE *f;
  char buf[1024];

  f=fopen(argv[1], "r");

  /*while(q=fread(buf, 1, 1024,f))*/
  while(q=read(fd, buf, 1024))
    printf("%d %d\n",q,ftell(f));

reply via email to

[Prev in Thread] Current Thread [Next in Thread]