On Fri, May 11, 2012 at 08:04:12PM +0300, Konstantin Belousov wrote: > On Fri, May 11, 2012 at 06:54:32PM +0400, Andrey Chernov wrote: > > Thanks, but in this two places old errno value should be saved across > > free() because free() may damage it: > I do not agree. free() cannot change errno.
Perhaps I forget something, so please refer to standard stating that. IEEE Std 1003.1-2008 says that "No errors are defined." in the ERRORS section, but states that beforehand: "if the argument does not match a pointer earlier returned by a function in POSIX.1-2008 that allocates memory as if by malloc(), or if the space has been deallocated by a call to free() or realloc(), the behavior is undefined. Any use of a pointer that refers to freed space results in undefined behavior. ... The DESCRIPTION is updated to clarify that if the pointer returned is not by a function that allocates memory as if by malloc(), then the behavior is undefined." So that "undefined behavior" case still can modify errno. (Some internal syscalls (like munmap etc) could produce errno. In any case it is very implemetation defined.) -- http://ache.vniz.net/
pgpSABA7ajT4j.pgp
Description: PGP signature