mmemalign.c

Go to the documentation of this file.
00001 /* @(#)root/clib:$Id: mmemalign.c 20882 2007-11-19 11:31:26Z rdm $ */
00002 /* Author: */
00003 
00004 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
00005 This file is part of the GNU C Library.
00006 
00007 The GNU C Library is free software; you can redistribute it and/or
00008 modify it under the terms of the GNU Library General Public License as
00009 published by the Free Software Foundation; either version 2 of the
00010 License, or (at your option) any later version.
00011 
00012 The GNU C Library is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 Library General Public License for more details.
00016 
00017 You should have received a copy of the GNU Library General Public
00018 License along with the GNU C Library; see the file COPYING.LIB.  If
00019 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020 Boston, MA 02111-1307, USA.  */
00021 
00022 #include "mmprivate.h"
00023 
00024 PTR
00025 mmemalign (md, alignment, size)
00026   PTR md;
00027   size_t alignment;
00028   size_t size;
00029 {
00030   PTR result;
00031   unsigned long int adj;
00032   struct alignlist *l;
00033   struct mdesc *mdp;
00034 
00035   if ((result = mmalloc (md, size + alignment - 1)) != NULL)
00036     {
00037       adj = RESIDUAL (result, alignment);
00038       if (adj != 0)
00039         {
00040           mdp = MD_TO_MDP (md);
00041           for (l = mdp -> aligned_blocks; l != NULL; l = l -> next)
00042             {
00043               if (l -> aligned == NULL)
00044                 {
00045                   /* This slot is free.  Use it.  */
00046                   break;
00047                 }
00048             }
00049           if (l == NULL)
00050             {
00051               l = (struct alignlist *) mmalloc (md, sizeof (struct alignlist));
00052               if (l == NULL)
00053                 {
00054                   mfree (md, result);
00055                   return (NULL);
00056                 }
00057               l -> next = mdp -> aligned_blocks;
00058               mdp -> aligned_blocks = l;
00059             }
00060           l -> exact = result;
00061           result = l -> aligned = (char *) result + alignment - adj;
00062         }
00063     }
00064   return (result);
00065 }

Generated on Tue Jul 5 14:11:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1