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