From 0abce0065f60c8a4d1f445196105a2483ecbc2ef Mon Sep 17 00:00:00 2001 From: Harout Hedeshian Date: Wed, 22 Jul 2015 14:53:41 -0600 Subject: datatop: switch to PRId64/PRIu64 instead of %llu/%lld Replaced lld and llu with PRId64/PRIu64 to allow cross-platform printing of 64-bit integers with printf. Also set C standard to C99 in order for these macros to compile cleanly. Change-Id: I0e39c41f931c92d3e554c2256fdb9d3bcef6d9b9 --- datatop/src/Android.mk | 2 +- datatop/src/datatop_helpers.c | 33 +++++++++------------------------ datatop/src/datatop_meminfo_file_poll.c | 4 +++- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/datatop/src/Android.mk b/datatop/src/Android.mk index 51d062a..6b93c9f 100644 --- a/datatop/src/Android.mk +++ b/datatop/src/Android.mk @@ -18,7 +18,7 @@ LOCAL_SRC_FILES += datatop_str.c LOCAL_SRC_FILES += datatop_sys_snap.c LOCAL_SRC_FILES += datatop_value_only_poll.c -LOCAL_CFLAGS := -Wall -Wextra -Werror -pedantic +LOCAL_CFLAGS := -Wall -Wextra -Werror -pedantic -std=c99 LOCAL_CFLAGS += -DVERSION="\"1.0.4"\" LOCAL_CFLAGS += -DHAVE_STRL_FUNCTIONS LOCAL_CFLAGS += -D _BSD_SOURCE diff --git a/datatop/src/datatop_helpers.c b/datatop/src/datatop_helpers.c index 55fbb09..325b824 100644 --- a/datatop/src/datatop_helpers.c +++ b/datatop/src/datatop_helpers.c @@ -38,6 +38,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include #include @@ -84,11 +85,11 @@ static int dtop_format_dp_values(struct dtop_data_point *dp, FILE *fw) { switch (dp->type) { case DTOP_ULONG: - if (fprintf(fw, "%lu", dp->data.d_ulong) < 0) + if (fprintf(fw, "%"PRIu64, dp->data.d_ulong) < 0) return FILE_ERROR; break; case DTOP_LONG: - if (fprintf(fw, "%ld", dp->data.d_long) < 0) + if (fprintf(fw, "%"PRId64, dp->data.d_long) < 0) return FILE_ERROR; break; case DTOP_UINT: @@ -191,11 +192,7 @@ static void dtop_handle_dp_type_for_snapshot( - (int64_t)dp.initial_data.d_ulong; if (int64 != 0) { dtop_format_text_for_snapshot(dpset, dp); - #if (__SIZEOF_LONG__ == 4) - printf("%lld\n", int64); - #elif (__SIZEOF_LONG__ == 8) - printf("%ld\n", int64); - #endif + printf("%"PRId64"\n", int64); } break; @@ -205,11 +202,7 @@ static void dtop_handle_dp_type_for_snapshot( - (int64_t)dp.initial_data.d_long; if (int64 != 0) { dtop_format_text_for_snapshot(dpset, dp); - #if (__SIZEOF_LONG__ == 4) - printf("%lld\n", int64); - #elif (__SIZEOF_LONG__ == 8) - printf("%ld\n", int64); - #endif + printf("%"PRId64"\n", int64); } break; @@ -218,11 +211,7 @@ static void dtop_handle_dp_type_for_snapshot( - (int64_t)dp.initial_data.d_uint; if (int64 != 0) { dtop_format_text_for_snapshot(dpset, dp); - #if (__SIZEOF_LONG__ == 4) - printf("%lld\n", int64); - #elif (__SIZEOF_LONG__ == 8) - printf("%ld\n", int64); - #endif + printf("%"PRId64"\n", int64); } break; @@ -231,11 +220,7 @@ static void dtop_handle_dp_type_for_snapshot( - (int64_t)dp.initial_data.d_int; if (int64 != 0) { dtop_format_text_for_snapshot(dpset, dp); - #if (__SIZEOF_LONG__ == 4) - printf("%lld\n", int64); - #elif (__SIZEOF_LONG__ == 8) - printf("%ld\n", int64); - #endif + printf("%"PRId64"\n", int64); } break; } @@ -332,14 +317,14 @@ void dtop_store_dp(struct dtop_data_point *dp, const char *str) { switch (dp->type) { case DTOP_ULONG: - sscanf(str, "%lu", &(dp->data.d_ulong)); + sscanf(str, "%"PRIu64, &(dp->data.d_ulong)); if (dp->initial_data_populated == NOT_POPULATED) { dp->initial_data.d_ulong = dp->data.d_ulong; dp->initial_data_populated = POPULATED; } break; case DTOP_LONG: - sscanf(str, "%ld", &(dp->data.d_long)); + sscanf(str, "%"PRId64, &(dp->data.d_long)); if (dp->initial_data_populated == NOT_POPULATED) { dp->initial_data.d_long = dp->data.d_long; dp->initial_data_populated = POPULATED; diff --git a/datatop/src/datatop_meminfo_file_poll.c b/datatop/src/datatop_meminfo_file_poll.c index bef1c5d..078b825 100644 --- a/datatop/src/datatop_meminfo_file_poll.c +++ b/datatop/src/datatop_meminfo_file_poll.c @@ -36,8 +36,10 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include #include +#include #include "datatop_interface.h" #include "datatop_fileops.h" #include "datatop_str.h" @@ -142,7 +144,7 @@ int dtop_meminfo_poll(struct dtop_data_point_gatherer *dpg) for (j = 0; j < dpg->data_points_len; j++) { i = dt_find_dict_idx(dpg->data_points[j].name, &dict); if (i >= 0 && i < dict.max) { - sscanf(dict.val[i], "%lu", + sscanf(dict.val[i], "%" PRIu64, &(dpg->data_points[i].data.d_ulong)); dpg->data_points[i].data.d_ulong *= 1024; if (dpg->data_points[i]. -- cgit v1.2.3