有一些/proc下面的文件用emacs没办法读取全部内容。emacs的策略是如果file stat size为0则只读一个READ_BUF_SIZE
大小的内容。但是用vim,cat,less都可以全部读出来。我把那几个的源码都稍微读了一下。它们都是会读到eof或者报错。
例如vim
/* vim/src/fileio.c:1124 */
while (!error && !got_int)
{
// ...
/* vim/src/fileio.c:1295 */
eof = size;
size = read_eintr(fd, ptr, size);
filesize_count += size;
// hit end of file
eof = (size < eof || filesize_count == filesize_disk);
以及cat
// src/cat.c
while (true)
{
/* Read a block of input. */
size_t n_read = safe_read (input_desc, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
{
error (0, errno, "%s", quotef (infile));
return false;
}
我往devel的邮件列表里发了邮件也没有人理我。emacs的这段代码可能是10到20年前的了。我也不知道问谁这么写的原因是不是有什么我没考虑到的因素。
/* emacs/src/fileio.c:4077 */
/* The file size returned from fstat may be zero, but data
may be readable nonetheless, for example when this is a
file in the /proc filesystem. */
if (end_offset == 0)
end_offset = READ_BUF_SIZE;
想问问 @oldosfan 大佬一般这种情况怎么搞。是修好了直接邮件发patch呢还是说要跟maintainer讨论一下怎么修?