]> git.mxchange.org Git - simgear.git/blob - simgear/metar/Antoi.cpp
Attempt to resolve ambiguity between #include <config.h> for simgear vs.
[simgear.git] / simgear / metar / Antoi.cpp
1 #pragma comment(compiler)
2 #pragma comment(date)
3 #pragma comment(timestamp)
4  
5 #include <stdlib.h>
6  
7 #pragma title("antoi - char array to integer")
8 #pragma pagesize (80)
9  
10 #pragma page(1)
11 /********************************************************************/
12 /*                                                                  */
13 /*  Title:         antoi                                            */
14 /*  Date:          Jan 28, 1991                                     */
15 /*  Organization:  W/OSO242 - Graphics and Display Section          */
16 /*  Programmer:    Allan Darling                                    */
17 /*  Language:      C/370                                            */
18 /*                                                                  */
19 /*  Abstract:      This function will convert a character array     */
20 /*                 (string) of length (len) into an integer.        */
21 /*                 The integer is created via a call to the         */
22 /*                 function atoi.  This function extends the        */
23 /*                 functionality of atoi by removing the            */
24 /*                 requirement for a sentinal delimited string      */
25 /*                 as input.                                        */
26 /*                                                                  */
27 /*  Input: - Pointer to an array of characters.                     */
28 /*         - Integer indicating the number of character to include  */
29 /*           in the conversion.                                     */
30 /*                                                                  */
31 /*  Output:- An integer corresponding to the value in the character */
32 /*           array or INT32_MIN (-2147483647-1) if the function is  */
33 /*           unable to acquire system storage.                      */
34 /*                                                                  */
35 /*  Modification History:                                           */
36 /*                 None                                             */
37 /*                                                                  */
38 /********************************************************************/
39
40 #ifdef HAVE_STDINT_H
41 #  include <stdint.h>
42 #endif
43
44 #ifndef INT32_MIN
45 #  define INT32_MIN (-2147483647-1)
46 #endif
47
48 int antoi(char * string, int len)
49 {
50  
51     /*******************/
52     /* local variables */
53     /*******************/
54  
55     char * tmpstr;
56     int i,
57         retval;
58  
59  
60     /*****************/
61     /* function body */
62     /*****************/
63  
64     tmpstr = (char *)malloc((len+1) * sizeof(char));
65  
66     if (tmpstr == NULL) return INT32_MIN;
67  
68     for (i = 0; i < len; i++)
69        tmpstr[i] = string[i];
70  
71     tmpstr[len] = '\0';
72  
73     retval = atoi(tmpstr);
74  
75     free(tmpstr);
76  
77     return(retval);
78  
79 } /* end antoi */
80  
81 #pragma page(1)