diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index c14050654..23569a805 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,16 @@ +2001-10-15 Christopher Faylor + + * cygerrno.h (set_errno): Define more informative version of this + function for debugging. + (__set_errno): Declare when DEBUGGING. + * cygheap.h (cygheap_fdget::cygheap_fdget): Add a flag to control when + errno is set. + * debug.cc (__set_errno): New function. + * fcntl.cc (_fcntl): Fix so that correct fd is used for second argument + to dup2. + * syscalls.cc (_cygwin_istext_for_stdio): Don't set errno here when + using cygheap_fdget. + 2001-10-15 Christopher Faylor * fhandler.cc (fhandler_base::fork_fixup): Don't protect handle. diff --git a/winsup/cygwin/cygerrno.h b/winsup/cygwin/cygerrno.h index dd40819b9..ff4e90489 100644 --- a/winsup/cygwin/cygerrno.h +++ b/winsup/cygwin/cygerrno.h @@ -15,7 +15,12 @@ int __stdcall geterrno_from_win_error (DWORD code, int deferrno) __attribute__ ( #define __seterrno() seterrno (__FILE__, __LINE__) #define __seterrno_from_win_error(val) seterrno_from_win_error (__FILE__, __LINE__, val) +#ifndef DEBUGGING #define set_errno(val) (_impure_ptr->_errno = (val)) +#else +void __stdcall __set_errno (const char *ln, int ln, int val) __attribute ((regparm(3))); +#define set_errno(val) __set_errno (__PRETTY_FUNCTION__, __LINE__, (val)) +#endif #define get_errno() (_impure_ptr->_errno) extern "C" void __stdcall set_sig_errno (int e); diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index f018517fe..5fb4b8ecd 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -228,7 +228,7 @@ class cygheap_fdnew : public cygheap_fdmanip class cygheap_fdget : public cygheap_fdmanip { public: - cygheap_fdget (int fd, bool lockit = false) + cygheap_fdget (int fd, bool lockit = false, bool do_set_errno = true) { if (lockit) SetResourceLock (LOCK_FD_LIST, READ_LOCK, "cygheap_fdget"); @@ -241,7 +241,8 @@ class cygheap_fdget : public cygheap_fdmanip else { this->fd = -1; - set_errno (EBADF); + if (do_set_errno) + set_errno (EBADF + 1); if (lockit) ReleaseResourceLock (LOCK_FD_LIST, READ_LOCK, "cygheap_fdget"); locked = false; diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc index e8293b91f..6de0757ab 100644 --- a/winsup/cygwin/debug.cc +++ b/winsup/cygwin/debug.cc @@ -14,6 +14,7 @@ details. */ #include "perthread.h" #include "perprocess.h" #include "security.h" +#include "cygerrno.h" #undef CloseHandle @@ -348,4 +349,12 @@ close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force) #endif return ret; } + +/* Add a handle to the linked list of known handles. */ +void __stdcall +__set_errno (const char *func, int ln, int val) +{ + debug_printf ("%s:%d val %d", func, ln, val); + _impure_ptr->_errno = val; +} #endif /*DEBUGGING*/ diff --git a/winsup/cygwin/fcntl.cc b/winsup/cygwin/fcntl.cc index 17889ac98..95b622c04 100644 --- a/winsup/cygwin/fcntl.cc +++ b/winsup/cygwin/fcntl.cc @@ -41,13 +41,7 @@ _fcntl (int fd, int cmd,...) if (cmd != F_DUPFD) res = cfd->fcntl(cmd, arg); else - { - cygheap_fdnew newfd; - if (newfd >= 0) - res = dup2 (fd, newfd); - else - res = -1; - } + res = dup2 (fd, cygheap_fdnew (((int) arg) - 1)); va_end (args); done: diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index dd9336c93..3224de358 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1461,7 +1461,7 @@ _cygwin_istext_for_stdio (int fd) return 0; /* we do it for old apps, due to getc/putc macros */ } - cygheap_fdget cfd (fd); + cygheap_fdget cfd (fd, false, false); if (cfd < 0) { syscall_printf (" _cifs: fd not open\n");