commit: 2261cbe1a2a4c734e79f8294e46e35b0bc17d0dd
parent 981588bda2c8e4ba5a2eb0b00026a9380ce5c43f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 29 Nov 2025 18:16:59 +0100
fix integer size warnings on ppc32
Diffstat:
7 files changed, 60 insertions(+), 52 deletions(-)
diff --git a/cmd/date.c b/cmd/date.c
@@ -12,7 +12,8 @@
#include <assert.h>
#include <errno.h>
-#include <locale.h> /* setlocale() */
+#include <inttypes.h> /* PRId64 */
+#include <locale.h> /* setlocale() */
#include <stdbool.h>
#include <stdio.h> /* BUFSIZ, fprintf(), puts() */
#include <stdlib.h> /* strtol() */
@@ -405,10 +406,10 @@ main(int argc, char *argv[])
if(clock_settime(CLOCK_REALTIME, &tp) != 0)
{
fprintf(stderr,
- "%s: error: clock_settime(CLOCK_REALTIME, {%ld, %ld}): %s\n",
+ "%s: error: clock_settime(CLOCK_REALTIME, {%" PRId64 ", %" PRId64 "}): %s\n",
argv0,
- tp.tv_sec,
- tp.tv_nsec,
+ (int64_t)tp.tv_sec,
+ (int64_t)tp.tv_nsec,
strerror(errno));
return 1;
}
diff --git a/cmd/df.c b/cmd/df.c
@@ -14,6 +14,7 @@
#include <errno.h> // errno
#include <mntent.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h> // printf
#include <stdlib.h> // abort, exit
#include <string.h> // strerror
@@ -414,8 +415,8 @@ main(int argc, char *argv[])
if(opt_i)
{
- fsfilcnt_t used = stats.f_files - stats.f_ffree;
- fsfilcnt_t percent = (used / stats.f_files) * 100;
+ intmax_t used = stats.f_files - stats.f_ffree;
+ intmax_t percent = (used / stats.f_files) * 100;
if(opt_h && !opt_P)
{
@@ -432,21 +433,21 @@ main(int argc, char *argv[])
}
else
{
- printf("%*zd ", col_width, stats.f_files);
- printf("%*zd ", col_width, used);
- printf("%*zd ", col_width, stats.f_ffree);
+ printf("%*jd ", col_width, (intmax_t)stats.f_files);
+ printf("%*jd ", col_width, used);
+ printf("%*jd ", col_width, (intmax_t)stats.f_ffree);
}
- printf("%*zd%% ", tty_out ? 4 : 0, percent);
+ printf("%*jd%% ", tty_out ? 4 : 0, percent);
printf("%s\n", mntent->mnt_dir);
continue;
}
- off_t percent = 0;
- off_t total = stats.f_frsize * (stats.f_blocks != 0 ? stats.f_blocks : 1);
- off_t free = stats.f_bfree * (stats.f_bsize != 0 ? stats.f_bsize : 1);
- off_t used = total - free;
+ intmax_t percent = 0;
+ intmax_t total = stats.f_frsize * (stats.f_blocks != 0 ? stats.f_blocks : 1);
+ intmax_t free = stats.f_bfree * (stats.f_bsize != 0 ? stats.f_bsize : 1);
+ intmax_t used = total - free;
if(used + free)
{
@@ -476,12 +477,12 @@ main(int argc, char *argv[])
}
else
{
- printf("%*zd ", col_width, total);
- printf("%*zd ", col_width, used);
- printf("%*zd ", col_width, free);
+ printf("%*jd ", col_width, total);
+ printf("%*jd ", col_width, used);
+ printf("%*jd ", col_width, free);
}
- printf("%*zd%% ", tty_out ? 3 : 0, percent);
+ printf("%*jd%% ", tty_out ? 3 : 0, percent);
printf("%s\n", mntent->mnt_dir);
}
diff --git a/cmd/getconf.c b/cmd/getconf.c
@@ -87,7 +87,7 @@ print_system_var(const char *var)
if(strcmp(sysconf_vars[i].name, var) != 0) continue;
errno = 0;
- long ret = sysconf((int)(sysconf_vars[i].value));
+ int_least64_t ret = sysconf((int)(sysconf_vars[i].value));
if(ret == -1 && errno != 0)
{
fprintf(stderr,
@@ -106,7 +106,7 @@ print_system_var(const char *var)
return 0;
}
- printf("%ld\n", ret);
+ printf("%" PRIdLEAST64 "\n", ret);
return 0;
}
@@ -114,7 +114,7 @@ print_system_var(const char *var)
{
if(strcmp(limits_vars[i].name, var) != 0) continue;
- long ret = limits_vars[i].limit_h;
+ int_least64_t ret = limits_vars[i].limit_h;
if(ret == -1)
{
@@ -122,7 +122,7 @@ print_system_var(const char *var)
return 0;
}
- printf("%ld\n", ret);
+ printf("%" PRIdLEAST64 "\n", ret);
return 0;
}
@@ -163,7 +163,7 @@ main(int argc, char *argv[])
if(strcmp(pathconf_vars[i].name, argv[0]) != 0) continue;
errno = 0;
- long ret = pathconf(argv[1], (int)(pathconf_vars[i].value));
+ int_least64_t ret = pathconf(argv[1], (int)(pathconf_vars[i].value));
if(ret == -1 && errno != 0)
{
fprintf(stderr,
@@ -176,7 +176,7 @@ main(int argc, char *argv[])
}
if(ret == -1) ret = pathconf_vars[i].limit_h;
- printf("%ld\n", ret);
+ printf("%" PRIdLEAST64 "\n", ret);
return 0;
}
@@ -258,7 +258,7 @@ main(int argc, char *argv[])
for(size_t i = 0; i < (sizeof(sysconf_vars) / sizeof(*sysconf_vars)); i++)
{
errno = 0;
- long ret = sysconf((int)(sysconf_vars[i].value));
+ int_least64_t ret = sysconf((int)(sysconf_vars[i].value));
if(ret == -1 && errno != 0)
{
fprintf(stderr,
@@ -278,12 +278,12 @@ main(int argc, char *argv[])
continue;
}
- printf("%s: %ld\n", sysconf_vars[i].name, ret);
+ printf("%s: %" PRIdLEAST64 "\n", sysconf_vars[i].name, ret);
}
for(size_t i = 0; i < (sizeof(limits_vars) / sizeof(*limits_vars)); i++)
{
- long ret = limits_vars[i].limit_h;
+ int_least64_t ret = limits_vars[i].limit_h;
if(ret == -1)
{
@@ -291,14 +291,14 @@ main(int argc, char *argv[])
continue;
}
- printf("%s: %ld\n", limits_vars[i].name, ret);
+ printf("%s: %" PRIdLEAST64 "\n", limits_vars[i].name, ret);
}
const char *path = argc == 1 ? argv[0] : ".";
for(size_t i = 0; i < (sizeof(pathconf_vars) / sizeof(*pathconf_vars)); i++)
{
errno = 0;
- long ret = pathconf(path, (int)(pathconf_vars[i].value));
+ int_least64_t ret = pathconf(path, (int)(pathconf_vars[i].value));
if(ret == -1 && errno != 0)
{
fprintf(stderr,
@@ -312,7 +312,7 @@ main(int argc, char *argv[])
}
if(ret == -1) ret = pathconf_vars[i].limit_h;
- printf("%s: %ld\n", pathconf_vars[i].name, ret);
+ printf("%s: %" PRIdLEAST64 "\n", pathconf_vars[i].name, ret);
}
return err;
diff --git a/cmd/sleep.c b/cmd/sleep.c
@@ -5,11 +5,12 @@
#define _POSIX_C_SOURCE 200809L
#include "../libutils/strtodur.h"
-#include <errno.h> // errno
-#include <stdio.h> // fprintf, perror
-#include <string.h> // strerror
-#include <time.h> // nanosleep
-#include <unistd.h> // execvp
+#include <errno.h> // errno
+#include <inttypes.h> // PRId64
+#include <stdio.h> // fprintf, perror
+#include <string.h> // strerror
+#include <time.h> // nanosleep
+#include <unistd.h> // execvp
const char *argv0 = "sleep";
@@ -50,9 +51,10 @@ main(int argc, char *argv[])
if(errno == EINTR)
{
fprintf(stderr,
- "sleep: warning: Interrupted during sleep, still had %ld.%09ld seconds remaining\n",
- dur.tv_sec,
- dur.tv_nsec);
+ "sleep: warning: Interrupted during sleep, still had %" PRId64 ".%09" PRId64
+ " seconds remaining\n",
+ (int64_t)dur.tv_sec,
+ (int64_t)dur.tv_nsec);
}
else
{
diff --git a/cmd/timeout.c b/cmd/timeout.c
@@ -11,8 +11,9 @@
#include <ctype.h>
#include <errno.h>
-#include <signal.h> // kill
-#include <spawn.h> // posix_spawn
+#include <inttypes.h> // PRId64
+#include <signal.h> // kill
+#include <spawn.h> // posix_spawn
#include <stdbool.h>
#include <stdio.h> // fprintf
#include <stdlib.h> // exit
@@ -203,11 +204,11 @@ main(int argc, char *argv[])
if(errno == EINTR)
{
fprintf(stderr,
- "timeout: warning: Interrupted during sleeping for %s, still had %ld.%09ld seconds "
- "remaining\n",
+ "timeout: warning: Interrupted during sleeping for %s, still had %" PRId64
+ ".%09" PRId64 " seconds remaining\n",
term_signame,
- term.tv_sec,
- term.tv_nsec);
+ (int64_t)term.tv_sec,
+ (int64_t)term.tv_nsec);
}
else
{
@@ -242,10 +243,10 @@ main(int argc, char *argv[])
if(errno == EINTR)
{
fprintf(stderr,
- "timeout: warning: Interrupted during KILL-sleep, still had %ld.%09ld seconds "
- "remaining\n",
- term.tv_sec,
- term.tv_nsec);
+ "timeout: warning: Interrupted during KILL-sleep, still had %" PRId64 ".%09" PRId64
+ " seconds remaining\n",
+ (int64_t)term.tv_sec,
+ (int64_t)term.tv_nsec);
}
else
{
diff --git a/lib/getconf_vars.m4 b/lib/getconf_vars.m4
@@ -20,17 +20,19 @@ define(`conf_var_limit', `#ifndef $3
#endif
')dnl
+#include <inttypes.h>
+
struct conf_vars
{
const char *name;
const int value;
- const long limit_h;
+ const int_least64_t limit_h;
};
struct limits
{
const char *name;
- const long limit_h;
+ const int_least64_t limit_h;
};
dnl _CS_V${n}_ENV exposes environment variables to achieve said SUSv${n} version
diff --git a/libutils/truncation.c b/libutils/truncation.c
@@ -8,6 +8,7 @@
#include <assert.h>
#include <ctype.h> // toupper
#include <errno.h>
+#include <stdint.h> // intmax_t
#include <stdio.h> // fprintf
#include <stdlib.h> // strtol
#include <string.h> // strerror
@@ -57,9 +58,9 @@ apply_truncation(int fd, struct truncation tr, char *arg)
if(ftruncate(fd, tr.size) < 0)
{
fprintf(stderr,
- "truncate: error: Failed to truncate '%s' to %ld: %s\n",
+ "truncate: error: Failed to truncate '%s' to %jd: %s\n",
arg,
- tr.size,
+ (intmax_t)tr.size,
strerror(errno));
return -1;
}