]> git.seodisparate.com - c_simple_http/commitdiff
Use proper format constants for size_t/uintX_t etc
authorStephen Seo <seo.disparate@gmail.com>
Mon, 25 Nov 2024 07:01:49 +0000 (16:01 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 25 Nov 2024 07:01:49 +0000 (16:01 +0900)
src/arg_parse.c
src/main.c
src/test.c

index 2aeb9f4a3f7d05358fd5a62cacfe582e4d491b79..30f19fabb8496e0cb67b0f6d5744d55ffec6eba7 100644 (file)
@@ -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) {
index b2b633848c6111be31c616217b5b6eeb7681cdc3..62cf98e338afa6736265cc12d67fac16581b9b0e 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <inttypes.h>
 
 // Linux/Unix includes.
 #include <sys/socket.h>
@@ -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) {
index 5fd5feb377c14add2994a231f3f3d2d39656e62a..0a98b3a8baaff06041db7672f4ad3c8362c7f18b 100644 (file)
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <inttypes.h>
 
 // POSIX includes.
 #include <unistd.h>
@@ -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);