Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: mapfile and proc filesystem, limitation or possible bug



On Tue 23 Jun 2026, at 01:15, Mikael Magnusson wrote:
> Files in /proc tend to have a reported size of 0 bytes

this is the immediate reason, but even if it weren't so (and it's not
for a few files), procfs would still need to actually support mmap()
operations, which afaict it and most other linux pseudo file systems
just don't do. e.g.

  >>> import mmap, os
  >>> os.path.getsize('/proc/cmdline')
  96
  >>> f = open('/proc/cmdline')
  >>> mmap.mmap(f.fileno(), 96)
  Traceback (most recent call last):
    File "<python-input-3>", line 1, in <module>
      mmap.mmap(f.fileno(), 96)
      ~~~~~~~~~^^^^^^^^^^^^^^^^
  PermissionError: [Errno 13] Permission denied

and it doesn't support seeking from SEEK_END at all, so even on those
non-zero files the zstuff() path presumably still doesn't work:

  >>> f.seek(0, 2)
  Traceback (most recent call last):
    File "<python-input-5>", line 1, in <module>
      f.seek(0, 2)
      ~~~~~~^^^^^^
  OSError: [Errno 22] Invalid argument

if we really wanted to we could probably work around this, e.g. have
get_contents() fall back to zstuff() when mmap() fails, and have
zstuff() use stat() when fseek() fails. (or have it use stat() to begin
with? is there ever a benefit to using fseek()+ftell()?)

dana




Messages sorted by: Reverse Date, Date, Thread, Author