Tabs to spaces, more consistent formatting.
[AROS.git] / workbench / libs / iffparse / alloclocalitem.c
blob73a2ad92777568fcbf743fc7d47f20980ac51239
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "iffparse_intern.h"
8 /*****************************************************************************
10 NAME */
11 #include <proto/iffparse.h>
13 AROS_LH4(struct LocalContextItem *, AllocLocalItem,
15 /* SYNOPSIS */
16 AROS_LHA(LONG, type, D0),
17 AROS_LHA(LONG, id, D1),
18 AROS_LHA(LONG, ident, D2),
19 AROS_LHA(ULONG, dataSize, D3),
21 /* LOCATION */
22 struct Library *, IFFParseBase, 31, IFFParse)
24 /* FUNCTION
25 Allocates and initializes a LocalContextItem structure. It also allocates
26 dataSize user data. User data can be accesseed via LocalItemData function.
27 This is the only way to allocate such a item, since the item contains private
28 fields. Of course programmers should assume NOTHING about this private
29 fields.
32 INPUTS
33 type, id - Longword identifications values.
34 ident - Longword identifier for class of item.
35 dataSize - Size of a user data area that will be allocated by this funcyion.
37 RESULT
38 item - A initialized LocalContextItem structure.
40 NOTES
41 Changed dataSize parameter to ULONG, negative-sized memory allocations are undefined.
44 EXAMPLE
46 BUGS
47 See notes.
49 SEE ALSO
50 FreeLocalItem(), LocalItemData(), StoreLocalItem(), StoreItemInContext(),
51 SetLocalItemPurge()
53 INTERNALS
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
59 struct IntLocalContextItem *intlci;
61 DEBUG_ALLOCLOCALITEM(dprintf("AllocLocalItem: type 0x%lx %c%c%c%c id 0x%lx %c%c%c%c ident 0x%lx %c%c%c&%c\n",
62 type, dmkid(type), id, dmkid(id), ident, dmkid(ident)));
64 if (!(intlci = AllocMem(sizeof (struct IntLocalContextItem), MEMF_ANY|MEMF_CLEAR)))
66 DEBUG_ALLOCLOCALITEM(dprintf("AllocLocalItem: out of memory #1!\n"));
67 return (FALSE);
70 GetLCI(intlci)->lci_ID = id;
71 GetLCI(intlci)->lci_Type = type;
72 GetLCI(intlci)->lci_Ident = ident;
74 /* Only allocate user date if dataSize > 0 */
75 if (dataSize > 0)
77 if (!(intlci->lci_UserData = AllocMem(dataSize, MEMF_ANY|MEMF_CLEAR)))
79 FreeMem(intlci,sizeof (struct IntLocalContextItem));
80 DEBUG_ALLOCLOCALITEM(dprintf("AllocLocalItem: out of memory #2!\n"));
81 return (FALSE);
84 /* Remember to set UserDataSize field for use in FreeLocalItem */
85 intlci->lci_UserDataSize = dataSize;
87 else
89 /* If no dataSize, then we set then we do not have userdata */
90 intlci->lci_UserData = NULL;
94 DEBUG_ALLOCLOCALITEM(dprintf("AllocLocalItem: return %p\n", intlci));
95 return ((struct LocalContextItem*)intlci);
98 AROS_LIBFUNC_EXIT
99 } /* AllocLocalItem */