* fhandler_clipboard.cc (fhandler_dev_clipboard::write): Never set

errno to 0.
	(fhandler_dev_clipboard::read): Ditto.
	* fhandler_windows.cc (fhandler_windows::read): Ditto.
	* scandir.cc (scandir): Ditto.
	* syscalls.cc (_fstat64_r): Ditto.
	(_fstat_r): Ditto.
	(_stat64_r): Ditto.
	(_stat_r): Ditto.

	* mmap.cc (mmap64): Fix /dev/zero mapping.
This commit is contained in:
Corinna Vinschen 2005-03-01 11:51:29 +00:00
parent 93c60b6d6a
commit 4717214c20
7 changed files with 67 additions and 66 deletions

View File

@ -1,3 +1,17 @@
2005-03-01 Corinna Vinschen <corinna@vinschen.de>
* fhandler_clipboard.cc (fhandler_dev_clipboard::write): Never set
errno to 0.
(fhandler_dev_clipboard::read): Ditto.
* fhandler_windows.cc (fhandler_windows::read): Ditto.
* scandir.cc (scandir): Ditto.
* syscalls.cc (_fstat64_r): Ditto.
(_fstat_r): Ditto.
(_stat64_r): Ditto.
(_stat_r): Ditto.
* mmap.cc (mmap64): Fix /dev/zero mapping.
2005-02-28 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Declare new method

View File

@ -174,7 +174,6 @@ fhandler_dev_clipboard::write (const void *buf, size_t len)
pos = msize;
set_errno (0);
eof = false;
return len;
}
@ -205,7 +204,6 @@ fhandler_dev_clipboard::read (void *ptr, size_t& len)
#if 0
system_printf ("a non-accepted format! %d", format);
#endif
set_errno (0);
len = 0;
}
else
@ -238,7 +236,6 @@ fhandler_dev_clipboard::read (void *ptr, size_t& len)
GlobalUnlock (hglb);
}
CloseClipboard ();
set_errno (0);
len = ret;
}
}

View File

@ -95,8 +95,6 @@ fhandler_windows::read (void *buf, size_t& len)
if ((ssize_t) len == -1)
__seterrno ();
else
set_errno (0);
return;
}

View File

@ -538,6 +538,33 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
if (flags & MAP_ANONYMOUS)
fd = -1;
fhandler_base *fh;
/* Get fhandler and convert /dev/zero mapping to MAP_ANONYMOUS mapping. */
if (fd != -1)
{
/* Ensure that fd is open */
cygheap_fdget cfd (fd);
if (cfd < 0)
{
syscall_printf ("-1 = mmap(): EBADF");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
return MAP_FAILED;
}
fh = cfd;
if (fh->get_device () == FH_ZERO)
{
/* mmap /dev/zero is like MAP_ANONYMOUS. */
fd = -1;
flags |= MAP_ANONYMOUS;
}
}
if (fd == -1)
{
fh_paging_file.set_io_handle (INVALID_HANDLE_VALUE);
fh = &fh_paging_file;
}
/* 9x only: If MAP_FIXED is requested on a non-granularity boundary,
change request so that this looks like a request with offset
addr % granularity. */
@ -554,49 +581,27 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, _off64_t off)
gran_len = howmany (off + len, granularity) * granularity - gran_off;
}
fhandler_base *fh;
if (fd != -1)
/* File mappings needs some extra care. */
if (fd != -1 && fh->get_device () == FH_FS)
{
/* Ensure that fd is open */
cygheap_fdget cfd (fd);
if (cfd < 0)
DWORD high;
DWORD low = GetFileSize (fh->get_handle (), &high);
_off64_t fsiz = ((_off64_t)high << 32) + low;
/* Don't allow mappings beginning beyond EOF since Windows can't
handle that POSIX like. FIXME: Still looking for a good idea
to allow that nevertheless. */
if (gran_off >= fsiz)
{
syscall_printf ("-1 = mmap(): EBADF");
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK, "mmap");
set_errno (ENXIO);
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return MAP_FAILED;
}
fh = cfd;
if (fh->get_device () == FH_FS)
{
DWORD high;
DWORD low = GetFileSize (fh->get_handle (), &high);
_off64_t fsiz = ((_off64_t)high << 32) + low;
/* Don't allow mappings beginning beyond EOF since Windows can't
handle that POSIX like. FIXME: Still looking for a good idea
to allow that nevertheless. */
if (gran_off >= fsiz)
{
set_errno (ENXIO);
ReleaseResourceLock (LOCK_MMAP_LIST, READ_LOCK | WRITE_LOCK,
"mmap");
return MAP_FAILED;
}
fsiz -= gran_off;
if (gran_len > fsiz)
gran_len = fsiz;
}
else if (fh->get_device () == FH_ZERO)
{
/* mmap /dev/zero is like MAP_ANONYMOUS. */
fd = -1;
flags |= MAP_ANONYMOUS;
}
}
if (fd == -1)
{
fh_paging_file.set_io_handle (INVALID_HANDLE_VALUE);
fh = &fh_paging_file;
/* Don't map beyond EOF. Windows would change the file to the
new length otherwise, in contrast to POSIX. */
fsiz -= gran_off;
if (gran_len > fsiz)
gran_len = fsiz;
}
DWORD access = (prot & PROT_WRITE) ? FILE_MAP_WRITE : FILE_MAP_READ;

View File

@ -946,7 +946,6 @@ cygwin_gethostname (char *name, size_t len)
}
}
debug_printf ("name %s", name);
h_errno = 0;
return 0;
}
@ -996,7 +995,6 @@ cygwin_gethostbyname (const char *name)
else
{
debug_printf ("h_name %s", _my_tls.locals.hostent_buf->h_name);
h_errno = 0;
}
return _my_tls.locals.hostent_buf;
}
@ -1020,7 +1018,6 @@ cygwin_gethostbyaddr (const char *addr, int len, int type)
else
{
debug_printf ("h_name %s", _my_tls.locals.hostent_buf->h_name);
h_errno = 0;
}
return _my_tls.locals.hostent_buf;
}

View File

@ -31,12 +31,11 @@ scandir (const char *dir,
struct dirent *ent, *etmp, **nl = NULL, **ntmp;
int count = 0;
int allocated = 0;
int err = 0;
if (!(dirp = opendir (dir)))
return -1;
int prior_errno = get_errno ();
set_errno (0);
if (!compar)
compar = alphasort;
@ -44,10 +43,6 @@ scandir (const char *dir,
{
if (!select || select (ent))
{
/* Ignore error from readdir/select. See POSIX specs. */
set_errno (0);
if (count == allocated)
{
@ -59,7 +54,7 @@ scandir (const char *dir,
ntmp = (struct dirent **) realloc (nl, allocated * sizeof *nl);
if (!ntmp)
{
set_errno (ENOMEM);
err = ENOMEM;
break;
}
nl = ntmp;
@ -67,7 +62,7 @@ scandir (const char *dir,
if (!(etmp = (struct dirent *) malloc (sizeof *ent)))
{
set_errno (ENOMEM);
err = ENOMEM;
break;
}
*etmp = *ent;
@ -75,7 +70,7 @@ scandir (const char *dir,
}
}
if ((prior_errno = get_errno ()) != 0)
if (err != 0)
{
closedir (dirp);
if (nl)
@ -85,12 +80,11 @@ scandir (const char *dir,
free (nl);
}
/* Ignore errors from closedir() and what not else. */
set_errno (prior_errno);
set_errno (err);
return -1;
}
closedir (dirp);
set_errno (prior_errno);
qsort (nl, count, sizeof *nl, (int (*)(const void *, const void *)) compar);
if (namelist)

View File

@ -879,8 +879,7 @@ _fstat64_r (struct _reent *ptr, int fd, struct __stat64 *buf)
{
int ret;
set_errno (0);
if ((ret = fstat64 (fd, buf)) == -1 && get_errno () != 0)
if ((ret = fstat64 (fd, buf)) == -1)
ptr->_errno = get_errno ();
return ret;
}
@ -900,8 +899,7 @@ _fstat_r (struct _reent *ptr, int fd, struct __stat32 *buf)
{
int ret;
set_errno (0);
if ((ret = fstat (fd, buf)) == -1 && get_errno () != 0)
if ((ret = fstat (fd, buf)) == -1)
ptr->_errno = get_errno ();
return ret;
}
@ -1039,8 +1037,7 @@ _stat64_r (struct _reent *ptr, const char *name, struct __stat64 *buf)
{
int ret;
set_errno (0);
if ((ret = stat64 (name, buf)) == -1 && get_errno () != 0)
if ((ret = stat64 (name, buf)) == -1)
ptr->_errno = get_errno ();
return ret;
}
@ -1060,8 +1057,7 @@ _stat_r (struct _reent *ptr, const char *name, struct __stat32 *buf)
{
int ret;
set_errno (0);
if ((ret = stat (name, buf)) == -1 && get_errno () != 0)
if ((ret = stat (name, buf)) == -1)
ptr->_errno = get_errno ();
return ret;
}