Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 1
    I'd agree with the OP here that a tail -c anyvalue /dev/zero that doesn't loop forever is a bug as it's meant to output the end of an infinite stream. Commented Apr 17 at 4:01
  • 2
    In any case, if the data changes, it kinda hard to get consistent results whatever you do, so odd behaviour on something special like /dev/zero isn't too bad, which ever way it goes. Actually, I could argue that the fact that /dev/zero supports seeking from the end is already wrong, since conceptually it doesn't have an end. And if the OS provides functions that are wrong, it's not the fault of the utility. :) Commented Apr 17 at 8:45
  • 2
    What I'm actually wondering, is why they bothered to make different behaviour for the case of a page or less in the first place... It's not like the read()/write() calls really care about page size at all. ... oh, right, for cases like the "files" in proc which look like regular files but where the size is a complete lie. Except that the seek(fd, -N, SEEK_END); read(N) should still be as valid as it can be. Commented Apr 17 at 8:47
  • 1
    @StephenKitt, well, exactly, it doesn't give an error, i.e. it succeeds, so it seems "supported" and it's fair to assume it does something useful, right? Not that the position would matter at all for /dev/zero, and it looks to always return a new position of zero, but with SEEK_END, the caller can't really know what the position should be anyway. But it could just drop an ESPIPE, same as /dev/tty appears to do. Commented Apr 17 at 9:37
  • 1
    As you mention, files can grow (or even be truncated) while being read, so seeking to n bytes from the end of a file doesn’t guarantee that there are exactly n bytes left to read anyway. Considering /dev/zero specifically, it might as well be considered as an infinite tape (Turing style), where every value is always zero, so position is meaningless. Commented Apr 17 at 19:01