Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / dos / strtolong.c
blob0e31236d817eba8f999340b98d1613356763b9c2
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Convert a string into a long
6 Lang: english
7 */
9 /*****************************************************************************
11 NAME */
12 #include <proto/dos.h>
14 AROS_LH2I(LONG, StrToLong,
16 /* SYNOPSIS */
17 AROS_LHA(CONST_STRPTR, string, D1),
18 AROS_LHA(LONG *, value, D2),
20 /* LOCATION */
21 struct DosLibrary *, DOSBase, 136, Dos)
23 /* FUNCTION
24 Convert a string to a long number.
26 INPUTS
27 string - The value to convert
28 value - The result is returned here
30 RESULT
31 How many characters in the string were considered when it was
32 converted or -1 if no valid number could be found.
34 NOTES
35 The routine doesn't check if the number if too large.
37 EXAMPLE
38 // Valid number are: 5, -1, +3, +0007, etc.
40 BUGS
42 SEE ALSO
44 INTERNALS
46 *****************************************************************************/
48 AROS_LIBFUNC_INIT
49 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
51 LONG sign=0, v=0;
52 CONST_STRPTR s=string;
54 /* Skip leading whitespace characters */
55 if(*s==' '||*s=='\t')
56 s++;
58 /* Swallow sign */
59 if(*s=='+'||*s=='-')
60 sign=*s++;
62 /* If there is no number return an error. */
63 if(*s<'0'||*s>'9')
65 *value=0;
66 return -1;
69 /* Calculate result */
71 v=v*10+*s++-'0';
72 while(*s>='0'&&*s<='9');
74 /* Negative? */
75 if(sign=='-')
76 v=-v;
78 /* All done. */
79 *value=v;
80 return s-string;
81 AROS_LIBFUNC_EXIT
82 } /* StrToLong */