* cygtls.h (_local_storage::setmode_file): New element.

(_local_storage::setmode_mode): New element.
* tlsoffsets.h: Regenerate.
* cygwin.din (setmode): Define as cygwin_getmode.
* syscalls.cc (setmode_helper): Use setmode_* variables from tls rather than
using unthreadsafe static.
(setmode): Break out fwalk stuff.
(cygwin_setmode): New function.  Put fwalk stdio stuff here.
This commit is contained in:
Christopher Faylor
2005-06-09 22:33:57 +00:00
parent fa0dcd0d65
commit 9a91777205
6 changed files with 95 additions and 75 deletions

View File

@@ -1565,20 +1565,17 @@ _cygwin_istext_for_stdio (int fd)
/* internal newlib function */
extern "C" int _fwalk (struct _reent *ptr, int (*function) (FILE *));
static int setmode_mode;
static int setmode_file;
static int
setmode_helper (FILE *f)
{
if (fileno (f) != setmode_file)
if (fileno (f) != _my_tls.locals.setmode_file)
{
syscall_printf ("improbable, but %d != %d", fileno (f), setmode_file);
syscall_printf ("improbable, but %d != %d", fileno (f), _my_tls.locals.setmode_file);
return 0;
}
syscall_printf ("file was %s now %s", f->_flags & __SCLE ? "text" : "binary",
setmode_mode & O_TEXT ? "text" : "binary");
if (setmode_mode & O_TEXT)
_my_tls.locals.setmode_mode & O_TEXT ? "text" : "binary");
if (_my_tls.locals.setmode_mode & O_TEXT)
f->_flags |= __SCLE;
else
f->_flags &= ~__SCLE;
@@ -1628,18 +1625,27 @@ setmode (int fd, int mode)
else
cfd->set_flags ((cfd->get_flags () & ~(O_TEXT | O_BINARY)) | mode);
if (_cygwin_istext_for_stdio (fd))
setmode_mode = O_TEXT;
else
setmode_mode = O_BINARY;
setmode_file = fd;
_fwalk (_GLOBAL_REENT, setmode_helper);
syscall_printf ("(%d<%s>, %p) returning %s", fd, cfd->get_name (),
mode, res & O_TEXT ? "text" : "binary");
return res;
}
extern "C" int
cygwin_setmode (int fd, int mode)
{
int res = setmode (fd, mode);
if (res != -1)
{
_my_tls.locals.setmode_file = fd;
if (_cygwin_istext_for_stdio (fd))
_my_tls.locals.setmode_mode = O_TEXT;
else
_my_tls.locals.setmode_mode = O_BINARY;
_fwalk (_GLOBAL_REENT, setmode_helper);
}
return res;
}
extern "C" int
ftruncate64 (int fd, _off64_t length)
{