revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / rexxsyslib / createargstring.c
blob350804d0764c24c0f461402c2c26bc21292dec01
1 /*
2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include "rexxsyslib_intern.h"
11 /*****************************************************************************
13 NAME */
14 #include <clib/rexxsyslib_protos.h>
16 AROS_LH2(UBYTE *, CreateArgstring,
18 /* SYNOPSIS */
19 AROS_LHA(CONST UBYTE *, string, A0),
20 AROS_LHA(ULONG , length, D0),
22 /* LOCATION */
23 struct RxsLib *, RexxSysBase, 21, RexxSys)
25 /* FUNCTION
26 This function will create a RexxArg structure and copy the supplied
27 string into it.
29 INPUTS
30 string - String to copy into the RexxArg structure
31 length - Length of the string to copy.
33 RESULT
34 A pointer to the string part of the allocated RexxArg structure.
36 NOTES
37 Pointer to the string returned by this function may be used as a
38 null terminated C string but should be considered read-only.
40 EXAMPLE
42 BUGS
44 SEE ALSO
45 DeleteArgstring(), LengthArgstring()
47 INTERNALS
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
54 /* size is the length of the memory to allocate: size of RexxArg without Buff + length of string + 1 */
55 ULONG size = sizeof(struct RexxArg) - 8 + length + 1;
56 struct RexxArg *ra = (struct RexxArg *)AllocMem(size, MEMF_PUBLIC|MEMF_CLEAR);
57 ULONG hash = 0;
58 int i;
60 if (ra == NULL) ReturnPtr("CreateArgstring", UBYTE *, NULL);
62 ra->ra_Size = size;
63 ra->ra_Length = length;
64 /* FIXME: Maybe the next two fields only need to be intialized on m68k? */
65 /* Initialize the deprecated fields to a sane value for compatibility under AmigaOS */
66 ra->ra_Deprecated1 = 1<<1 | 1<<2 | 1<<6; /* Was ra_Flags = NSF_ALPHA | NSF_EXT */
67 for (i=0; i<length; i++)
68 hash += string[i];
69 ra->ra_Deprecated2 = (UBYTE)(hash & 255); /* Was ra_Hash */
70 CopyMem(string, ra->ra_Buff, length);
71 *(ra->ra_Buff + length) = '\0';
73 ReturnPtr("CreateArgString", UBYTE *, ra->ra_Buff);
74 AROS_LIBFUNC_EXIT
75 } /* CreateArgstring */