changeset 31525:5b50ac5d207d

(mmap_enlarge): Don't return 0 if successful.
author Gerd Moellmann <gerd@gnu.org>
date Sun, 10 Sep 2000 11:17:26 +0000
parents 3935d834ff04
children b4573e2b2918
files src/ralloc.c
diffstat 1 files changed, 14 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/ralloc.c	Sun Sep 10 01:12:09 2000 +0000
+++ b/src/ralloc.c	Sun Sep 10 11:17:26 2000 +0000
@@ -1389,41 +1389,39 @@
 {
   char *region_end = (char *) r + r->nbytes_mapped;
   size_t nbytes;
-  int success = 1;
+  int success = 0;
 
   if (npages < 0)
     {
       /* Unmap pages at the end of the region.  */
       nbytes = - npages * page_size;
       if (munmap (region_end - nbytes, nbytes) == -1)
+	fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
+      else
 	{
-	  fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
-	  success = 0;
+	  r->nbytes_mapped -= nbytes;
+	  success = 1;
 	}
-      else
-	r->nbytes_mapped -= nbytes;
     }
   else if (npages > 0)
     {
+      struct mmap_region *r2;
+      
       nbytes = npages * page_size;
       
       /* Try to map additional pages at the end of the region.  We
 	 cannot do this if the address range is already occupied by
 	 something else because mmap deletes any previous mapping.
 	 I'm not sure this is worth doing, let's see.  */
-      if (mmap_find (region_end, region_end + nbytes))
-	success = 0;
-      else
+      r2 = mmap_find (region_end, region_end + nbytes);
+      if (r2 == NULL)
 	{
 	  POINTER_TYPE *p;
       
 	  p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE,
 		    MAP_ANON | MAP_PRIVATE | MAP_FIXED, mmap_fd, 0);
 	  if (p == MAP_FAILED)
-	    {
-	      fprintf (stderr, "mmap: %s\n", emacs_strerror (errno));
-	      success = 0;
-	    }
+	    fprintf (stderr, "mmap: %s\n", emacs_strerror (errno));
 	  else if (p != (POINTER_TYPE *) region_end)
 	    {
 	      /* Kernels are free to choose a different address.  In
@@ -1431,13 +1429,13 @@
 		 no use for it.  */
 	      if (munmap (p, nbytes) == -1)
 		fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
-	      success = 0;
 	    }
 	  else
-	    r->nbytes_mapped += nbytes;
+	    {
+	      r->nbytes_mapped += nbytes;
+	      success = 1;
+	    }
 	}
-      
-      success = 0;
     }
 
   return success;