some fixes to accented characters
[tangerine.git] / rom / dos / strtolong.c
blobf2edad1d1a115ba494900aec2a11af89db39c2ad
1 /*
2 Copyright © 1995-2008, 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
50 LONG sign=0, v=0;
51 CONST_STRPTR s=string;
53 /* Skip leading whitespace characters */
54 while(*s==' '||*s=='\t')
55 s++;
57 /* Swallow sign */
58 if(*s=='+'||*s=='-')
59 sign=*s++;
61 /* If there is no number return an error. */
62 if(*s<'0'||*s>'9')
64 *value=0;
65 return -1;
68 /* Calculate result */
70 v=v*10+*s++-'0';
71 while(*s>='0'&&*s<='9');
73 /* Negative? */
74 if(sign=='-')
75 v=-v;
77 /* All done. */
78 *value=v;
79 return s-string;
80 AROS_LIBFUNC_EXIT
81 } /* StrToLong */