From a6a8f687f8a05e222c557d48e22a214f48c3c9cb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 13 Feb 2025 23:27:42 -0800 Subject: [PATCH] cat: port to platforms with shm, tmo * src/cat.c (main): Work even on platforms that have shared memory objects and typed memory objects, which means st_dev and st_ino do not work. --- src/cat.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cat.c b/src/cat.c index dcf537bc99..92773d354f 100644 --- a/src/cat.c +++ b/src/cat.c @@ -646,9 +646,15 @@ main (int argc, char **argv) idx_t outsize = io_blksize (&stat_buf); /* Device, I-node number and lazily-acquired flags of the output. */ - dev_t out_dev = stat_buf.st_dev; - ino_t out_ino = stat_buf.st_ino; + dev_t out_dev; + ino_t out_ino; int out_flags = -2; + bool have_out_dev = ! (S_TYPEISSHM (&stat_buf) || S_TYPEISTMO (&stat_buf)); + if (have_out_dev) + { + out_dev = stat_buf.st_dev; + out_ino = stat_buf.st_ino; + } /* True if the output is a regular file. */ bool out_isreg = S_ISREG (stat_buf.st_mode) != 0; @@ -706,7 +712,9 @@ main (int argc, char **argv) output device. It's better to catch this error earlier rather than later. */ - if (stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino) + if (! (S_TYPEISSHM (&stat_buf) || S_TYPEISTMO (&stat_buf)) + && have_out_dev + && stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino) { if (out_flags < -1) out_flags = fcntl (STDOUT_FILENO, F_GETFL); -- 2.47.3