Mail Archives: djgpp-workers/2012/03/07/12:49:18
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 -