home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / allocentry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  3.4 KB  |  136 lines

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