Project

General

Profile

Actions

Bug #12415

closed

Dir#pos reports invalid position after Dir#read

Added by djberg96 (Daniel Berger) almost 8 years ago. Updated almost 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
[ruby-core:75685]

Description

irb(main):002:0> `ls`.split("\n")
=> ["bench", "berger_spec.gemspec", "lib", "Rakefile", "README", "SCORECARD", "test"]

irb(main):003:0> dir = Dir.new(Dir.pwd)
=> #<Dir:/home/dberger/Repositories/berger_spec>

irb(main):004:0> dir.pos
=> 0

irb(main):005:0> 5.times{ dir.read }
=> 5

irb(main):006:0> dir.pos
=> 3695892277965309219 # WUT

Updated by phasis68 (Heesob Park) almost 8 years ago

This is not a bug.
The return value of Dir#pos is just the return value of telldir().
The return values of telldir() are implementation-defined.

According to http://man7.org/linux/man-pages/man3/telldir.3.html

In glibc up to version 2.1.1, the return type of telldir() was off_t.
POSIX.1-2001 specifies long, and this is the type used since glibc
2.1.2.

In early filesystems, the value returned by telldir() was a simple
file offset within a directory.  Modern filesystems use tree or hash
structures, rather than flat tables, to represent directories.  On
such filesystems, the value returned by telldir() (and used
internally by readdir(3)) is a "cookie" that is used by the
implementation to derive a position within a directory.  Application
programs should treat this strictly as an opaque value, making no
assumptions about its contents.

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0