lua-users home
lua-l archive

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



On 16-Jan-06, at 6:45 AM, Roberto Ierusalimschy wrote:
* malloc: as far as I know, a correct malloc should not change errno.
An error in malloc generates a MEMERR, so errno is not used.

Sadly, that's not true.

  "The setting of errno after a successful call to a
   function is unspecified unless the description of
   that function specifies that errno shall not be
   modified."

POSIX malloc() does use errno, and it does not specify
that errno is preserved by a successful call. So it
might change. (And, in fact, I've observed this
behaviour from some mallocs which internally use
features like mmap().)

In general, the only safe way to use errno is to
save it immediately after a call to a function
which generates an error return.

I agree with ET: errno is an awful mechanism for error
reporting.