]> git.mxchange.org Git - simgear.git/blob - simgear/metar/Antoi.cpp
Fix various compiler warnings contributed by Norman Princeton.
[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_CONFIG_H
41 #  include <config.h>
42 #endif
43
44 #ifdef HAVE_STDINT_H
45 #  include <stdint.h>
46 #endif
47
48 #ifndef INT32_MIN
49 #  define INT32_MIN (-2147483647-1)
50 #endif
51
52 int antoi(char * string, int len)
53 {
54  
55     /*******************/
56     /* local variables */
57     /*******************/
58  
59     char * tmpstr;
60     int i,
61         retval;
62  
63  
64     /*****************/
65     /* function body */
66     /*****************/
67  
68     tmpstr = (char *)malloc((len+1) * sizeof(char));
69  
70     if (tmpstr == NULL) return INT32_MIN;
71  
72     for (i = 0; i < len; i++)
73        tmpstr[i] = string[i];
74  
75     tmpstr[len] = '\0';
76  
77     retval = atoi(tmpstr);
78  
79     free(tmpstr);
80  
81     return(retval);
82  
83 } /* end antoi */
84  
85 #pragma page(1)