if (flags & MAP_ANONYMOUS)
fd = -1;
- /* 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. */
- if (wincap.share_mmaps_only_by_name () && fd == -1 && (flags & MAP_FIXED)
- && ((DWORD)addr % granularity) && !off)
- off = (DWORD)addr % granularity;
- /* Map always in multipliers of `granularity'-sized chunks.
- Not necessary for anonymous maps on NT. */
- _off64_t gran_off = off;
- DWORD gran_len = len;
- if (wincap.share_mmaps_only_by_name () || fd != -1)
- {
- gran_off = off & ~(granularity - 1);
- gran_len = howmany (off + len, granularity) * granularity - gran_off;
- }
-
fhandler_base *fh;
+ /* Get fhandler and convert /dev/zero mapping to MAP_ANONYMOUS mapping. */
if (fd != -1)
{
/* Ensure that fd is open */
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)
- {
+ if (fh->get_device () == FH_ZERO)
+ {
/* mmap /dev/zero is like MAP_ANONYMOUS. */
fd = -1;
flags |= MAP_ANONYMOUS;
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. */
+ if (wincap.share_mmaps_only_by_name () && fd == -1 && (flags & MAP_FIXED)
+ && ((DWORD)addr % granularity) && !off)
+ off = (DWORD)addr % granularity;
+ /* Map always in multipliers of `granularity'-sized chunks.
+ Not necessary for anonymous maps on NT. */
+ _off64_t gran_off = off;
+ DWORD gran_len = len;
+ if (wincap.share_mmaps_only_by_name () || fd != -1)
+ {
+ gran_off = off & ~(granularity - 1);
+ gran_len = howmany (off + len, granularity) * granularity - gran_off;
+ }
+
+ /* File mappings needs some extra care. */
+ if (fd != -1 && 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;
+ }
+ /* 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;
/* copy-on-write doesn't work at all on 9x using anonymous maps.
Workaround: Anonymous mappings always use normal READ or WRITE
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;
{
if (!select || select (ent))
{
-
- /* Ignore error from readdir/select. See POSIX specs. */
- set_errno (0);
-
if (count == allocated)
{
ntmp = (struct dirent **) realloc (nl, allocated * sizeof *nl);
if (!ntmp)
{
- set_errno (ENOMEM);
+ err = ENOMEM;
break;
}
nl = ntmp;
if (!(etmp = (struct dirent *) malloc (sizeof *ent)))
{
- set_errno (ENOMEM);
+ err = ENOMEM;
break;
}
*etmp = *ent;
}
}
- if ((prior_errno = get_errno ()) != 0)
+ if (err != 0)
{
closedir (dirp);
if (nl)
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)
{
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;
}
{
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;
}
{
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;
}
{
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;
}