freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Devel] fall-back for mmap


From: jonathan . foster
Subject: Re: [Devel] fall-back for mmap
Date: Mon, 26 Jan 2004 13:29:28 +0000

Hi,

Masatake YAMATO <address@hidden> wrote:

+      if ( stream->size != read ( file, stream->base, stream->size ) )
+      {
+            FT_ERROR(( "FT_Stream_Open:" ));
+            FT_ERROR(( " could not `read' file `%s'\n", filepathname ));
+            goto Fail_Read;
+      }

Please don't do this!  This is not guaranteed to work - read()
may legally read less bytes than requested.  Perhaps it was
interrupted by a signal, or perhaps it's just a wierd (but legal)
filesystem driver.  The only safe way to call read() is in a loop.
If you read less than you requested, or if read() returns -1 and
sets errno to EINTR, then try again to read the rest of the file.

"man 2 read" (on a Linux system) says:
>RETURN VALUE
>       On success, the number of bytes  read  is  returned  (zero
>       indicates  end of file), and the file position is advanced
>       by this number.  It is not an  error  if  this  number  is
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>       smaller  than the number of bytes requested; this may hapĀ­
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>       pen for example because fewer bytes are actually available
>       right  now (maybe because we were close to end-of-file, or
>       because we are reading from a pipe, or from  a  terminal),
>       or  because read() was interrupted by a signal.  On error,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>       -1 is returned, and errno is set  appropriately.  In  this
>       case  it is left unspecified whether the file position (if
>       any) changes.
>
>ERRORS
>       EINTR  The call was interrupted by  a  signal  before  any
>              data was read.
>       [...]

Kind regards,

Jon Foster
--









reply via email to

[Prev in Thread] Current Thread [Next in Thread]