This source file includes following definitions.
- opal_ltostr
- opal_dtostr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "opal_config.h"
20 #include "opal/util/numtostr.h"
21 #include "opal/util/printf.h"
22 #include <stdio.h>
23 #include <stdlib.h>
24
25
26 char*
27 opal_ltostr(long num)
28 {
29
30 int buflen = sizeof(long) * 8;
31 char *buf = NULL;
32 int ret = 0;
33
34 buf = (char*) malloc(sizeof(char) * buflen);
35 if (NULL == buf) return NULL;
36
37 ret = snprintf(buf, buflen, "%ld", num);
38 if (ret < 0) {
39 free(buf);
40 return NULL;
41 }
42
43 return buf;
44 }
45
46
47 char*
48 opal_dtostr(double num)
49 {
50
51 int buflen = sizeof(long) * 8;
52 char *buf = NULL;
53 int ret = 0;
54
55 buf = (char*) malloc(sizeof(char) * buflen);
56 if (NULL == buf) return NULL;
57
58 ret = snprintf(buf, buflen, "%f", num);
59 if (ret < 0) {
60 free(buf);
61 return NULL;
62 }
63
64 return buf;
65 }