El día martes, diciembre 22, 2020 a las 08:32:06p. m. +0100, Josef Wolf escribió:
> On Tue, Dec 22, 2020 at 04:58:53PM +0100, Matthias Apitz wrote: > > And what is this repeated asking with lseek(2) from line 22 to 89 in > > both cases with > > > > 22617 lseek(4, 0, SEEK_CUR) = 4096 > > > > always getting "yes, next byte to read is number 4096" I don't know where > > maildir files in mutt are handled. > > As I wrote in my prevous post, this are 68 invocations to lseek() and the mail > file contains 68 header lines. I guess those lseek() calls are somewhere deep > inside fgets() which mutt uses to read the header line-by-line. > > ... Why fgets(3) should do that? The first fgets(3) call will use a read(2) sys call to read (as shown in your strace's output) 4096 bytes and every fgets(3) call will return the bytes until a '\n'; and then the next line from its internal buffer, until this is exhausted. I wrote a small C pgm as: #include <stdio.h> int main() { FILE *fp; char str[4097]; fp = fopen("mail", "r"); while( fgets(str, 4096, fp) != NULL ) { printf("%s", str); } fclose(fp); return(0); } and if you run this with "truss -o tr ./a.out" (FreeBSD has currently no strace(1)), you will see exactly this: ... open("mail",O_RDONLY,0666) = 3 (0x3) fstat(3,{ mode=-rw------- ,inode=13942391,size=4539,blksize=32768 }) = 0 (0x0) read(3,"From mutt-users-boun...@mutt.org"...,32768) = 4539 (0x11bb) fstat(1,{ mode=crw--w---- ,inode=402,size=0,blksize=4096 }) = 0 (0x0) ioctl(1,TIOCGETA,0x7fffffffced0) = 0 (0x0) write(1,"From mutt-users-boun...@mutt.org"...,58) = 58 (0x3a) write(1,"Return-Path: <mutt-users-bounces"...,43) = 43 (0x2b) write(1,"Delivered-To: w51246_0-guru@mb-1"...,42) = 42 (0x2a) ... write(1,"j...@raven.inka.de\n",17) = 17 (0x11) write(1,"\n",1) = 1 (0x1) read(3,0x800a09180,32768) = 0 (0x0) close(3) = 0 (0x0) exit(0x0) i.e. no further lseek(2) sys calls. matthias -- Matthias Apitz, ✉ g...@unixarea.de, http://www.unixarea.de/ +49-176-38902045 Public GnuPG key: http://www.unixarea.de/key.pub Без книги нет знания, без знания нет коммунизма (Влaдимир Ильич Ленин) Without books no knowledge - without knowledge no communism (Vladimir Ilyich Lenin) Sin libros no hay saber - sin saber no hay comunismo. (Vladimir Ilich Lenin)