delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2012/03/07/12:49:18

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
X-Authenticated: #27081556
X-Provags-ID: V01U2FsdGVkX1+i1OQMi/qi+In7YTqC4Iew9XuxCyDxGEz4v9SVM5
P3/xTlKaLEKf2s
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
To: djgpp-workers AT delorie DOT com
Subject: errno returned by open()
Date: Wed, 7 Mar 2012 18:45:09 +0100
User-Agent: KMail/1.9.10
MIME-Version: 1.0
Message-Id: <201203071845.09240.juan.guerrero@gmx.de>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

I have observed that the open() call sets errno = 4 when a file is created.
This errno or alternatively errno = 22 are set by previous calls to _open,
_creatnew and _creat.  That is OK as long as those calls fail but if those do
not fail then the last errno value is passed by open() to the calling function
as its errno.  I assume that this is a bug and not a feature.  I compared this
behaviour with the behaviour of the same test program compiled with cygwin.
The cygwin version of the program always returns errno = 0 if the file has
been successfuly created.

Regards,
Juan M. Guerrero


diff -aprNU5 djgpp.orig/src/libc/posix/fcntl/open.c djgpp/src/libc/posix/fcntl/open.c
--- djgpp.orig/src/libc/posix/fcntl/open.c	2003-11-21 22:54:56 +0000
+++ djgpp/src/libc/posix/fcntl/open.c	2012-03-07 00:18:54 +0000
@@ -1,5 +1,6 @@
+/* Copyright (C) 2012 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
@@ -266,10 +267,13 @@ open(const char* filename, int oflag, ..
   if ((fd == -1) && (access(real_name, D_OK) == 0))
     return opendir_as_fd(real_name, original_oflag);
 
   if (fd == -1)
     return fd;	/* errno already set by _open or _creat */
+  else
+    errno = 0;  /* at this stage reset errno set by
+                   previous calls to _open or _creat */
 
   if ((oflag & O_TRUNC) && !should_create)
 #ifndef TRUNC_CHECK
     _write(fd, 0, 0);
 #else

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019