home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / exec / allocentry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  3.1 KB  |  128 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: allocentry.c,v 1.6 1996/10/24 15:50:43 aros Exp $
  4.     $Log: allocentry.c,v $
  5.     Revision 1.6  1996/10/24 15:50:43  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.5  1996/09/13 17:51:22  digulla
  9.     Use IPTR
  10.  
  11.     Revision 1.4  1996/08/13 13:55:57  digulla
  12.     Replaced AROS_LA by AROS_LHA
  13.     Replaced some AROS_LH*I by AROS_LH*
  14.     Sorted and added includes
  15.  
  16.     Revision 1.3  1996/08/01 17:41:04  digulla
  17.     Added standard header for all files
  18.  
  19.     Desc:
  20.     Lang:
  21. */
  22. #include "exec_intern.h"
  23. #include <aros/libcall.h>
  24.  
  25. /*****************************************************************************
  26.  
  27.     NAME */
  28.     #include <exec/memory.h>
  29.     #include <clib/exec_protos.h>
  30.  
  31. AROS_LH1(struct MemList *, AllocEntry,
  32.  
  33. /*  SYNOPSIS */
  34.     AROS_LHA(struct MemList *, entry, A0),
  35.  
  36. /*  LOCATION */
  37.     struct ExecBase *, SysBase, 37, Exec)
  38.  
  39. /*  FUNCTION
  40.     Allocate a number of memory blocks through a MemList structure.
  41.  
  42.     INPUTS
  43.     entry - The MemList with one MemEntry for each block you want to get
  44.  
  45.     RESULT
  46.     The allocation was successful if the most significant bit of the
  47.     result is 0. The result then contains a pointer to a copy of
  48.     the MemList structure with the me_Addr fields filled.
  49.     If the most significant bit is set the result contains the type of
  50.     memory that couldn't be allocated.
  51.  
  52.     NOTES
  53.  
  54.     EXAMPLE
  55.  
  56.     BUGS
  57.  
  58.     SEE ALSO
  59.     FreeEntry()
  60.  
  61.     INTERNALS
  62.  
  63.     HISTORY
  64.     18-10-95    created by m. fleischer
  65.  
  66. ******************************************************************************/
  67. {
  68.     AROS_LIBFUNC_INIT
  69.  
  70.     struct MemList *ret;
  71.     ULONG mlsize,i;
  72.  
  73.     /* Calculate size of a MemList with ml_NumEntries MemEntries. */
  74.     mlsize=sizeof(struct MemList)-sizeof(struct MemEntry)+
  75.        sizeof(struct MemEntry)*entry->ml_NumEntries;
  76.  
  77.     /* Get the MemList structure */
  78.     ret=(struct MemList *)AllocMem(mlsize,MEMF_PUBLIC);
  79.  
  80.     /* Check nasty case where the returncode is misleading :-( */
  81.     if((IPTR)ret&0x80ul<<(sizeof(APTR)-1)*8)
  82.     {
  83.     FreeMem(ret,mlsize);
  84.     ret=NULL;
  85.     }
  86.  
  87.     /* The allocation failed? Return "no public memory" */
  88.     if(ret==NULL)
  89.     return (struct MemList *)(MEMF_PUBLIC|0x80ul<<(sizeof(APTR)-1)*8);
  90.  
  91.     /* Init new struct */
  92.     ret->ml_NumEntries=entry->ml_NumEntries;
  93.     ret->ml_Node.ln_Type=0;
  94.     ret->ml_Node.ln_Pri =0;
  95.     ret->ml_Node.ln_Name=NULL;
  96.  
  97.     /* Fill all entries */
  98.     for(i=0;i<entry->ml_NumEntries;i++)
  99.     {
  100.     /* Get one */
  101.     ret->ml_ME[i].me_Addr=AllocMem(entry->ml_ME[i].me_Length,
  102.                        entry->ml_ME[i].me_Reqs);
  103.     /* Got it? */
  104.     if(ret->ml_ME[i].me_Addr==NULL)
  105.     {
  106.         /* No. Set returncode to "none of the 'ml_ME[i].me_Reqs' memory". */
  107.         entry=(struct MemList *)
  108.           ((IPTR)entry->ml_ME[i].me_Reqs|0x80ul<<(sizeof(APTR)-1)*8);
  109.  
  110.         /* Free everything allocated until now... */
  111.         for(;i-->0;)
  112.         FreeMem(ret->ml_ME[i].me_Addr,ret->ml_ME[i].me_Length);
  113.  
  114.         /* ...including the MemList */
  115.         FreeMem(ret,mlsize);
  116.  
  117.         /* All done */
  118.         return entry;
  119.     }
  120.     /* Copy the Length field */
  121.     ret->ml_ME[i].me_Length=entry->ml_ME[i].me_Length;
  122.     }
  123.     /* Everything filled. Return OK. */
  124.     return ret;
  125.     AROS_LIBFUNC_EXIT
  126. } /* AllocEntry */
  127.  
  128.