From: Martin Str|mberg Message-Id: <200102112000.VAA19068@father.ludd.luth.se> Subject: Re: preserve errno in open patch In-Reply-To: <3A869A94.27606.A30709@localhost> from "Mark E." at "Feb 11, 2001 01:58:44 pm" To: djgpp-workers AT delorie DOT com Date: Sun, 11 Feb 2001 21:00:54 +0100 (MET) X-Mailer: ELM [version 2.4ME+ PL54 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk According to Mark E.: > Hi, > > This program prints out a "file not found" message even when fd != -1. > > #include > #include > #include > #include > > int main() > { > int fd; > > fd = open("file", O_RDWR | O_CREAT | O_TRUNC, S_IWUSR); > > if (errno) > perror("file"); > > close(fd); > > return 0; > } In general, it's wrong to look at errno unless you've got error indication from the system call. Hence the program works as expected. Right, MartinS