coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/7] maint: modernize attribute usage


From: Paul Eggert
Subject: [PATCH 4/7] maint: modernize attribute usage
Date: Sun, 31 Oct 2021 22:37:27 -0700

* src/system.h (__attribute__): Remove.  Replace all uses that
rely on this by _GL_ATTRIBUTE_xxx or ATTRIBUTE_xxx.
(ATTRIBUTE_WARN_UNUSED_RESULT): Remove.  Replace all uses by
NODISCARD.
---
 src/prog-fprintf.h |  2 +-
 src/stat.c         | 36 ++++++++++++++++++++++++------------
 src/stty.c         |  4 +---
 src/system.h       | 14 --------------
 4 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/src/prog-fprintf.h b/src/prog-fprintf.h
index f55f8c229..d26334c8f 100644
--- a/src/prog-fprintf.h
+++ b/src/prog-fprintf.h
@@ -20,6 +20,6 @@
 # include <stdio.h>
 
 extern void prog_fprintf (FILE *fp, char const *fmt, ...)
-  __attribute__ ((__format__ (__printf__, 2, 3)));
+  _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3));
 
 #endif
diff --git a/src/stat.c b/src/stat.c
index f4fdc9984..280142b5c 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -107,7 +107,8 @@
 /* BeOS has a statvfs function, but it does not return sensible values
    for f_files, f_ffree and f_favail, and lacks f_type, f_basetype and
    f_fstypename.  Use 'struct fs_info' instead.  */
-static int ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static int
 statfs (char const *filename, struct fs_info *buf)
 {
   dev_t device = dev_for_path (filename);
@@ -256,7 +257,8 @@ print_stat (char *pformat, size_t prefix_len, char mod, 
char m,
    Others have statfs.f_fstypename[MFSNAMELEN] (NetBSD 1.5.2).
    Still others have neither and have to get by with f_type (GNU/Linux).
    But f_type may only exist in statfs (Cygwin).  */
-static char const * ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static char const *
 human_fstype (STRUCT_STATVFS const *statfsbuf)
 {
 #ifdef STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME
@@ -631,7 +633,8 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
 #endif
 }
 
-static char * ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static char *
 human_access (struct stat const *statbuf)
 {
   static char modebuf[12];
@@ -640,7 +643,8 @@ human_access (struct stat const *statbuf)
   return modebuf;
 }
 
-static char * ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static char *
 human_time (struct timespec t)
 {
   /* STR must be at least INT_BUFSIZE_BOUND (intmax_t) big, either
@@ -830,7 +834,8 @@ out_epoch_sec (char *pformat, size_t prefix_len,
 
 /* Print the context information of FILENAME, and return true iff the
    context could not be obtained.  */
-static bool ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static bool
 out_file_context (char *pformat, size_t prefix_len, char const *filename)
 {
   char *scontext;
@@ -853,7 +858,8 @@ out_file_context (char *pformat, size_t prefix_len, char 
const *filename)
 }
 
 /* Print statfs info.  Return zero upon success, nonzero upon failure.  */
-static bool ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static bool
 print_statfs (char *pformat, size_t prefix_len, char mod _GL_UNUSED, char m,
               int fd, char const *filename,
               void const *data)
@@ -941,7 +947,8 @@ print_statfs (char *pformat, size_t prefix_len, char mod 
_GL_UNUSED, char m,
 /* Return any bind mounted source for a path.
    The caller should not free the returned buffer.
    Return NULL if no bind mount found.  */
-static char const * ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static char const *
 find_bind_mount (char const * name)
 {
   char const * bind_mount = NULL;
@@ -980,7 +987,8 @@ find_bind_mount (char const * name)
 }
 
 /* Print mount point.  Return zero upon success, nonzero upon failure.  */
-static bool ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static bool
 out_mount_point (char const *filename, char *pformat, size_t prefix_len,
                  const struct stat *statp)
 {
@@ -1120,7 +1128,8 @@ format_code_offset (char const* directive)
 /* Print the information specified by the format string, FORMAT,
    calling PRINT_FUNC for each %-directive encountered.
    Return zero upon success, nonzero upon failure.  */
-static bool ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static bool
 print_it (char const *format, int fd, char const *filename,
           bool (*print_func) (char *, size_t, char, char,
                               int, char const *, void const *),
@@ -1248,7 +1257,8 @@ print_it (char const *format, int fd, char const 
*filename,
 }
 
 /* Stat the file system and print what we find.  */
-static bool ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static bool
 do_statfs (char const *filename, char const *format)
 {
   STRUCT_STATVFS statfsbuf;
@@ -1356,7 +1366,8 @@ format_to_mask (char const *format)
 }
 
 /* statx the file and print what we find */
-static bool ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static bool
 do_stat (char const *filename, char const *format, char const *format2)
 {
   int fd = STREQ (filename, "-") ? 0 : AT_FDCWD;
@@ -1440,7 +1451,8 @@ get_birthtime (int fd, char const *filename, struct stat 
const *st)
 
 
 /* stat the file and print what we find */
-static bool ATTRIBUTE_WARN_UNUSED_RESULT
+NODISCARD
+static bool
 do_stat (char const *filename, char const *format,
          char const *format2)
 {
diff --git a/src/stty.c b/src/stty.c
index ac38dbb16..9b10eb1ee 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -481,13 +481,11 @@ static struct option const longopts[] =
   {NULL, 0, NULL, 0}
 };
 
-static void wrapf (char const *message, ...)
-     __attribute__ ((__format__ (__printf__, 1, 2)));
-
 /* Print format string MESSAGE and optional args.
    Wrap to next line first if it won't fit.
    Print a space first unless MESSAGE will start a new line. */
 
+ATTRIBUTE_FORMAT ((printf, 1, 2))
 static void
 wrapf (char const *message,...)
 {
diff --git a/src/system.h b/src/system.h
index 8fc13bff0..ce07ab03f 100644
--- a/src/system.h
+++ b/src/system.h
@@ -421,20 +421,6 @@ enum
 # define IF_LINT(Code) /* empty */
 #endif
 
-#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-#  define __attribute__(x) /* empty */
-# endif
-#endif
-
-/* The warn_unused_result attribute appeared first in gcc-3.4.0 */
-#undef ATTRIBUTE_WARN_UNUSED_RESULT
-#if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
-# define ATTRIBUTE_WARN_UNUSED_RESULT /* empty */
-#else
-# define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
-#endif
-
 #ifdef __GNUC__
 # define LIKELY(cond)    __builtin_expect ((cond), 1)
 # define UNLIKELY(cond)  __builtin_expect ((cond), 0)
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]