git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] mmap error handling

From
Linus Torvalds <torvalds@osdl.org>
Date
Jul 29, 2005, 00:30 UTC
Message-ID
<Pine.LNX.4.58.0507281725440.3307@g5.osdl.org>
In-Reply-To
<118833cc05072816294f80a829@mail.gmail.com>
On Thu, 28 Jul 2005, Morten Welinder wrote:
Show 9 quoted lines
>
> > I have verified that successful close() after failed mmap() won't reset
> > the output of perror() to "Success".
> 
> Does $standard guarantee that?
> 
> In general, successful libc calls can set errno to whatever they
> please, except zero.  And they sometimes do.  This follows from
> C99.
Indeed. 

_always_ save the value of errno before doing any other calls. Even successful calls are perfectly allowed to change errno.

"close()" may not _normally_ change errno, but the fact is, not only can close sometimes return an error, but it could validly have some debugging wrapper that does logging, and change errno because of that.

Yeah, we'd be better off if UNIX had always used the linux kernel practice of hiding errno as a negative return value (and the "IS_ERR()" test for pointers), but hey, crud happens to the best of us.

		Linus
Previous: Morten WelinderNext: Pavel Roskin
Message 3 of 4 in “mmap error handling”
  1. mmap error handlingPavel Roskin, Jul 28, 2005
  2. Morten WelinderJul 28, 2005
  3. Linus TorvaldsJul 29, 2005
  4. Pavel RoskinJul 29, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.