0

For the purpose of tracing I/O calls, I have overwritten fwrite in a shared library that I LD_PRELOAD when running a program. In my version of fwrite, I get the absolute offset of the write using

long int pos = ftell(stream);

The value is then passed to a function that takes a size_t argument (so unsigned long), and the value is printed.

I encountered some calls with 18446744073709551615 as the offset (2^64 - 1), so I guess the initial long int returned by ftell was -1. These operations always wrote 10 bytes.

So my question is: what could have led the stream offset to be set to -1?

I don't trace the name of the files being accessed by those strange fwrites, so I don't know what is being accessed. Also I should precise that the program is an MPI program. It might be possible that the stream involved is actually a socket, or something else than a file...

4

1 回答 1

0

ftell 的 -1 返回值意味着设置了 errno。这是手册页中的重生文本:

ftell() 返回当前偏移量。否则,返回 -1 并设置 errno 以指示错误。

于 2014-03-06T16:10:53.577 回答