Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add new function : xbt_dict_is_empty
[simgrid.git] / src / xbt / mmalloc / mmap-sup.c
index e485126..4388ff9 100644 (file)
@@ -1,26 +1,17 @@
 /* Support for an sbrk-like function that uses mmap.
    Copyright 1992, 2000 Free Software Foundation, Inc.
 
-   Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com
+   Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com */
 
-This file is part of the GNU C Library.
+/* Copyright (c) 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
 
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
-
-#if defined(HAVE_MMAP)
+#ifndef MAP_ANONYMOUS
+       #define MAP_ANONYMOUS MAP_ANON
+#endif
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>    /* Prototypes for lseek */
@@ -51,7 +42,7 @@ extern int getpagesize (void);
 /* Return MAP_PRIVATE if MDP represents /dev/zero.  Otherwise, return
    MAP_SHARED.  */
 
-#define MAP_PRIVATE_OR_SHARED(MDP) ((MDP -> flags & MMALLOC_DEVZERO) \
+#define MAP_PRIVATE_OR_SHARED(MDP) (( MDP -> flags & MMALLOC_ANONYMOUS) \
                                     ? MAP_PRIVATE \
                                     : MAP_SHARED)
 
@@ -73,6 +64,7 @@ extern int getpagesize (void);
 void*
 __mmalloc_mmap_morecore (struct mdesc *mdp, int size)
 {
+  ssize_t test = 0;
   void* result = NULL;
   off_t foffset;       /* File offset at which new mapping will start */
   size_t mapbytes;     /* Number of bytes to map */
@@ -125,7 +117,7 @@ __mmalloc_mmap_morecore (struct mdesc *mdp, int size)
       if( mdp -> fd > 0){
          /* FIXME:  Test results of lseek() and write() */
         lseek (mdp -> fd, foffset + mapbytes - 1, SEEK_SET);
-             write (mdp -> fd, &buf, 1);
+        test = write (mdp -> fd, &buf, 1);
       }
            
            /* Let's call mmap. Note that it is possible that mdp->top
@@ -203,7 +195,7 @@ mmalloc_findbase (int size)
         to signal an error return, and besides, it is useful to
         catch NULL pointers if it is unmapped.  Instead start
         at the next page boundary. */
-      base = (void*) getpagesize ();
+      base = (void*)(long) getpagesize ();
     }
   else if (base == (void*) -1)
     {
@@ -211,4 +203,3 @@ mmalloc_findbase (int size)
     }
   return ((void*) base);
 }
-#endif /* defined(HAVE_MMAP) */