From 0771cac8493ca4de04058ae3f9b86c5d2e23c1b5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 3 Sep 2023 18:14:53 -0700 Subject: [PATCH] same-inode, stat-size: support pointers too Add functions and macros so that we can test pointers to struct stat as well as plain struct stat. This lets coreutils deal with structs that are only partly initialized, without relying on undefined behavior. * NEWS: Mention this. * doc/posix-headers/sys_stat.texi, doc/stat-size.texi: Mention this and modernize. * lib/at-func2.c (at_func2): * lib/fts.c (same_fd): * lib/rename.c (rpl_rename) [RENAME_HARD_LINK_BUG]: * lib/same-inode.c: New file. * lib/same.c (same_nameat): * lib/term-style-control.c (activate_term_style_controller): Prefer psame_inode (a, b) to SAME_INODE (*a, *b). * lib/hash-triple-simple.c (triple_compare_ino_str): * lib/hash-triple.c (triple_compare): Prefer PSAME_INODE (a, b) to SAME_INODE (*a, *b). psame_inode is not suitable since the args are not struct stat *. * lib/same-inode.h: Check that config.h is included first. (SAME_INODE_INLINE, PSAME_INODE): New macros. (SAME_INODE): Reimplement in terms of PSAME_INODE. (psame_inode): New function. * lib/stat-size.h (STP_BLKSIZE, STP_NBLOCKS): New macros. (ST_BLKSIZE, ST_NBLOCKS): Use them. * lib/term-style-control.c (log_signal_handler_called): Always define as a function, to pacify -Wunused*. * modules/canonicalize-lgpl-tests (Files): Add m4/musl.m4. (Depends-on): Call gl_MUSL_LIBC. * modules/same-inode (Files): Add same-inode.c. (Depends-on): Add extern-inline, stdbool. (lib_SOURCES): New macro. * tests/test-binary-io.c, tests/test-canonicalize-lgpl.c: * tests/test-canonicalize.c, tests/test-cloexec.c: * tests/test-dup-safer.c, tests/test-dup2.c, tests/test-error.c: * tests/test-fcntl.c, tests/test-fdopendir.c, tests/test-fgetc.c: * tests/test-fputc.c, tests/test-fread.c, tests/test-fstat.c: * tests/test-fstatat.c, tests/test-ftruncate.c: * tests/test-fwrite.c, tests/test-getcwd.c: * tests/test-getdtablesize.c, tests/test-isblank.c: * tests/test-linkat.c, tests/test-lock.c, tests/test-lstat.h: * tests/test-malloc-gnu.c, tests/test-openat.c: * tests/test-pthread-thread.c, tests/test-pthread_sigmask1.c: * tests/test-pthread_sigmask2.c, tests/test-ptsname.c: * tests/test-ptsname_r.c, tests/test-raise.c: * tests/test-realloc-gnu.c, tests/test-rwlock1.c: * tests/test-sigprocmask.c, tests/test-snprintf.c: * tests/test-stat.h, tests/test-term-style-control-hello.c: * tests/test-term-style-control-yes.c, tests/test-thread_create.c: * tests/test-unlinkat.c, tests/test-vasnprintf.c: * tests/test-xalloc-die.c: Adjust to these changes, and fix some warnings elicited by -Wall -Wextra that I ran into while testing. * top/maint.mk (sc_prohibit_stat_st_blocks): Mention STP_NBLOCKS. --- ChangeLog | 57 ++++++++++++++++++ NEWS | 3 + doc/posix-headers/sys_stat.texi | 34 ++++++----- doc/stat-size.texi | 8 ++- lib/at-func2.c | 10 ++-- lib/fts.c | 2 +- lib/hash-triple-simple.c | 2 +- lib/hash-triple.c | 2 +- lib/rename.c | 2 +- lib/same-inode.c | 3 + lib/same-inode.h | 84 +++++++++++++++++++-------- lib/same.c | 4 +- lib/stat-size.h | 48 +++++++-------- lib/term-style-control.c | 7 ++- modules/canonicalize-lgpl-tests | 2 + modules/same-inode | 4 ++ tests/test-binary-io.c | 2 +- tests/test-canonicalize-lgpl.c | 12 ++-- tests/test-canonicalize.c | 8 ++- tests/test-cloexec.c | 8 ++- tests/test-dup-safer.c | 8 ++- tests/test-dup2.c | 8 ++- tests/test-error.c | 2 +- tests/test-fcntl.c | 10 +++- tests/test-fdopendir.c | 2 +- tests/test-fgetc.c | 2 +- tests/test-fputc.c | 2 +- tests/test-fread.c | 2 +- tests/test-fstat.c | 2 +- tests/test-fstatat.c | 2 +- tests/test-ftruncate.c | 2 +- tests/test-fwrite.c | 2 +- tests/test-getcwd.c | 2 +- tests/test-getdtablesize.c | 2 +- tests/test-isblank.c | 2 +- tests/test-linkat.c | 2 +- tests/test-lock.c | 12 ++-- tests/test-lstat.h | 6 +- tests/test-malloc-gnu.c | 2 +- tests/test-openat.c | 2 +- tests/test-pthread-thread.c | 2 +- tests/test-pthread_sigmask1.c | 4 +- tests/test-pthread_sigmask2.c | 6 +- tests/test-ptsname.c | 2 +- tests/test-ptsname_r.c | 2 +- tests/test-raise.c | 2 +- tests/test-realloc-gnu.c | 2 +- tests/test-rwlock1.c | 6 +- tests/test-sigprocmask.c | 4 +- tests/test-snprintf.c | 2 +- tests/test-stat.h | 6 +- tests/test-term-style-control-hello.c | 6 +- tests/test-term-style-control-yes.c | 6 +- tests/test-thread_create.c | 2 +- tests/test-unlinkat.c | 2 +- tests/test-vasnprintf.c | 2 +- tests/test-xalloc-die.c | 2 +- top/maint.mk | 4 +- 58 files changed, 288 insertions(+), 150 deletions(-) create mode 100644 lib/same-inode.c diff --git a/ChangeLog b/ChangeLog index 4273e680ec..601ab4f2c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,60 @@ +2023-09-03 Paul Eggert + + same-inode, stat-size: support pointers too + Add functions and macros so that we can test pointers to struct + stat as well as plain struct stat. This lets coreutils deal with + structs that are only partly initialized, without relying on + undefined behavior. + * NEWS: Mention this. + * doc/posix-headers/sys_stat.texi, doc/stat-size.texi: + Mention this and modernize. + * lib/at-func2.c (at_func2): + * lib/fts.c (same_fd): + * lib/rename.c (rpl_rename) [RENAME_HARD_LINK_BUG]: + * lib/same-inode.c: New file. + * lib/same.c (same_nameat): + * lib/term-style-control.c (activate_term_style_controller): + Prefer psame_inode (a, b) to SAME_INODE (*a, *b). + * lib/hash-triple-simple.c (triple_compare_ino_str): + * lib/hash-triple.c (triple_compare): + Prefer PSAME_INODE (a, b) to SAME_INODE (*a, *b). + psame_inode is not suitable since the args are not struct stat *. + * lib/same-inode.h: Check that config.h is included first. + (SAME_INODE_INLINE, PSAME_INODE): New macros. + (SAME_INODE): Reimplement in terms of PSAME_INODE. + (psame_inode): New function. + * lib/stat-size.h (STP_BLKSIZE, STP_NBLOCKS): New macros. + (ST_BLKSIZE, ST_NBLOCKS): Use them. + * lib/term-style-control.c (log_signal_handler_called): + Always define as a function, to pacify -Wunused*. + * modules/canonicalize-lgpl-tests (Files): Add m4/musl.m4. + (Depends-on): Call gl_MUSL_LIBC. + * modules/same-inode (Files): Add same-inode.c. + (Depends-on): Add extern-inline, stdbool. + (lib_SOURCES): New macro. + * tests/test-binary-io.c, tests/test-canonicalize-lgpl.c: + * tests/test-canonicalize.c, tests/test-cloexec.c: + * tests/test-dup-safer.c, tests/test-dup2.c, tests/test-error.c: + * tests/test-fcntl.c, tests/test-fdopendir.c, tests/test-fgetc.c: + * tests/test-fputc.c, tests/test-fread.c, tests/test-fstat.c: + * tests/test-fstatat.c, tests/test-ftruncate.c: + * tests/test-fwrite.c, tests/test-getcwd.c: + * tests/test-getdtablesize.c, tests/test-isblank.c: + * tests/test-linkat.c, tests/test-lock.c, tests/test-lstat.h: + * tests/test-malloc-gnu.c, tests/test-openat.c: + * tests/test-pthread-thread.c, tests/test-pthread_sigmask1.c: + * tests/test-pthread_sigmask2.c, tests/test-ptsname.c: + * tests/test-ptsname_r.c, tests/test-raise.c: + * tests/test-realloc-gnu.c, tests/test-rwlock1.c: + * tests/test-sigprocmask.c, tests/test-snprintf.c: + * tests/test-stat.h, tests/test-term-style-control-hello.c: + * tests/test-term-style-control-yes.c, tests/test-thread_create.c: + * tests/test-unlinkat.c, tests/test-vasnprintf.c: + * tests/test-xalloc-die.c: + Adjust to these changes, and fix some warnings elicited by + -Wall -Wextra that I ran into while testing. + * top/maint.mk (sc_prohibit_stat_st_blocks): Mention STP_NBLOCKS. + 2023-09-02 Bruno Haible alignalloc: Fix license header. diff --git a/NEWS b/NEWS index 081a5f6035..a7c22ecb33 100644 --- a/NEWS +++ b/NEWS @@ -74,6 +74,9 @@ User visible incompatible changes Date Modules Changes +2023-09-03 same-inode SAME_INODE, ST_BLKSIZE and ST_NBLOCKS args + stat-size must be addressable lvalues. + 2023-08-08 readutmp The result element type of the function read_utmp, STRUCT_UTMP, is no longer the same as the result value type of the function getutxent, struct utmpx. diff --git a/doc/posix-headers/sys_stat.texi b/doc/posix-headers/sys_stat.texi index afa3a1c912..52027d7a25 100644 --- a/doc/posix-headers/sys_stat.texi +++ b/doc/posix-headers/sys_stat.texi @@ -37,6 +37,13 @@ Portability problems fixed by Gnulib module @code{sys_stat}, together with modul On Windows platforms (excluding Cygwin), @code{st_ino} is always 0. @end itemize +On platforms where @code{off_t} is a 32-bit type, @code{struct stat} +cannot represent the size of files or block devices 2 GiB or lager +and may not work correctly on directories 2 GiB or larger. +Also, on platforms where @code{ino_t} is a 32-bit type, +@code{struct stat} cannot represent larger inode numbers. +@xref{Large File Support}, for how to address these problems. + @xref{Avoiding the year 2038 problem}, for portability issues with the @code{time_t} components of @code{struct stat}. @@ -48,15 +55,7 @@ MSVC 14. @item On OpenVMS, @code{st_ino} is an array of three @code{ino_t} values, not a single value. -@item -To partially work around the previous two problems, you can test for -nonzero @code{st_ino} and use the Gnulib @code{same-inode} module to -compare nonzero values. For example, @code{SAME_INODE (a, b)} -is true if the @code{struct stat} values @code{a} and -@code{b} are known to represent the same file, @code{(a.st_ino && -!SAME_INODE (a, b))} is true if they are known to represent different -files, and @code{!a.st_ino} is true if it is not known whether they -represent different files. +@code{b} are known to represent the same file. @item On some platforms, two different files may have the same @code{st_dev} and @code{st_ino} values, even when @code{st_ino} is nonzero: @@ -70,13 +69,20 @@ Network Appliance NFS servers in snapshot directories; see Network Appliance bug #195. @item ClearCase MVFS; see bug id ATRia04618. -@end itemize -One partial workaround is to compare other file metadata such as -@code{st_mode} and @code{st_mtime} to detect this bug, but this -approach does not work on files whose metadata are being changed by -other programs. @item On some file systems, @code{st_size} contains bogus information for symlinks; use the Gnulib module @code{areadlink-with-size} for a better way to get symlink contents. @end itemize + +To partially work around porting problems with Microsoft Windows and OpenVMS, +you can use the Gnulib @code{same-inode} module to test whether two +@code{struct stat} objects are known to represent the same file. +For example, @code{psame_inode (&a, &b)} is true if the @code{struct stat} +objects @code{a} and @code{b} are known to represent the same file. + +Another partial workaround is to compare other file metadata such as +@code{st_mode} and @code{st_mtime} on platforms where @code{st_dev} +and @code{st_ino} not uniquely identify a file. However, this does +not work reliably on files whose metadata are being changed by other +programs, or where the metadata happen to be equal. diff --git a/doc/stat-size.texi b/doc/stat-size.texi index 17b5be97f6..80d8ae14ba 100644 --- a/doc/stat-size.texi +++ b/doc/stat-size.texi @@ -9,17 +9,21 @@ intended for interpreting the file size information in an instance of @c Youngman as if the ST_NBLOCKSIZE macro should be used instead). @findex ST_NBLOCKS +@findex STP_NBLOCKS @findex ST_NBLOCKSIZE @cindex block size On POSIX systems, the @code{st_blocks} member of @code{struct stat} contains the number of disk blocks occupied by a file. The -@code{ST_NBLOCKS} macro is used to estimate this quantity on systems +@code{ST_NBLOCKS} and @code{STP_NBLOCKS} macros +estimate this quantity on systems which don't actually have @code{st_blocks}. Each of these blocks contains @code{ST_NBLOCKSIZE} bytes. @findex ST_BLKSIZE +@findex STP_BLKSIZE The value of @code{ST_NBLOCKSIZE} is often quite small, small enough that performing I/O in chunks that size would be inefficient. -@code{ST_BLKSIZE} is the I/O block size recommended for I/O to this +The @code{ST_BLKSIZE} and @code{STP_BLKSIZE} macros +give the I/O block size recommended for I/O to this file. This is not guaranteed to give optimum performance, but it should be reasonably efficient. diff --git a/lib/at-func2.c b/lib/at-func2.c index bea7ea6ce6..bdec139bdf 100644 --- a/lib/at-func2.c +++ b/lib/at-func2.c @@ -132,7 +132,7 @@ at_func2 (int fd1, char const *file1, errno = ENOTDIR; return -1; } - if (SAME_INODE (st1, st2)) /* Reduced to cases 1, 5. */ + if (psame_inode (&st1, &st2)) /* Reduced to cases 1, 5. */ return func (file1, file2); } else if (fd2 == AT_FDCWD) /* Cases 12, 13. */ @@ -144,7 +144,7 @@ at_func2 (int fd1, char const *file1, errno = ENOTDIR; return -1; } - if (SAME_INODE (st1, st2)) /* Reduced to cases 4, 5. */ + if (psame_inode (&st1, &st2)) /* Reduced to cases 4, 5. */ return func (file1, file2); } else if (fd1 != fd2) /* Case 15b. */ @@ -156,10 +156,10 @@ at_func2 (int fd1, char const *file1, errno = ENOTDIR; return -1; } - if (SAME_INODE (st1, st2)) /* Reduced to case 15a. */ + if (psame_inode (&st1, &st2)) /* Reduced to case 15a. */ { fd2 = fd1; - if (stat (".", &st1) == 0 && SAME_INODE (st1, st2)) + if (stat (".", &st1) == 0 && psame_inode (&st1, &st2)) return func (file1, file2); /* Further reduced to case 5. */ } } @@ -172,7 +172,7 @@ at_func2 (int fd1, char const *file1, errno = ENOTDIR; return -1; } - if (stat (".", &st2) == 0 && SAME_INODE (st1, st2)) + if (stat (".", &st2) == 0 && psame_inode (&st1, &st2)) return func (file1, file2); /* Reduced to case 5. */ } diff --git a/lib/fts.c b/lib/fts.c index faeb4b20a5..d66c134fb8 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -1714,7 +1714,7 @@ same_fd (int fd1, int fd2) struct stat sb1, sb2; return (fstat (fd1, &sb1) == 0 && fstat (fd2, &sb2) == 0 - && SAME_INODE (sb1, sb2)); + && psame_inode (&sb1, &sb2)); } static void diff --git a/lib/hash-triple-simple.c b/lib/hash-triple-simple.c index b0fd31dc3a..4b8016049b 100644 --- a/lib/hash-triple-simple.c +++ b/lib/hash-triple-simple.c @@ -46,7 +46,7 @@ triple_compare_ino_str (void const *x, void const *y) { struct F_triple const *a = x; struct F_triple const *b = y; - return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false; + return PSAME_INODE (a, b) && STREQ (a->name, b->name); } /* Free an F_triple. */ diff --git a/lib/hash-triple.c b/lib/hash-triple.c index 3e51b5992e..523c07ab17 100644 --- a/lib/hash-triple.c +++ b/lib/hash-triple.c @@ -40,5 +40,5 @@ triple_compare (void const *x, void const *y) { struct F_triple const *a = x; struct F_triple const *b = y; - return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false; + return PSAME_INODE (a, b) && same_name (a->name, b->name); } diff --git a/lib/rename.c b/lib/rename.c index aa3afd8768..a1dcc004bb 100644 --- a/lib/rename.c +++ b/lib/rename.c @@ -351,7 +351,7 @@ rpl_rename (char const *src, char const *dst) return -1; } # if RENAME_HARD_LINK_BUG - if (SAME_INODE (src_st, dst_st)) + if (psame_inode (&src_st, &dst_st)) return 0; # endif /* RENAME_HARD_LINK_BUG */ dst_exists = true; diff --git a/lib/same-inode.c b/lib/same-inode.c new file mode 100644 index 0000000000..08c66a2586 --- /dev/null +++ b/lib/same-inode.c @@ -0,0 +1,3 @@ +#include +#define SAME_INODE_INLINE _GL_EXTERN_INLINE +#include "same-inode.h" diff --git a/lib/same-inode.h b/lib/same-inode.h index 10964f00fc..2518f4b1ac 100644 --- a/lib/same-inode.h +++ b/lib/same-inode.h @@ -16,32 +16,70 @@ along with this program. If not, see . */ #ifndef SAME_INODE_H -# define SAME_INODE_H 1 - -# include - -# if defined __VMS && __CRTL_VER < 80200000 -# define SAME_INODE(a, b) \ - ((a).st_ino[0] == (b).st_ino[0] \ - && (a).st_ino[1] == (b).st_ino[1] \ - && (a).st_ino[2] == (b).st_ino[2] \ - && (a).st_dev == (b).st_dev) -# elif defined _WIN32 && ! defined __CYGWIN__ - /* Native Windows. */ -# if _GL_WINDOWS_STAT_INODES - /* stat() and fstat() set st_dev and st_ino to 0 if information about - the inode is not available. */ -# define SAME_INODE(a, b) \ - (!((a).st_ino == 0 && (a).st_dev == 0) \ - && (a).st_ino == (b).st_ino && (a).st_dev == (b).st_dev) +#define SAME_INODE_H 1 + +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + +#include + +_GL_INLINE_HEADER_BEGIN +#ifndef SAME_INODE_INLINE +# define SAME_INODE_INLINE _GL_INLINE +#endif + +/* True if A and B point to structs with st_dev and st_ino members + that are known to represent the same file. + + Use | and ^ to shorten generated code, and to lessen the + probability of screwups if st_ino is an array. */ + +#if defined __VMS && __CRTL_VER < 80200000 +# define PSAME_INODE(a, b) (! (((a)->st_dev ^ (b)->st_dev) \ + | ((a)->st_ino[0] ^ (b)->st_ino[0]) \ + | ((a)->st_ino[1] ^ (b)->st_ino[1]) \ + | ((a)->st_ino[2] ^ (b)->st_ino[2]))) +#elif defined _WIN32 && ! defined __CYGWIN__ + /* Native Windows. */ +# if _GL_WINDOWS_STAT_INODES + /* stat() and fstat() set st_dev and st_ino to 0 if information about + the inode is not available. */ +# if _GL_WINDOWS_STAT_INODES == 2 +# define PSAME_INODE(a, b) \ + (! (! ((a)->st_dev | (a)->st_ino._gl_ino[0] | (a)->st_ino._gl_ino[1]) \ + | ((a)->st_dev ^ (b)->st_dev) \ + | ((a)->st_ino._gl_ino[0] ^ (b)->st_ino._gl_ino[0]) \ + | ((a)->st_ino._gl_ino[1] ^ (b)->st_ino._gl_ino[1]))) # else - /* stat() and fstat() set st_ino to 0 always. */ -# define SAME_INODE(a, b) 0 +# define PSAME_INODE(a, b) (! (! ((a)->st_dev | (a)->st_ino) \ + | ((a)->st_dev ^ (b)->st_dev) \ + | ((a)->st_ino ^ (b)->st_ino))) # endif # else -# define SAME_INODE(a, b) \ - ((a).st_ino == (b).st_ino \ - && (a).st_dev == (b).st_dev) + /* stat() and fstat() set st_ino to 0 always. */ +# define PSAME_INODE(a, b) 0 # endif +#else + /* POSIX. */ +# define PSAME_INODE(a, b) (! (((a)->st_dev ^ (b)->st_dev) \ + | ((a)->st_ino ^ (b)->st_ino))) +#endif + +/* True if struct objects A and B are known to represent the same file. */ + +#define SAME_INODE(a, b) PSAME_INODE (&(a), &(b)) + +/* True if *A and *B represent the same file. Unlike PSAME_INODE, + args are evaluated once and must point to struct stat. */ + +SAME_INODE_INLINE bool +psame_inode (struct stat const *a, struct stat const *b) +{ + return PSAME_INODE (a, b); +} + +_GL_INLINE_HEADER_END #endif diff --git a/lib/same.c b/lib/same.c index 65c9d4ffa3..82a5cc3cff 100644 --- a/lib/same.c +++ b/lib/same.c @@ -111,7 +111,7 @@ same_nameat (int source_dfd, char const *source, int destdir_fd = openat (dest_dfd, dest_dirname, open_flags); if (destdir_fd < 0 || fstat (destdir_fd, &dest_dir_stats) != 0) destdir_errno = errno; - else if (SAME_INODE (source_dir_stats, dest_dir_stats)) + else if (psame_inode (&source_dir_stats, &dest_dir_stats)) { same = identical_basenames; if (! same) @@ -138,7 +138,7 @@ same_nameat (int source_dfd, char const *source, /* Shouldn't happen. */ error (1, errno, "%s", dest_dirname); } - same = SAME_INODE (source_dir_stats, dest_dir_stats); + same = psame_inode (&source_dir_stats, &dest_dir_stats); #endif free (dest_dirname); diff --git a/lib/stat-size.h b/lib/stat-size.h index bda00b7289..8f2b47f3e4 100644 --- a/lib/stat-size.h +++ b/lib/stat-size.h @@ -1,4 +1,4 @@ -/* macros useful in interpreting size-related values in struct stat. +/* Yield size-related values in struct stat. Copyright (C) 1989, 1991-2023 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -13,15 +13,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/* - Macros defined by this file (s is an rvalue of type struct stat): - DEV_BSIZE: The device blocksize. But use ST_NBLOCKSIZE instead. - ST_BLKSIZE(s): Preferred (in the sense of best performance) I/O blocksize - for the file, in bytes. - ST_NBLOCKS(s): Number of blocks in the file, including indirect blocks. - ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. - */ #ifndef STAT_SIZE_H #define STAT_SIZE_H @@ -35,8 +27,8 @@ # include #endif - -/* Get or fake the disk device blocksize. +/* The device blocksize, or a faked version thereof. + But use ST_NBLOCKSIZE instead. Usually defined by sys/param.h (if at all). */ #if !defined DEV_BSIZE && defined BSIZE # define DEV_BSIZE BSIZE @@ -48,23 +40,21 @@ # define DEV_BSIZE 4096 #endif - - -/* Extract or fake data from a 'struct stat'. - ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes. - ST_NBLOCKS: Number of blocks in the file, including indirect blocks. +/* Extract or fake data from a struct stat *st. + STP_BLKSIZE(st): Preferred performance I/O blocksize, in bytes. + STP_NBLOCKS(st): Number of blocks, including indirect blocks. ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */ #ifndef HAVE_STRUCT_STAT_ST_BLOCKS -# define ST_BLKSIZE(statbuf) DEV_BSIZE +# define STP_BLKSIZE(st) DEV_BSIZE /* coreutils' fileblocks.c also uses BSIZE. */ # if defined _POSIX_SOURCE || !defined BSIZE -# define ST_NBLOCKS(statbuf) \ - ((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0)) +# define STP_NBLOCKS(st) \ + ((st)->st_size / ST_NBLOCKSIZE + ((st)->st_size % ST_NBLOCKSIZE != 0)) # else /* This definition calls st_blocks, which is in the fileblocks module. */ -# define ST_NBLOCKS(statbuf) \ - (S_ISREG ((statbuf).st_mode) || S_ISDIR ((statbuf).st_mode) ? \ - st_blocks ((statbuf).st_size) : 0) +# define STP_NBLOCKS(st) \ + (S_ISREG ((st)->st_mode) || S_ISDIR ((st)->st_mode) \ + ? st_blocks ((st)->st_size) : 0) # endif #else /* When running 'rsh hpux11-system cat any-file', cat would @@ -75,9 +65,9 @@ suffice, since "cat" sometimes multiplies the result by 4.) If anyone knows of a system for which this limit is too small, please report it as a bug in this code. */ -# define ST_BLKSIZE(statbuf) ((0 < (statbuf).st_blksize \ - && (statbuf).st_blksize <= ((size_t)-1) / 8 + 1) \ - ? (statbuf).st_blksize : DEV_BSIZE) +# define STP_BLKSIZE(st) ((0 < (st)->st_blksize \ + && (st)->st_blksize <= (size_t) -1 / 8 + 1) \ + ? (st)->st_blksize : DEV_BSIZE) # if defined hpux || defined __hpux__ || defined __hpux /* HP-UX counts st_blocks in 1024-byte units. This loses when mixing HP-UX and BSD file systems with NFS. */ @@ -85,8 +75,8 @@ # endif #endif -#ifndef ST_NBLOCKS -# define ST_NBLOCKS(statbuf) ((statbuf).st_blocks) +#ifndef STP_NBLOCKS +# define STP_NBLOCKS(st) ((st)->st_blocks) #endif #ifndef ST_NBLOCKSIZE @@ -97,4 +87,8 @@ # endif #endif +/* Preferred blocksize and number of blocks for a struct stat object. */ +#define ST_BLKSIZE(statbuf) STP_BLKSIZE (&(statbuf)) +#define ST_NBLOCKS(statbuf) STP_NBLOCKS (&(statbuf)) + #endif /* STAT_SIZE_H */ diff --git a/lib/term-style-control.c b/lib/term-style-control.c index 18259c827c..454e72e383 100644 --- a/lib/term-style-control.c +++ b/lib/term-style-control.c @@ -225,7 +225,10 @@ log_signal_handler_called (int sig) #else -# define log_signal_handler_called(sig) +static void +log_signal_handler_called (_GL_UNUSED int sig) +{ +} #endif @@ -970,7 +973,7 @@ activate_term_style_controller (const struct term_style_controller *controller, if (fd == STDERR_FILENO || (fstat (fd, &statbuf1) >= 0 && fstat (STDERR_FILENO, &statbuf2) >= 0 - && SAME_INODE (statbuf1, statbuf2))) + && psame_inode (&statbuf1, &statbuf2))) control_data->same_as_stderr = true; else control_data->same_as_stderr = false; diff --git a/modules/canonicalize-lgpl-tests b/modules/canonicalize-lgpl-tests index 73a0e32abb..409ee7225b 100644 --- a/modules/canonicalize-lgpl-tests +++ b/modules/canonicalize-lgpl-tests @@ -1,4 +1,5 @@ Files: +m4/musl.m4 tests/test-canonicalize-lgpl.c tests/signature.h tests/null-ptr.h @@ -10,6 +11,7 @@ same-inode symlink configure.ac: +gl_MUSL_LIBC Makefile.am: TESTS += test-canonicalize-lgpl diff --git a/modules/same-inode b/modules/same-inode index 53964d0409..f31ade64fc 100644 --- a/modules/same-inode +++ b/modules/same-inode @@ -2,14 +2,18 @@ Description: compare inodes Files: +lib/same-inode.c lib/same-inode.h Depends-on: +extern-inline +stdbool sys_types configure.ac: Makefile.am: +lib_SOURCES += same-inode.h same-inode.c Include: "same-inode.h" diff --git a/tests/test-binary-io.c b/tests/test-binary-io.c index a474d37179..97b2f27bda 100644 --- a/tests/test-binary-io.c +++ b/tests/test-binary-io.c @@ -30,7 +30,7 @@ #include "macros.h" int -main (int argc, char *argv[]) +main (_GL_UNUSED int argc, char *argv[]) { /* Test the O_BINARY macro. */ { diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index 9d249dff54..1216ee212c 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -261,16 +261,18 @@ main (void) ASSERT (result2); ASSERT (stat ("/", &st1) == 0); ASSERT (stat ("//", &st2) == 0); - /* On IBM z/OS, "/" and "//" are distinct, yet they both have - st_dev == st_ino == 1. */ -#ifndef __MVS__ - if (SAME_INODE (st1, st2)) + bool same = psame_inode (&st1, &st2); +#if defined __MVS__ || defined MUSL_LIBC + /* On IBM z/OS and musl libc, "/" and "//" both canonicalize to + themselves, yet they both have st_dev == st_ino == 1. */ + same = false; +#endif + if (same) { ASSERT (strcmp (result1, "/") == 0); ASSERT (strcmp (result2, "/") == 0); } else -#endif { ASSERT (strcmp (result1, "//") == 0); ASSERT (strcmp (result2, "//") == 0); diff --git a/tests/test-canonicalize.c b/tests/test-canonicalize.c index 8c5207ff7d..5a2ea998dc 100644 --- a/tests/test-canonicalize.c +++ b/tests/test-canonicalize.c @@ -393,7 +393,13 @@ main (void) ASSERT (result4); ASSERT (stat ("/", &st1) == 0); ASSERT (stat ("//", &st2) == 0); - if (SAME_INODE (st1, st2)) + bool same = psame_inode (&st1, &st2); +#if defined __MVS__ || defined MUSL_LIBC + /* On IBM z/OS and musl libc, "/" and "//" both canonicalize to + themselves, yet they both have st_dev == st_ino == 1. */ + same = false; +#endif + if (same) { ASSERT (strcmp (result1, "/") == 0); ASSERT (strcmp (result2, "/") == 0); diff --git a/tests/test-cloexec.c b/tests/test-cloexec.c index e8c8eb61a6..b859db03ee 100644 --- a/tests/test-cloexec.c +++ b/tests/test-cloexec.c @@ -62,8 +62,12 @@ is_inheritable (int fd) } #if !O_BINARY -# define set_binary_mode(f,m) zero () -static int zero (void) { return 0; } +# define set_binary_mode my_set_binary_mode +static int +set_binary_mode (_GL_UNUSED int fd, _GL_UNUSED int mode) +{ + return 0; +} #endif /* Return non-zero if FD is open in the given MODE, which is either diff --git a/tests/test-dup-safer.c b/tests/test-dup-safer.c index c2de3003ff..334f82c3b1 100644 --- a/tests/test-dup-safer.c +++ b/tests/test-dup-safer.c @@ -41,8 +41,12 @@ #endif #if !O_BINARY -# define set_binary_mode(f,m) zero () -static int zero (void) { return 0; } +# define set_binary_mode my_set_binary_mode +static int +set_binary_mode (_GL_UNUSED int fd, _GL_UNUSED int mode) +{ + return 0; +} #endif /* This test intentionally closes stderr. So, we arrange to have fd 10 diff --git a/tests/test-dup2.c b/tests/test-dup2.c index 8acbc038ca..8d2467f493 100644 --- a/tests/test-dup2.c +++ b/tests/test-dup2.c @@ -98,8 +98,12 @@ is_inheritable (int fd) #endif /* GNULIB_TEST_CLOEXEC */ #if !O_BINARY -# define set_binary_mode(f,m) zero () -static int zero (void) { return 0; } +# define set_binary_mode my_set_binary_mode +static int +set_binary_mode (_GL_UNUSED int fd, _GL_UNUSED int mode) +{ + return 0; +} #endif /* Return non-zero if FD is open in the given MODE, which is either diff --git a/tests/test-error.c b/tests/test-error.c index 697e783eee..463b1915c4 100644 --- a/tests/test-error.c +++ b/tests/test-error.c @@ -31,7 +31,7 @@ print_no_progname (void) } int -main (int argc, char *argv[]) +main () { /* Test error() function with zero STATUS and zero ERRNUM. */ error (0, 0, "bummer"); diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c index 5fb554afe7..7b63cc7ced 100644 --- a/tests/test-fcntl.c +++ b/tests/test-fcntl.c @@ -51,8 +51,12 @@ SIGNATURE_CHECK (fcntl, int, (int, int, ...)); #endif #if !O_BINARY -# define set_binary_mode(f,m) zero () -static int zero (void) { return 0; } +# define set_binary_mode my_set_binary_mode +static int +set_binary_mode (_GL_UNUSED int fd, _GL_UNUSED int mode) +{ + return 0; +} #endif /* Return true if FD is open. */ @@ -217,7 +221,7 @@ check_flags (void) } int -main (int argc, char *argv[]) +main (int argc, _GL_UNUSED char *argv[]) { if (argc > 1) /* child process */ diff --git a/tests/test-fdopendir.c b/tests/test-fdopendir.c index 41b15f3e77..88b912cf5d 100644 --- a/tests/test-fdopendir.c +++ b/tests/test-fdopendir.c @@ -30,7 +30,7 @@ SIGNATURE_CHECK (fdopendir, DIR *, (int)); #include "macros.h" int -main (_GL_UNUSED int argc, char *argv[]) +main () { DIR *d; int fd; diff --git a/tests/test-fgetc.c b/tests/test-fgetc.c index c8c65f58aa..169451410b 100644 --- a/tests/test-fgetc.c +++ b/tests/test-fgetc.c @@ -32,7 +32,7 @@ SIGNATURE_CHECK (fgetc, int, (FILE *)); #include "macros.h" int -main (int argc, char **argv) +main () { const char *filename = "test-fgetc.txt"; diff --git a/tests/test-fputc.c b/tests/test-fputc.c index 3a9e7c38ac..ae7c718014 100644 --- a/tests/test-fputc.c +++ b/tests/test-fputc.c @@ -32,7 +32,7 @@ SIGNATURE_CHECK (fputc, int, (int, FILE *)); #include "macros.h" int -main (int argc, char **argv) +main () { const char *filename = "test-fputc.txt"; diff --git a/tests/test-fread.c b/tests/test-fread.c index d6d16ec3d9..8bdb551487 100644 --- a/tests/test-fread.c +++ b/tests/test-fread.c @@ -32,7 +32,7 @@ SIGNATURE_CHECK (fread, size_t, (void *, size_t, size_t, FILE *)); #include "macros.h" int -main (int argc, char **argv) +main () { const char *filename = "test-fread.txt"; diff --git a/tests/test-fstat.c b/tests/test-fstat.c index 59c2dc4d1a..9a7b521f8e 100644 --- a/tests/test-fstat.c +++ b/tests/test-fstat.c @@ -27,7 +27,7 @@ SIGNATURE_CHECK (fstat, int, (int, struct stat *)); #include "macros.h" int -main (int argc, char *argv[]) +main () { /* Test behaviour for invalid file descriptors. */ { diff --git a/tests/test-fstatat.c b/tests/test-fstatat.c index fe8a694076..684681d389 100644 --- a/tests/test-fstatat.c +++ b/tests/test-fstatat.c @@ -66,7 +66,7 @@ do_lstat (char const *name, struct stat *st) } int -main (_GL_UNUSED int argc, char *argv[]) +main (_GL_UNUSED int argc, _GL_UNUSED char *argv[]) { int result; diff --git a/tests/test-ftruncate.c b/tests/test-ftruncate.c index bcd63932fa..ae6444a557 100644 --- a/tests/test-ftruncate.c +++ b/tests/test-ftruncate.c @@ -27,7 +27,7 @@ SIGNATURE_CHECK (ftruncate, int, (int, off_t)); #include "macros.h" int -main (int argc, char *argv[]) +main (_GL_UNUSED int argc, char *argv[]) { const char *filename = argv[1]; diff --git a/tests/test-fwrite.c b/tests/test-fwrite.c index 503e849b47..4e097fff7a 100644 --- a/tests/test-fwrite.c +++ b/tests/test-fwrite.c @@ -32,7 +32,7 @@ SIGNATURE_CHECK (fwrite, size_t, (const void *, size_t, size_t, FILE *)); #include "macros.h" int -main (int argc, char **argv) +main () { const char *filename = "test-fwrite.txt"; diff --git a/tests/test-getcwd.c b/tests/test-getcwd.c index aa510d4e45..090fa02723 100644 --- a/tests/test-getcwd.c +++ b/tests/test-getcwd.c @@ -262,7 +262,7 @@ test_long_name (void) } int -main (int argc, char **argv) +main () { int err1 = test_abort_bug (); int err2 = test_long_name (); diff --git a/tests/test-getdtablesize.c b/tests/test-getdtablesize.c index d2c93f19a4..82f3a19535 100644 --- a/tests/test-getdtablesize.c +++ b/tests/test-getdtablesize.c @@ -31,7 +31,7 @@ SIGNATURE_CHECK (getdtablesize, int, (void)); #endif int -main (int argc, char *argv[]) +main () { ASSERT (getdtablesize () >= 3); ASSERT (dup2 (0, getdtablesize() - 1) == getdtablesize () - 1); diff --git a/tests/test-isblank.c b/tests/test-isblank.c index 5f2a1838f8..6f20716202 100644 --- a/tests/test-isblank.c +++ b/tests/test-isblank.c @@ -29,7 +29,7 @@ SIGNATURE_CHECK (isblank, int, (int)); #include "macros.h" int -main (int argc, char *argv[]) +main () { unsigned int c; diff --git a/tests/test-linkat.c b/tests/test-linkat.c index 44c1bb945e..4c8d365d88 100644 --- a/tests/test-linkat.c +++ b/tests/test-linkat.c @@ -78,7 +78,7 @@ check_same_link (char const *name1, char const *name2) ASSERT (contents2); ASSERT (strcmp (contents1, contents2) == 0); if (EXPECT_LINK_HARDLINKS_SYMLINKS) - ASSERT (SAME_INODE (st1, st2)); + ASSERT (psame_inode (&st1, &st2)); free (contents1); free (contents2); } diff --git a/tests/test-lock.c b/tests/test-lock.c index b52f7e0cd8..d7fcec0235 100644 --- a/tests/test-lock.c +++ b/tests/test-lock.c @@ -143,7 +143,7 @@ check_accounts (void) gl_lock_define_initialized(static, my_lock) static void * -lock_mutator_thread (void *arg) +lock_mutator_thread (_GL_UNUSED void *arg) { int repeat; @@ -181,7 +181,7 @@ lock_mutator_thread (void *arg) static struct atomic_int lock_checker_done; static void * -lock_checker_thread (void *arg) +lock_checker_thread (_GL_UNUSED void *arg) { while (get_atomic_int_value (&lock_checker_done) == 0) { @@ -234,7 +234,7 @@ test_lock (void) gl_rwlock_define_initialized(static, my_rwlock) static void * -rwlock_mutator_thread (void *arg) +rwlock_mutator_thread (_GL_UNUSED void *arg) { int repeat; @@ -266,7 +266,7 @@ rwlock_mutator_thread (void *arg) static struct atomic_int rwlock_checker_done; static void * -rwlock_checker_thread (void *arg) +rwlock_checker_thread (_GL_UNUSED void *arg) { while (get_atomic_int_value (&rwlock_checker_done) == 0) { @@ -345,7 +345,7 @@ recshuffle (void) } static void * -reclock_mutator_thread (void *arg) +reclock_mutator_thread (_GL_UNUSED void *arg) { int repeat; @@ -369,7 +369,7 @@ reclock_mutator_thread (void *arg) static struct atomic_int reclock_checker_done; static void * -reclock_checker_thread (void *arg) +reclock_checker_thread (_GL_UNUSED void *arg) { while (get_atomic_int_value (&reclock_checker_done) == 0) { diff --git a/tests/test-lstat.h b/tests/test-lstat.h index 8a367678c4..fb7287e413 100644 --- a/tests/test-lstat.h +++ b/tests/test-lstat.h @@ -32,14 +32,14 @@ test_lstat_func (int (*func) (char const *, struct stat *), bool print) ASSERT (func (".", &st1) == 0); ASSERT (func ("./", &st2) == 0); #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES) - ASSERT (SAME_INODE (st1, st2)); + ASSERT (psame_inode (&st1, &st2)); #endif ASSERT (S_ISDIR (st1.st_mode)); ASSERT (S_ISDIR (st2.st_mode)); ASSERT (func ("/", &st1) == 0); ASSERT (func ("///", &st2) == 0); #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES) - ASSERT (SAME_INODE (st1, st2)); + ASSERT (psame_inode (&st1, &st2)); #endif ASSERT (S_ISDIR (st1.st_mode)); ASSERT (S_ISDIR (st2.st_mode)); @@ -90,7 +90,7 @@ test_lstat_func (int (*func) (char const *, struct stat *), bool print) ASSERT (S_ISDIR (st1.st_mode)); ASSERT (S_ISDIR (st2.st_mode)); #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES) - ASSERT (SAME_INODE (st1, st2)); + ASSERT (psame_inode (&st1, &st2)); #endif ASSERT (func (BASE "link2", &st1) == 0); diff --git a/tests/test-malloc-gnu.c b/tests/test-malloc-gnu.c index e2462dad48..48284d0b34 100644 --- a/tests/test-malloc-gnu.c +++ b/tests/test-malloc-gnu.c @@ -25,7 +25,7 @@ #include "macros.h" int -main (int argc, char **argv) +main (int argc, _GL_UNUSED char **argv) { /* Check that malloc (0) is not a NULL pointer. */ void *volatile p = malloc (0); diff --git a/tests/test-openat.c b/tests/test-openat.c index ff6cd988fc..7a54fa8d58 100644 --- a/tests/test-openat.c +++ b/tests/test-openat.c @@ -57,7 +57,7 @@ do_open (char const *name, int flags, ...) } int -main (_GL_UNUSED int argc, char *argv[]) +main () { int result; diff --git a/tests/test-pthread-thread.c b/tests/test-pthread-thread.c index 5a5bce5691..02c637e9d1 100644 --- a/tests/test-pthread-thread.c +++ b/tests/test-pthread-thread.c @@ -33,7 +33,7 @@ static pthread_t worker_thread; static volatile int work_done; static void * -worker_thread_func (void *arg) +worker_thread_func (_GL_UNUSED void *arg) { work_done = 1; return MAGIC; diff --git a/tests/test-pthread_sigmask1.c b/tests/test-pthread_sigmask1.c index b1b6eb5ab9..06158f9d58 100644 --- a/tests/test-pthread_sigmask1.c +++ b/tests/test-pthread_sigmask1.c @@ -36,13 +36,13 @@ SIGNATURE_CHECK (pthread_sigmask, int, (int, const sigset_t *, sigset_t *)); static volatile int sigint_occurred; static void -sigint_handler (int sig) +sigint_handler (_GL_UNUSED int sig) { sigint_occurred++; } int -main (int argc, char *argv[]) +main () { sigset_t set; pid_t pid = getpid (); diff --git a/tests/test-pthread_sigmask2.c b/tests/test-pthread_sigmask2.c index 94f951f323..f126690bca 100644 --- a/tests/test-pthread_sigmask2.c +++ b/tests/test-pthread_sigmask2.c @@ -33,7 +33,7 @@ static pthread_t main_thread; static pthread_t killer_thread; static void * -killer_thread_func (void *arg) +killer_thread_func (_GL_UNUSED void *arg) { sleep (1); pthread_kill (main_thread, SIGINT); @@ -43,13 +43,13 @@ killer_thread_func (void *arg) static volatile int sigint_occurred; static void -sigint_handler (int sig) +sigint_handler (_GL_UNUSED int sig) { sigint_occurred++; } int -main (int argc, char *argv[]) +main () { sigset_t set; diff --git a/tests/test-ptsname.c b/tests/test-ptsname.c index 142b6a0a1d..75647c352b 100644 --- a/tests/test-ptsname.c +++ b/tests/test-ptsname.c @@ -50,7 +50,7 @@ same_slave (const char *slave_name1, const char *slave_name2) return (strcmp (slave_name1, slave_name2) == 0 || (stat (slave_name1, &statbuf1) >= 0 && stat (slave_name2, &statbuf2) >= 0 - && SAME_INODE (statbuf1, statbuf2))); + && psame_inode (&statbuf1, &statbuf2))); } int diff --git a/tests/test-ptsname_r.c b/tests/test-ptsname_r.c index 9806b53eb7..cd2605f618 100644 --- a/tests/test-ptsname_r.c +++ b/tests/test-ptsname_r.c @@ -59,7 +59,7 @@ same_slave (const char *slave_name1, const char *slave_name2) return (strcmp (slave_name1, slave_name2) == 0 || (stat (slave_name1, &statbuf1) >= 0 && stat (slave_name2, &statbuf2) >= 0 - && SAME_INODE (statbuf1, statbuf2))); + && psame_inode (&statbuf1, &statbuf2))); } static void diff --git a/tests/test-raise.c b/tests/test-raise.c index 7574b2b4a4..97be64dd2c 100644 --- a/tests/test-raise.c +++ b/tests/test-raise.c @@ -30,7 +30,7 @@ SIGNATURE_CHECK (raise, int, (int)); exit() is a non-returning function, even on platforms where its declaration in does not have the 'noreturn' attribute. */ static _Noreturn void -handler (int sig) +handler (_GL_UNUSED int sig) { _exit (0); } diff --git a/tests/test-realloc-gnu.c b/tests/test-realloc-gnu.c index 28afc628de..435f10b610 100644 --- a/tests/test-realloc-gnu.c +++ b/tests/test-realloc-gnu.c @@ -25,7 +25,7 @@ #include "macros.h" int -main (int argc, char **argv) +main (int argc, _GL_UNUSED char **argv) { /* Check that realloc (NULL, 0) is not a NULL pointer. */ void *volatile p = realloc (NULL, 0); diff --git a/tests/test-rwlock1.c b/tests/test-rwlock1.c index a5675317d3..26ff878f2e 100644 --- a/tests/test-rwlock1.c +++ b/tests/test-rwlock1.c @@ -73,7 +73,7 @@ static gl_thread_t timer; static gl_lock_t baton; static void * -timer_func (void *ignored) +timer_func (_GL_UNUSED void *ignored) { /* Step 13 (can be before or after step 12): The timer thread takes the baton, then waits a moment to make sure @@ -87,7 +87,7 @@ timer_func (void *ignored) } static void * -reader2_func (void *ignored) +reader2_func (_GL_UNUSED void *ignored) { int err; @@ -113,7 +113,7 @@ reader2_func (void *ignored) } static void * -writer_func (void *ignored) +writer_func (_GL_UNUSED void *ignored) { /* Step 4: Take the baton, so that the second reader thread does not go ahead too early. */ diff --git a/tests/test-sigprocmask.c b/tests/test-sigprocmask.c index b6d0114c8b..640a8e2eb0 100644 --- a/tests/test-sigprocmask.c +++ b/tests/test-sigprocmask.c @@ -36,13 +36,13 @@ SIGNATURE_CHECK (sigprocmask, int, (int, const sigset_t *, sigset_t *)); static volatile int sigint_occurred; static void -sigint_handler (int sig) +sigint_handler (_GL_UNUSED int sig) { sigint_occurred++; } int -main (int argc, char *argv[]) +main () { sigset_t set; pid_t pid = getpid (); diff --git a/tests/test-snprintf.c b/tests/test-snprintf.c index d106ad65dd..3b67925488 100644 --- a/tests/test-snprintf.c +++ b/tests/test-snprintf.c @@ -28,7 +28,7 @@ SIGNATURE_CHECK (snprintf, int, (char *, size_t, char const *, ...)); #include "macros.h" int -main (int argc, char *argv[]) +main () { char buf[8]; int size; diff --git a/tests/test-stat.h b/tests/test-stat.h index f2132c2a35..7cdc44b8f6 100644 --- a/tests/test-stat.h +++ b/tests/test-stat.h @@ -33,16 +33,16 @@ test_stat_func (int (*func) (char const *, struct stat *), bool print) ASSERT (func (".", &st1) == 0); ASSERT (func ("./", &st2) == 0); #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES) - ASSERT (SAME_INODE (st1, st2)); + ASSERT (psame_inode (&st1, &st2)); #endif ASSERT (func (cwd, &st2) == 0); #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES) - ASSERT (SAME_INODE (st1, st2)); + ASSERT (psame_inode (&st1, &st2)); #endif ASSERT (func ("/", &st1) == 0); ASSERT (func ("///", &st2) == 0); #if !(defined _WIN32 && !defined __CYGWIN__ && !_GL_WINDOWS_STAT_INODES) - ASSERT (SAME_INODE (st1, st2)); + ASSERT (psame_inode (&st1, &st2)); #endif errno = 0; diff --git a/tests/test-term-style-control-hello.c b/tests/test-term-style-control-hello.c index b9004ea41d..0db9dc4984 100644 --- a/tests/test-term-style-control-hello.c +++ b/tests/test-term-style-control-hello.c @@ -56,7 +56,7 @@ get_control_data (struct term_style_user_data *user_data) } static void -restore (struct term_style_user_data *user_data) +restore (_GL_UNUSED struct term_style_user_data *user_data) { fputs (set_underline_off, stdout); fputs (set_background_color_default, stdout); @@ -64,7 +64,7 @@ restore (struct term_style_user_data *user_data) } static _GL_ASYNC_SAFE void -async_restore (struct term_style_user_data *user_data) +async_restore (_GL_UNUSED struct term_style_user_data *user_data) { /* No calls here! */ full_write (STDOUT_FILENO, set_underline_off, @@ -94,7 +94,7 @@ static const struct term_style_controller controller = }; int -main (int argc, char *argv[]) +main () { struct term_style_user_data user_data; diff --git a/tests/test-term-style-control-yes.c b/tests/test-term-style-control-yes.c index 118434c99f..830e8d5c71 100644 --- a/tests/test-term-style-control-yes.c +++ b/tests/test-term-style-control-yes.c @@ -57,7 +57,7 @@ get_control_data (struct term_style_user_data *user_data) } static void -restore (struct term_style_user_data *user_data) +restore (_GL_UNUSED struct term_style_user_data *user_data) { fputs (set_underline_off, stdout); fputs (set_foreground_color_default, stdout); @@ -65,7 +65,7 @@ restore (struct term_style_user_data *user_data) } static _GL_ASYNC_SAFE void -async_restore (struct term_style_user_data *user_data) +async_restore (_GL_UNUSED struct term_style_user_data *user_data) { /* No calls here! */ full_write (STDOUT_FILENO, set_underline_off, @@ -96,7 +96,7 @@ static const struct term_style_controller controller = }; int -main (int argc, char *argv[]) +main () { struct term_style_user_data user_data; diff --git a/tests/test-thread_create.c b/tests/test-thread_create.c index 9312d8e910..d23f010780 100644 --- a/tests/test-thread_create.c +++ b/tests/test-thread_create.c @@ -33,7 +33,7 @@ static int dummy; static volatile int work_done; static void * -worker_thread_func (void *arg) +worker_thread_func (_GL_UNUSED void *arg) { work_done = 1; return &dummy; diff --git a/tests/test-unlinkat.c b/tests/test-unlinkat.c index 22c17e7aed..a21fb465a2 100644 --- a/tests/test-unlinkat.c +++ b/tests/test-unlinkat.c @@ -55,7 +55,7 @@ unlinker (char const *name) } int -main (_GL_UNUSED int argc, char *argv[]) +main () { /* FIXME: Add tests of fd other than ".". */ int result1; diff --git a/tests/test-vasnprintf.c b/tests/test-vasnprintf.c index 635654bb13..97ed573de2 100644 --- a/tests/test-vasnprintf.c +++ b/tests/test-vasnprintf.c @@ -113,7 +113,7 @@ test_asnprintf () } int -main (int argc, char *argv[]) +main () { test_vasnprintf (); test_asnprintf (); diff --git a/tests/test-xalloc-die.c b/tests/test-xalloc-die.c index 07dcb1dbda..10b5abfa42 100644 --- a/tests/test-xalloc-die.c +++ b/tests/test-xalloc-die.c @@ -21,7 +21,7 @@ #include "xalloc.h" int -main (_GL_UNUSED int argc, char **argv) +main () { xalloc_die (); return 0; diff --git a/top/maint.mk b/top/maint.mk index edcf3c7049..1173b64d10 100644 --- a/top/maint.mk +++ b/top/maint.mk @@ -998,12 +998,12 @@ sc_prohibit_empty_lines_at_EOF: exit 1; } \ || : -# Make sure we don't use st_blocks. Use ST_NBLOCKS instead. +# Make sure we don't use st_blocks. Use ST_NBLOCKS or STP_NBLOCKS instead. # This is a bit of a kludge, since it prevents use of the string # even in comments, but for now it does the job with no false positives. sc_prohibit_stat_st_blocks: @prohibit='[.>]st_blocks' \ - halt='do not use st_blocks; use ST_NBLOCKS' \ + halt='do not use st_blocks; use ST_NBLOCKS or STP_NBLOCKS' \ $(_sc_search_regexp) # Make sure we don't define any S_IS* macros in src/*.c files. -- 2.39.5