On Thu, May 04, 2006 at 08:30:53PM +0200, Michael Kerrisk wrote:
> Justin,
> 
> > > To your patch:
> > > 
> > > >  fopen, fdopen, freopen \- stream open functions
> > > 
> > > Did you check whether you text is true of all three of these 
> > > functions?
> > Yup, I just checked.
> > 
> > > > +.TP
> > > > +.B m
> > > > +Attempts to access the file using \fBmmap()\fP rather than
> > > > +\fBread()\fP and \fBwrite()\fP.
> > > 
> > > How did you deduce "write()"?  My reading is that mmap() is only used
> > > if the file is opened for reading.
> > This seems to be true, as indicated in the comments.  I hadn't
> > followed the code well enough to be sure, though, and it is slightly
> > strange that it defers the mmap decision until the first read..
> > 
> > I just wrote a test case for "r+m", which seems to indicate that you
> > are correct; an "r+m" file is read() not mmaped.
> 
> Have you written a test program that verifies (presumably via
> monitoring via 'strace') how 'm' changes the behaviour of stdio
> with respect to the use of mmap()?
Erm, yes, thats what I'm talking about (and is strace exactly what I
did).  But I'm not sure if I understand you .. I verified that all 3
routines mmap() a file if "m" is given (and it is read-only), and do
not mmap() it if "m" is not given (or if it is not read-only).

I include now the test program :)

Justin

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <error.h>

int main()
{
#define PATHNAME        "/tmp/fp.c"

        char buf[1<<10];
        int fd;
        FILE *fp;
        // if (-1==(fd=open(PATHNAME, O_RDONLY))) {
        //      error(EXIT_FAILURE, errno, "open");
        // } 
        
        if (NULL==(fp=fopen(PATHNAME, "r+m"))) {
                error(EXIT_FAILURE, errno, "fdopen");
        }

        fread(buf, 1, sizeof(buf), fp);

        exit(EXIT_SUCCESS);
}


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to