1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
From: Karel Zak <kzak@redhat.com>
Date: Thu, 20 Mar 2025 11:57:06 +0100
Subject: misc: never include wchar.h
We have a portable "widechar.h" that follows --disable-widechar and
provides portability. It is a bug to directly include libc's wchar.h
or wctype.h.
Fixes: https://github.com/util-linux/util-linux/issues/3470
Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 5c0888dde3cc296d06b8243dcc78248ff90526e5)
---
disk-utils/cfdisk.c | 6 +-----
include/carefulputc.h | 5 +----
include/fgetwc_or_err.h | 6 +-----
lib/idcache.c | 2 +-
sys-utils/irqtop.c | 7 ++-----
sys-utils/lsns.c | 2 +-
tests/helpers/test_sysinfo.c | 2 +-
7 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 4018f4d..d4057ee 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -52,14 +52,10 @@
# include <ncurses/ncurses.h>
#endif
-#ifdef HAVE_WIDECHAR
-# include <wctype.h>
-# include <wchar.h>
-#endif
-
#include "c.h"
#include "closestream.h"
#include "nls.h"
+#include "widechar.h"
#include "strutils.h"
#include "xalloc.h"
#include "mbsalign.h"
diff --git a/include/carefulputc.h b/include/carefulputc.h
index 3cc6f7f..c6b778b 100644
--- a/include/carefulputc.h
+++ b/include/carefulputc.h
@@ -4,12 +4,9 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
-#ifdef HAVE_WIDECHAR
-#include <wctype.h>
-#include <wchar.h>
-#endif
#include <stdbool.h>
+#include "widechar.h"
#include "cctype.h"
/*
diff --git a/include/fgetwc_or_err.h b/include/fgetwc_or_err.h
index 3cf9262..f6ba71c 100644
--- a/include/fgetwc_or_err.h
+++ b/include/fgetwc_or_err.h
@@ -1,13 +1,9 @@
#ifndef UTIL_LINUX_FGETWC_OR_ERR_H
#define UTIL_LINUX_FGETWC_OR_ERR_H
-#include <stdio.h>
-#include <wchar.h>
-#include <errno.h>
-
-#include "widechar.h"
#include "c.h"
#include "nls.h"
+#include "widechar.h"
static inline wint_t fgetwc_or_err(FILE *stream) {
wint_t ret;
diff --git a/lib/idcache.c b/lib/idcache.c
index fa77e7b..7bae768 100644
--- a/lib/idcache.c
+++ b/lib/idcache.c
@@ -4,12 +4,12 @@
*
* Written by Karel Zak <kzak@redhat.com>
*/
-#include <wchar.h>
#include <pwd.h>
#include <grp.h>
#include <sys/types.h>
#include "c.h"
+#include "widechar.h"
#include "idcache.h"
struct identry *get_id(struct idcache *ic, unsigned long int id)
diff --git a/sys-utils/irqtop.c b/sys-utils/irqtop.c
index ce6a2ca..f05bf6b 100644
--- a/sys-utils/irqtop.c
+++ b/sys-utils/irqtop.c
@@ -43,13 +43,10 @@
# include <ncurses/ncurses.h>
#endif
-#ifdef HAVE_WIDECHAR
-# include <wctype.h>
-# include <wchar.h>
-#endif
-
#include <libsmartcols.h>
+#include "c.h"
+#include "widechar.h"
#include "closestream.h"
#include "cpuset.h"
#include "monotonic.h"
diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index 6b2dcba..2b613cf 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -19,7 +19,6 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <wchar.h>
#include <libsmartcols.h>
#include <libmount.h>
# include <stdbool.h>
@@ -43,6 +42,7 @@
#include "nls.h"
#include "xalloc.h"
#include "c.h"
+#include "widechar.h"
#include "list.h"
#include "closestream.h"
#include "optutils.h"
diff --git a/tests/helpers/test_sysinfo.c b/tests/helpers/test_sysinfo.c
index 1559d47..95f50f3 100644
--- a/tests/helpers/test_sysinfo.c
+++ b/tests/helpers/test_sysinfo.c
@@ -23,12 +23,12 @@
#include <limits.h>
#include <stdint.h>
#include <inttypes.h>
-#include <wchar.h>
#include <errno.h>
#include <time.h>
#include <sys/ioctl.h>
#include "c.h"
+#include "widechar.h"
#ifdef __linux__
# include <sys/mount.h>
|