fix(portability): sx_mount_t so macOS struct mount cannot collide, and Linux-only helpers gated
Two real portability defects, both invisible on Linux: 1. mount_t is typedef'd by sys/mount.h on macOS, so the local type shadowed it and every m->member became 'member reference base type mount_t (aka struct mount *)' - 20 errors, both Mach-O slices lost. 2. unescape_mount_field/fill_vfs are /proc/mounts-specific; Apple clang printed 'unused function' warnings because the macOS collector uses getmntinfo. Gated to !_WIN32 && !__APPLE__. Verified: gcc/musl x86_64 warning-free, arm64 static builds, Apple clang -arch arm64 and -arch x86_64 warning-free on macOS.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-11 06:54:35
Commit3b6f6858
Parents89829a91
Changed files
src/plugin_disks.c+13−13■■■■■
1 file+13−13
Diff
src/plugin_disks.c+13−13■■■■■
index 1493b81..18829ec 100644
--- a/src/plugin_disks.c
+++ b/src/plugin_disks.c
@@ -263,7 +263,7 @@ typedef struct {
263263 unsigned long long inodes_total;
264264 unsigned long long inodes_used;
265265 int has_inodes;
266-} mount_t;
266+} sx_mount_t;
267267
268268 #if !defined(_WIN32)
269269
@@ -302,7 +302,7 @@ static int pseudo_mountpoint(const char *mp)
302302
303303 #endif /* !_WIN32 */
304304
305-#if !defined(_WIN32)
305+#if !defined(_WIN32) && !defined(__APPLE__)
306306
307307 /* /proc/mounts and /etc/mtab escape space, tab, newline and backslash as octal. */
308308 static void unescape_mount_field(char *s)
@@ -320,7 +320,7 @@ static void unescape_mount_field(char *s)
320320 *o = '\0';
321321 }
322322
323-static void fill_vfs(const char *mp, mount_t *m)
323+static void fill_vfs(const char *mp, sx_mount_t *m)
324324 {
325325 struct statvfs vfs;
326326 if (statvfs(mp, &vfs) != 0) return;
@@ -340,7 +340,7 @@ static void fill_vfs(const char *mp, mount_t *m)
340340
341341 #if defined(__APPLE__)
342342
343-static int collect_mounts(mount_t *out, int max)
343+static int collect_mounts(sx_mount_t *out, int max)
344344 {
345345 struct statfs *mnt = NULL;
346346 int n, i, count = 0;
@@ -349,7 +349,7 @@ static int collect_mounts(mount_t *out, int max)
349349 if (n <= 0) return 0;
350350
351351 for (i = 0; i < n && count < max; i++) {
352- mount_t *m = &out[count];
352+ sx_mount_t *m = &out[count];
353353 unsigned long long bs = (unsigned long long)mnt[i].f_bsize;
354354 if (pseudo_fstype(mnt[i].f_fstypename)) continue;
355355 if (pseudo_mountpoint(mnt[i].f_mntonname)) continue;
@@ -374,7 +374,7 @@ static int collect_mounts(mount_t *out, int max)
374374
375375 #elif defined(_WIN32)
376376
377-static int collect_mounts(mount_t *out, int max)
377+static int collect_mounts(sx_mount_t *out, int max)
378378 {
379379 char drives[512];
380380 DWORD n;
@@ -387,7 +387,7 @@ static int collect_mounts(mount_t *out, int max)
387387 for (p = drives; *p && count < max; p += strlen(p) + 1) {
388388 ULARGE_INTEGER avail, total, totalfree;
389389 char fsname[64] = "unknown";
390- mount_t *m;
390+ sx_mount_t *m;
391391
392392 if (GetDriveTypeA(p) == DRIVE_NO_ROOT_DIR) continue;
393393 if (!GetDiskFreeSpaceExA(p, &avail, &total, &totalfree)) continue;
@@ -412,7 +412,7 @@ static int collect_mounts(mount_t *out, int max)
412412
413413 #else /* Linux and other POSIX */
414414
415-static int collect_mounts(mount_t *out, int max)
415+static int collect_mounts(sx_mount_t *out, int max)
416416 {
417417 FILE *fp;
418418 char line[2048];
@@ -474,8 +474,8 @@ static int collect_mounts(mount_t *out, int max)
474474 /* Largest first. Used for display order. */
475475 static int mount_cmp(const void *a, const void *b)
476476 {
477- const mount_t *x = (const mount_t *)a;
478- const mount_t *y = (const mount_t *)b;
477+ const sx_mount_t *x = (const sx_mount_t *)a;
478+ const sx_mount_t *y = (const sx_mount_t *)b;
479479 if (x->total_bytes < y->total_bytes) return 1;
480480 if (x->total_bytes > y->total_bytes) return -1;
481481 return strcmp(x->mount, y->mount);
@@ -719,7 +719,7 @@ static void json_header(void)
719719
720720 static void emit_mounts(void)
721721 {
722- mount_t mnt[MAX_MOUNTS];
722+ sx_mount_t mnt[MAX_MOUNTS];
723723 int i, n;
724724
725725 memset(mnt, 0, sizeof(mnt));
@@ -728,7 +728,7 @@ static void emit_mounts(void)
728728
729729 fputs("[", stdout);
730730 for (i = 0; i < n; i++) {
731- const mount_t *m = &mnt[i];
731+ const sx_mount_t *m = &mnt[i];
732732 double pct = 0.0, ipct = 0.0;
733733 if (m->used_bytes + m->avail_bytes > 0)
734734 pct = (double)m->used_bytes * 100.0 / (double)(m->used_bytes + m->avail_bytes);
@@ -899,7 +899,7 @@ static int mode_json(const char *qs)
899899
900900 /* action == mounts */
901901 {
902- mount_t probe[MAX_MOUNTS];
902+ sx_mount_t probe[MAX_MOUNTS];
903903 int n;
904904 memset(probe, 0, sizeof(probe));
905905 n = collect_mounts(probe, MAX_MOUNTS);
906906
src/plugin_disks.c+13−13■■■■■
index 1493b81..18829ec 100644index 1493b81..18829ec 100644
--- a/src/plugin_disks.c--- a/src/plugin_disks.c
+++ b/src/plugin_disks.c+++ b/src/plugin_disks.c
@@ -263,7 +263,7 @@ typedef struct {@@ -263,7 +263,7 @@ typedef struct {
263 unsigned long long inodes_total;263 unsigned long long inodes_total;
264 unsigned long long inodes_used;264 unsigned long long inodes_used;
265 int has_inodes;265 int has_inodes;
266-} mount_t;266+} sx_mount_t;
267 267
268 #if !defined(_WIN32)268 #if !defined(_WIN32)
269 269
@@ -302,7 +302,7 @@ static int pseudo_mountpoint(const char *mp)@@ -302,7 +302,7 @@ static int pseudo_mountpoint(const char *mp)
302 302
303 #endif /* !_WIN32 */303 #endif /* !_WIN32 */
304 304
305-#if !defined(_WIN32)305+#if !defined(_WIN32) && !defined(__APPLE__)
306 306
307 /* /proc/mounts and /etc/mtab escape space, tab, newline and backslash as octal. */307 /* /proc/mounts and /etc/mtab escape space, tab, newline and backslash as octal. */
308 static void unescape_mount_field(char *s)308 static void unescape_mount_field(char *s)
@@ -320,7 +320,7 @@ static void unescape_mount_field(char *s)@@ -320,7 +320,7 @@ static void unescape_mount_field(char *s)
320 *o = '\0';320 *o = '\0';
321 }321 }
322 322
323-static void fill_vfs(const char *mp, mount_t *m)323+static void fill_vfs(const char *mp, sx_mount_t *m)
324 {324 {
325 struct statvfs vfs;325 struct statvfs vfs;
326 if (statvfs(mp, &vfs) != 0) return;326 if (statvfs(mp, &vfs) != 0) return;
@@ -340,7 +340,7 @@ static void fill_vfs(const char *mp, mount_t *m)@@ -340,7 +340,7 @@ static void fill_vfs(const char *mp, mount_t *m)
340 340
341 #if defined(__APPLE__)341 #if defined(__APPLE__)
342 342
343-static int collect_mounts(mount_t *out, int max)343+static int collect_mounts(sx_mount_t *out, int max)
344 {344 {
345 struct statfs *mnt = NULL;345 struct statfs *mnt = NULL;
346 int n, i, count = 0;346 int n, i, count = 0;
@@ -349,7 +349,7 @@ static int collect_mounts(mount_t *out, int max)@@ -349,7 +349,7 @@ static int collect_mounts(mount_t *out, int max)
349 if (n <= 0) return 0;349 if (n <= 0) return 0;
350 350
351 for (i = 0; i < n && count < max; i++) {351 for (i = 0; i < n && count < max; i++) {
352- mount_t *m = &out[count];352+ sx_mount_t *m = &out[count];
353 unsigned long long bs = (unsigned long long)mnt[i].f_bsize;353 unsigned long long bs = (unsigned long long)mnt[i].f_bsize;
354 if (pseudo_fstype(mnt[i].f_fstypename)) continue;354 if (pseudo_fstype(mnt[i].f_fstypename)) continue;
355 if (pseudo_mountpoint(mnt[i].f_mntonname)) continue;355 if (pseudo_mountpoint(mnt[i].f_mntonname)) continue;
@@ -374,7 +374,7 @@ static int collect_mounts(mount_t *out, int max)@@ -374,7 +374,7 @@ static int collect_mounts(mount_t *out, int max)
374 374
375 #elif defined(_WIN32)375 #elif defined(_WIN32)
376 376
377-static int collect_mounts(mount_t *out, int max)377+static int collect_mounts(sx_mount_t *out, int max)
378 {378 {
379 char drives[512];379 char drives[512];
380 DWORD n;380 DWORD n;
@@ -387,7 +387,7 @@ static int collect_mounts(mount_t *out, int max)@@ -387,7 +387,7 @@ static int collect_mounts(mount_t *out, int max)
387 for (p = drives; *p && count < max; p += strlen(p) + 1) {387 for (p = drives; *p && count < max; p += strlen(p) + 1) {
388 ULARGE_INTEGER avail, total, totalfree;388 ULARGE_INTEGER avail, total, totalfree;
389 char fsname[64] = "unknown";389 char fsname[64] = "unknown";
390- mount_t *m;390+ sx_mount_t *m;
391 391
392 if (GetDriveTypeA(p) == DRIVE_NO_ROOT_DIR) continue;392 if (GetDriveTypeA(p) == DRIVE_NO_ROOT_DIR) continue;
393 if (!GetDiskFreeSpaceExA(p, &avail, &total, &totalfree)) continue;393 if (!GetDiskFreeSpaceExA(p, &avail, &total, &totalfree)) continue;
@@ -412,7 +412,7 @@ static int collect_mounts(mount_t *out, int max)@@ -412,7 +412,7 @@ static int collect_mounts(mount_t *out, int max)
412 412
413 #else /* Linux and other POSIX */413 #else /* Linux and other POSIX */
414 414
415-static int collect_mounts(mount_t *out, int max)415+static int collect_mounts(sx_mount_t *out, int max)
416 {416 {
417 FILE *fp;417 FILE *fp;
418 char line[2048];418 char line[2048];
@@ -474,8 +474,8 @@ static int collect_mounts(mount_t *out, int max)@@ -474,8 +474,8 @@ static int collect_mounts(mount_t *out, int max)
474 /* Largest first. Used for display order. */474 /* Largest first. Used for display order. */
475 static int mount_cmp(const void *a, const void *b)475 static int mount_cmp(const void *a, const void *b)
476 {476 {
477- const mount_t *x = (const mount_t *)a;477+ const sx_mount_t *x = (const sx_mount_t *)a;
478- const mount_t *y = (const mount_t *)b;478+ const sx_mount_t *y = (const sx_mount_t *)b;
479 if (x->total_bytes < y->total_bytes) return 1;479 if (x->total_bytes < y->total_bytes) return 1;
480 if (x->total_bytes > y->total_bytes) return -1;480 if (x->total_bytes > y->total_bytes) return -1;
481 return strcmp(x->mount, y->mount);481 return strcmp(x->mount, y->mount);
@@ -719,7 +719,7 @@ static void json_header(void)@@ -719,7 +719,7 @@ static void json_header(void)
719 719
720 static void emit_mounts(void)720 static void emit_mounts(void)
721 {721 {
722- mount_t mnt[MAX_MOUNTS];722+ sx_mount_t mnt[MAX_MOUNTS];
723 int i, n;723 int i, n;
724 724
725 memset(mnt, 0, sizeof(mnt));725 memset(mnt, 0, sizeof(mnt));
@@ -728,7 +728,7 @@ static void emit_mounts(void)@@ -728,7 +728,7 @@ static void emit_mounts(void)
728 728
729 fputs("[", stdout);729 fputs("[", stdout);
730 for (i = 0; i < n; i++) {730 for (i = 0; i < n; i++) {
731- const mount_t *m = &mnt[i];731+ const sx_mount_t *m = &mnt[i];
732 double pct = 0.0, ipct = 0.0;732 double pct = 0.0, ipct = 0.0;
733 if (m->used_bytes + m->avail_bytes > 0)733 if (m->used_bytes + m->avail_bytes > 0)
734 pct = (double)m->used_bytes * 100.0 / (double)(m->used_bytes + m->avail_bytes);734 pct = (double)m->used_bytes * 100.0 / (double)(m->used_bytes + m->avail_bytes);
@@ -899,7 +899,7 @@ static int mode_json(const char *qs)@@ -899,7 +899,7 @@ static int mode_json(const char *qs)
899 899
900 /* action == mounts */900 /* action == mounts */
901 {901 {
902- mount_t probe[MAX_MOUNTS];902+ sx_mount_t probe[MAX_MOUNTS];
903 int n;903 int n;
904 memset(probe, 0, sizeof(probe));904 memset(probe, 0, sizeof(probe));
905 n = collect_mounts(probe, MAX_MOUNTS);905 n = collect_mounts(probe, MAX_MOUNTS);
906906