From d6edaa3bddd28e0cd013f7d228faaf249565e3c4 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 25 Nov 2024 16:01:49 +0900 Subject: [PATCH] Use proper format constants for size_t/uintX_t etc --- src/arg_parse.c | 2 +- src/main.c | 12 +++++++----- src/test.c | 6 +++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/arg_parse.c b/src/arg_parse.c index 2aeb9f4..30f19fa 100644 --- a/src/arg_parse.c +++ b/src/arg_parse.c @@ -129,7 +129,7 @@ Args parse_args(int32_t argc, char **argv) { exit(1); } else { printf( - "NOTICE set cache-entry-lifetime to %lu\n", + "NOTICE set cache-entry-lifetime to %zu\n", args.cache_lifespan_seconds); } } else if (strncmp(argv[0], "--enable-static-dir=", 20) == 0) { diff --git a/src/main.c b/src/main.c index b2b6338..62cf98e 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,7 @@ #include #include #include +#include // Linux/Unix includes. #include @@ -232,7 +233,7 @@ int c_simple_http_manage_connections(void *data, void *ud) { snprintf( content_length_buf + content_length_buf_size, 127 - content_length_buf_size, - "%lu\n%n", + "%zu\n%n", response_size, &written); if (written <= 0) { @@ -304,7 +305,7 @@ int c_simple_http_manage_connections(void *data, void *ud) { snprintf( content_length_buf, content_str_len + 1 + 16 + 1, - "Content-Length: %lu\n", + "Content-Length: %" PRIu64 "\n", file_info.buf_size); CHECK_ERROR_WRITE_NO_FD(write( citem->fd, content_length_buf, content_str_len + 1 + 16)); @@ -385,7 +386,8 @@ int main(int argc, char **argv) { socklen_t size = sizeof(ipv6_addr); int ret = getsockname(tcp_socket, (struct sockaddr*)&ipv6_addr, &size); if (ret == 0) { - printf("Listening on port: %u\n", u16_be_swap(ipv6_addr.sin6_port)); + printf("Listening on port: %" PRIu16 "\n", + u16_be_swap(ipv6_addr.sin6_port)); } else { fprintf( stderr, @@ -462,7 +464,7 @@ int main(int argc, char **argv) { ++config_try_reload_attempts; fprintf( stderr, - "Attempting to reload config now (try %u of %u)...\n", + "Attempting to reload config now (try %" PRIu32 " of %u)...\n", config_try_reload_attempts, C_SIMPLE_HTTP_TRY_CONFIG_RELOAD_MAX_ATTEMPTS); C_SIMPLE_HTTP_ParsedConfig new_parsed_config = @@ -532,7 +534,7 @@ int main(int argc, char **argv) { } } else if (read_ret > 0) { #ifndef NDEBUG - printf("DEBUG inotify_event->mask: %x\n", inotify_event->mask); + printf("DEBUG inotify_event->mask: %" PRIx32 "\n", inotify_event->mask); #endif if ((inotify_event->mask & IN_MODIFY) != 0 || (inotify_event->mask & IN_CLOSE_WRITE) != 0) { diff --git a/src/test.c b/src/test.c index 5fd5feb..0a98b3a 100644 --- a/src/test.c +++ b/src/test.c @@ -3,6 +3,7 @@ #include #include #include +#include // POSIX includes. #include @@ -28,7 +29,10 @@ static int32_t checks_passed = 0; #define RETURN() \ do { \ - fprintf(stderr, "checked %d\npassed %d\n", checks_checked, checks_passed);\ + fprintf(stderr, \ + "checked %" PRId32 "\npassed %" PRId32 "\n", \ + checks_checked, \ + checks_passed); \ return checks_checked == checks_passed ? 0 : 1; \ } while (0);