diff -EBbu ./src/numfmt.c.orig ./src/numfmt.c
-__attribute ((pure))
+__attribute__ ((pure))
Oops. I'll fix this up with a more extensive patch in coreutils.
3 patches attached.
thanks,
Pádraig.
>From 8ebe5ae503a0f6955456bc94dc9c771cc579d533 Mon Sep 17 00:00:00 2001
From: Joachim Schmitz <[email protected]>
Date: Tue, 19 Feb 2013 11:09:44 +0000
Subject: [PATCH 1/3] build: fix numfmt build error on compilers without
__attribute
* src/numfmt.c (): Use the more standard _GL_ATTRIBUTE_PURE
which is elided where required.
Reported in http://bugs.gnu.org/10305
---
src/numfmt.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/numfmt.c b/src/numfmt.c
index 8c21c2b..f689a97 100644
--- a/src/numfmt.c
+++ b/src/numfmt.c
@@ -1194,8 +1194,7 @@ process_suffixed_number (char *text, long double *result, size_t *precision)
/* Skip the requested number of fields in the input string.
Returns a pointer to the *delimiter* of the requested field,
or a pointer to NUL (if reached the end of the string). */
-static inline char *
-__attribute ((pure))
+static inline char * _GL_ATTRIBUTE_PURE
skip_fields (char *buf, int fields)
{
char *ptr = buf;
--
1.7.7.6
>From 43cdfc6863831fdeea76718d7d759de2893d650f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 19 Feb 2013 10:58:51 +0000
Subject: [PATCH 2/3] maint: cleaup up various uses of __attribute__
* src/cfg.mk (sc_prohibit-gl-attributes): Disallow the __attribute()
form without trailing underscores as that is not elided where required.
Also ensure we use gnulib macros rather than defining our own.
* src/system.h: Remove gnulib provided macros.
* gl/lib/randread.c: Use gnulib provided macros.
* src/chown-core.c: Likewise.
* src/chroot.c: Likewise.
* src/copy.c: Likewise.
* src/csplit.c: Likewise.
* src/dd.c: Likewise.
* src/expr.c: Likewise.
* src/extent-scan.c: Likewise.
* src/factor.c: Likewise.
* src/ls.c: Likewise.
* src/od.c: Likewise.
* src/paste.c: Likewise.
* src/ptx.c: Likewise.
* src/sort.c: Likewise.
* src/stat.c: Likewise.
* src/stty.c: Likewise.
* src/system.h: Likewise.
* src/tac.c: Likewise.
* src/test.c: Likewise.
* src/tsort.c: Likewise.
---
cfg.mk | 10 ++++++++++
gl/lib/randread.c | 12 +-----------
src/chown-core.c | 2 +-
src/chroot.c | 2 +-
src/copy.c | 20 ++++++++++----------
src/csplit.c | 6 +++---
src/dd.c | 2 +-
src/expr.c | 4 ++--
src/extent-scan.c | 2 +-
src/factor.c | 14 +++++++-------
src/ls.c | 2 +-
src/od.c | 10 +++++-----
src/paste.c | 2 +-
src/ptx.c | 2 +-
src/sort.c | 6 +++---
src/stat.c | 2 +-
src/stty.c | 2 +-
src/system.h | 10 +---------
src/tac.c | 2 +-
src/test.c | 4 ++--
src/tsort.c | 2 +-
21 files changed, 55 insertions(+), 63 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index c9952d2..4ee3809 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -201,6 +201,16 @@ sc_prohibit-j-printf-format:
&& { echo '$(ME): Use PRI*MAX instead of %j' 1>&2; exit 1; } \
|| :
+# Ensure the alternative __attribute (keyword) form isn't used as
+# that form is not elided where required. Also ensure that we don't
+# directly use attributes already defined by gnulib.
+# TODO: move the check for _GL... attributes to gnulib.
+sc_prohibit-gl-attributes:
+ @cd $(srcdir) && GIT_PAGER= git grep -En \
+ "__attribute |__(noreturn|unused|pure|const)__" src gl/lib/*.[ch] \
+ && { echo '$(ME): Use _GL... attribute macros' 1>&2; exit 1; } \
+ || :
+
# Look for lines longer than 80 characters, except omit:
# - program-generated long lines in diff headers,
# - tests involving long checksum lines, and
diff --git a/gl/lib/randread.c b/gl/lib/randread.c
index dfba611..9e272ec 100644
--- a/gl/lib/randread.c
+++ b/gl/lib/randread.c
@@ -46,16 +46,6 @@
#include "unlocked-io.h"
#include "xalloc.h"
-#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-# define __attribute__(x) /* empty */
-# endif
-#endif
-
-#ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
-#endif
-
#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
@@ -120,7 +110,7 @@ struct randread_source
/* The default error handler. */
-static void ATTRIBUTE_NORETURN
+static void _Noreturn
randread_error (void const *file_name)
{
if (file_name)
diff --git a/src/chown-core.c b/src/chown-core.c
index 3a3044e..a5a2b47 100644
--- a/src/chown-core.c
+++ b/src/chown-core.c
@@ -68,7 +68,7 @@ chopt_init (struct Chown_option *chopt)
}
extern void
-chopt_free (struct Chown_option *chopt ATTRIBUTE_UNUSED)
+chopt_free (struct Chown_option *chopt _GL_UNUSED)
{
/* Deliberately do not free chopt->user_name or ->group_name.
They're not always allocated. */
diff --git a/src/chroot.c b/src/chroot.c
index 1c1a976..bb45825 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -57,7 +57,7 @@ static struct option const long_opts[] =
always-successful replacement to avoid checking for setgroups
availability everywhere, just to support broken platforms. */
static int
-setgroups (size_t size ATTRIBUTE_UNUSED, gid_t const *list ATTRIBUTE_UNUSED)
+setgroups (size_t size _GL_UNUSED, gid_t const *list ATTRIBUTE_UNUSED)
{
return 0;
}
diff --git a/src/copy.c b/src/copy.c
index 3f2cc2b..244313e 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -471,7 +471,7 @@ errno_unsupported (int err)
#if USE_XATTR
static void
-copy_attr_error (struct error_context *ctx ATTRIBUTE_UNUSED,
+copy_attr_error (struct error_context *ctx _GL_UNUSED,
char const *fmt, ...)
{
if (!errno_unsupported (errno))
@@ -487,7 +487,7 @@ copy_attr_error (struct error_context *ctx ATTRIBUTE_UNUSED,
}
static void
-copy_attr_allerror (struct error_context *ctx ATTRIBUTE_UNUSED,
+copy_attr_allerror (struct error_context *ctx _GL_UNUSED,
char const *fmt, ...)
{
int err = errno;
@@ -500,14 +500,14 @@ copy_attr_allerror (struct error_context *ctx ATTRIBUTE_UNUSED,
}
static char const *
-copy_attr_quote (struct error_context *ctx ATTRIBUTE_UNUSED, char const *str)
+copy_attr_quote (struct error_context *ctx _GL_UNUSED, char const *str)
{
return quote (str);
}
static void
-copy_attr_free (struct error_context *ctx ATTRIBUTE_UNUSED,
- char const *str ATTRIBUTE_UNUSED)
+copy_attr_free (struct error_context *ctx _GL_UNUSED,
+ char const *str _GL_UNUSED)
{
}
@@ -539,11 +539,11 @@ copy_attr (char const *src_path, int src_fd,
#else /* USE_XATTR */
static bool
-copy_attr (char const *src_path ATTRIBUTE_UNUSED,
- int src_fd ATTRIBUTE_UNUSED,
- char const *dst_path ATTRIBUTE_UNUSED,
- int dst_fd ATTRIBUTE_UNUSED,
- struct cp_options const *x ATTRIBUTE_UNUSED)
+copy_attr (char const *src_path _GL_UNUSED,
+ int src_fd _GL_UNUSED,
+ char const *dst_path _GL_UNUSED,
+ int dst_fd _GL_UNUSED,
+ struct cp_options const *x _GL_UNUSED)
{
return true;
}
diff --git a/src/csplit.c b/src/csplit.c
index 22f3ad4..86d1b28 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -205,7 +205,7 @@ cleanup (void)
sigprocmask (SIG_SETMASK, &oldset, NULL);
}
-static void cleanup_fatal (void) ATTRIBUTE_NORETURN;
+static void cleanup_fatal (void) _Noreturn;
static void
cleanup_fatal (void)
{
@@ -691,7 +691,7 @@ dump_rest_of_file (void)
on iteration REPETITION if nonzero. */
static void handle_line_error (const struct control *, uintmax_t)
- ATTRIBUTE_NORETURN;
+ _Noreturn;
static void
handle_line_error (const struct control *p, uintmax_t repetition)
{
@@ -739,7 +739,7 @@ process_line_count (const struct control *p, uintmax_t repetition)
handle_line_error (p, repetition);
}
-static void regexp_error (struct control *, uintmax_t, bool) ATTRIBUTE_NORETURN;
+static void regexp_error (struct control *, uintmax_t, bool) _Noreturn;
static void
regexp_error (struct control *p, uintmax_t repetition, bool ignore)
{
diff --git a/src/dd.c b/src/dd.c
index c98e578..ff401f8 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -852,7 +852,7 @@ process_signals (void)
}
}
-static void ATTRIBUTE_NORETURN
+static void _Noreturn
quit (int code)
{
cleanup ();
diff --git a/src/expr.c b/src/expr.c
index b4fa808..dbbac79 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -44,7 +44,7 @@
int, the widest unsigned type that GMP supports. */
verify (SIZE_MAX <= ULONG_MAX);
-static void integer_overflow (char) ATTRIBUTE_NORETURN;
+static void integer_overflow (char) _Noreturn;
#ifndef HAVE_GMP
# define HAVE_GMP 0
@@ -287,7 +287,7 @@ integer_overflow (char op)
}
static void die (int errno_val, char const *msg)
- ATTRIBUTE_NORETURN;
+ _Noreturn;
static void
die (int errno_val, char const *msg)
{
diff --git a/src/extent-scan.c b/src/extent-scan.c
index 5d25b9a..6d3032a7 100644
--- a/src/extent-scan.c
+++ b/src/extent-scan.c
@@ -218,7 +218,7 @@ extent_scan_read (struct extent_scan *scan)
}
#else
extern bool
-extent_scan_read (struct extent_scan *scan ATTRIBUTE_UNUSED)
+extent_scan_read (struct extent_scan *scan _GL_UNUSED)
{
scan->initial_scan_failed = true;
errno = ENOTSUP;
diff --git a/src/factor.c b/src/factor.c
index 8f1542a..257a7ed 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -791,7 +791,7 @@ factor_using_division (uintmax_t *t1p, uintmax_t t1, uintmax_t t0,
{
for (;;)
{
- uintmax_t q1, q0, hi, lo ATTRIBUTE_UNUSED;
+ uintmax_t q1, q0, hi, lo _GL_UNUSED;
q0 = t0 * primes_dtab[i].binv;
umul_ppmm (hi, lo, q0, p);
@@ -933,7 +933,7 @@ static const unsigned char binvert_table[128] =
_q0 = (u0) * _di; \
if ((u1) >= (d)) \
{ \
- uintmax_t _p1, _p0 ATTRIBUTE_UNUSED; \
+ uintmax_t _p1, _p0 _GL_UNUSED; \
umul_ppmm (_p1, _p0, _q0, d); \
(q1) = ((u1) - _p1) * _di; \
(q0) = _q0; \
@@ -948,7 +948,7 @@ static const unsigned char binvert_table[128] =
/* x B (mod n). */
#define redcify(r_prim, r, n) \
do { \
- uintmax_t _redcify_q ATTRIBUTE_UNUSED; \
+ uintmax_t _redcify_q _GL_UNUSED; \
udiv_qrnnd (_redcify_q, r_prim, r, 0, n); \
} while (0)
@@ -981,7 +981,7 @@ static const unsigned char binvert_table[128] =
static inline uintmax_t
mulredc (uintmax_t a, uintmax_t b, uintmax_t m, uintmax_t mi)
{
- uintmax_t rh, rl, q, th, tl ATTRIBUTE_UNUSED, xh;
+ uintmax_t rh, rl, q, th, tl _GL_UNUSED, xh;
umul_ppmm (rh, rl, a, b);
q = rl * mi;
@@ -1001,7 +1001,7 @@ mulredc2 (uintmax_t *r1p,
uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0,
uintmax_t m1, uintmax_t m0, uintmax_t mi)
{
- uintmax_t r1, r0, q, p1, p0 ATTRIBUTE_UNUSED, t1, t0, s1, s0;
+ uintmax_t r1, r0, q, p1, p0 _GL_UNUSED, t1, t0, s1, s0;
mi = -mi;
assert ( (a1 >> (W_TYPE_SIZE - 1)) == 0);
assert ( (b1 >> (W_TYPE_SIZE - 1)) == 0);
@@ -1271,7 +1271,7 @@ prime_p (uintmax_t n)
a_prim = s0 % n;
else
{
- uintmax_t dummy ATTRIBUTE_UNUSED;
+ uintmax_t dummy _GL_UNUSED;
udiv_qrnnd (dummy, a_prim, s1, s0, n);
}
}
@@ -1803,7 +1803,7 @@ isqrt2 (uintmax_t nh, uintmax_t nl)
/* Do we need more than one iteration? */
for (;;)
{
- uintmax_t r ATTRIBUTE_UNUSED;
+ uintmax_t r _GL_UNUSED;
uintmax_t q, y;
udiv_qrnnd (q, r, nh, nl, x);
y = (x + q) / 2;
diff --git a/src/ls.c b/src/ls.c
index f1ed43b..d9876f8 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -2734,7 +2734,7 @@ has_capability (char const *name)
}
#else
static bool
-has_capability (char const *name ATTRIBUTE_UNUSED)
+has_capability (char const *name _GL_UNUSED)
{
errno = ENOTSUP;
return false;
diff --git a/src/od.c b/src/od.c
index ffccd74..e7d881b 100644
--- a/src/od.c
+++ b/src/od.c
@@ -416,7 +416,7 @@ N (size_t fields, size_t blank, void const *block, \
PRINT_FIELDS (N, T, fmt_string, xprintf (fmt_string, adjusted_width, x))
#define PRINT_FLOATTYPE(N, T, FTOASTR, BUFSIZE) \
- PRINT_FIELDS (N, T, fmt_string ATTRIBUTE_UNUSED, \
+ PRINT_FIELDS (N, T, fmt_string _GL_UNUSED, \
char buf[BUFSIZE]; \
FTOASTR (buf, sizeof buf, 0, 0, x); \
xprintf ("%*s", adjusted_width, buf))
@@ -452,7 +452,7 @@ dump_hexl_mode_trailer (size_t n_bytes, const char *block)
static void
print_named_ascii (size_t fields, size_t blank, void const *block,
- const char *unused_fmt_string ATTRIBUTE_UNUSED,
+ const char *unused_fmt_string _GL_UNUSED,
int width, int pad)
{
unsigned char const *p = block;
@@ -483,7 +483,7 @@ print_named_ascii (size_t fields, size_t blank, void const *block,
static void
print_ascii (size_t fields, size_t blank, void const *block,
- const char *unused_fmt_string ATTRIBUTE_UNUSED, int width,
+ const char *unused_fmt_string _GL_UNUSED, int width,
int pad)
{
unsigned char const *p = block;
@@ -1056,8 +1056,8 @@ skip (uintmax_t n_skip)
}
static void
-format_address_none (uintmax_t address ATTRIBUTE_UNUSED,
- char c ATTRIBUTE_UNUSED)
+format_address_none (uintmax_t address _GL_UNUSED,
+ char c _GL_UNUSED)
{
}
diff --git a/src/paste.c b/src/paste.c
index bc9fa76..91fa5b8 100644
--- a/src/paste.c
+++ b/src/paste.c
@@ -153,7 +153,7 @@ collapse_escapes (char const *strptr)
/* Report a write error and exit. */
-static void write_error (void) ATTRIBUTE_NORETURN;
+static void write_error (void) _Noreturn;
static void
write_error (void)
{
diff --git a/src/ptx.c b/src/ptx.c
index f993673..29d8417 100644
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -277,7 +277,7 @@ static BLOCK reference; /* reference field for input reference mode */
/* Diagnose an error in the regular expression matcher. Then exit. */
-static void ATTRIBUTE_NORETURN
+static void _Noreturn
matcher_error (void)
{
error (0, errno, _("error in regular expression matcher"));
diff --git a/src/sort.c b/src/sort.c
index 7410abc..aceb713 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -376,7 +376,7 @@ static unsigned int nmerge = NMERGE_DEFAULT;
/* Report MESSAGE for FILE, then clean up and exit.
If FILE is null, it represents standard output. */
-static void die (char const *, char const *) ATTRIBUTE_NORETURN;
+static void die (char const *, char const *) _Noreturn;
static void
die (char const *message, char const *file)
{
@@ -3969,7 +3969,7 @@ insertkey (struct keyfield *key_arg)
/* Report a bad field specification SPEC, with extra info MSGID. */
static void badfieldspec (char const *, char const *)
- ATTRIBUTE_NORETURN;
+ _Noreturn;
static void
badfieldspec (char const *spec, char const *msgid)
{
@@ -3980,7 +3980,7 @@ badfieldspec (char const *spec, char const *msgid)
/* Report incompatible options. */
-static void incompatible_options (char const *) ATTRIBUTE_NORETURN;
+static void incompatible_options (char const *) _Noreturn;
static void
incompatible_options (char const *opts)
{
diff --git a/src/stat.c b/src/stat.c
index dd210d1..2326698 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -583,7 +583,7 @@ out_minus_zero (char *pformat, size_t prefix_len)
acts like printf's %f format. */
static void
out_epoch_sec (char *pformat, size_t prefix_len,
- struct stat const *statbuf ATTRIBUTE_UNUSED,
+ struct stat const *statbuf _GL_UNUSED,
struct timespec arg)
{
char *dot = memchr (pformat, '.', prefix_len);
diff --git a/src/stty.c b/src/stty.c
index ee891a5..e518839 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -745,7 +745,7 @@ main (int argc, char **argv)
int argi = 0;
int opti = 1;
bool require_set_attr;
- bool speed_was_set ATTRIBUTE_UNUSED;
+ bool speed_was_set _GL_UNUSED;
bool verbose_output;
bool recoverable_output;
int k;
diff --git a/src/system.h b/src/system.h
index 1677999..31f1c5a 100644
--- a/src/system.h
+++ b/src/system.h
@@ -421,14 +421,6 @@ enum
# endif
#endif
-#ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
-#endif
-
-#ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-#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)
@@ -620,7 +612,7 @@ usable_st_size (struct stat const *sb)
|| S_TYPEISSHM (sb) || S_TYPEISTMO (sb));
}
-void usage (int status) ATTRIBUTE_NORETURN;
+void usage (int status) _Noreturn;
#define emit_cycle_warning(file_name) \
do \
diff --git a/src/tac.c b/src/tac.c
index c6a8cf6..5bf40a7 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -409,7 +409,7 @@ record_or_unlink_tempfile (char const *fn, FILE *fp)
#else
static void
-record_or_unlink_tempfile (char const *fn, FILE *fp ATTRIBUTE_UNUSED)
+record_or_unlink_tempfile (char const *fn, FILE *fp _GL_UNUSED)
{
unlink (fn);
}
diff --git a/src/test.c b/src/test.c
index 2038209..72ddbd0 100644
--- a/src/test.c
+++ b/src/test.c
@@ -80,8 +80,8 @@ static bool and (void);
static bool or (void);
static void test_syntax_error (char const *format, char const *arg)
- ATTRIBUTE_NORETURN;
-static void beyond (void) ATTRIBUTE_NORETURN;
+ _Noreturn;
+static void beyond (void) _Noreturn;
static void
test_syntax_error (char const *format, char const *arg)
diff --git a/src/tsort.c b/src/tsort.c
index d22f1f0..93ff894 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -280,7 +280,7 @@ record_relation (struct item *j, struct item *k)
}
static bool
-count_items (struct item *unused ATTRIBUTE_UNUSED)
+count_items (struct item *unused _GL_UNUSED)
{
n_strings++;
return false;
--
1.7.7.6
>From 9df5bc69bade3b36de0bd136979177c94ca37ec7 Mon Sep 17 00:00:00 2001
From: Joachim Schmitz <[email protected]>
Date: Tue, 19 Feb 2013 11:36:57 +0000
Subject: [PATCH 3/3] copy: ensure the correct root ID is checked on all
platforms
* src/copy.c (copy_reg): Check ROOT_UID rather than 0 which is
significant on HP-NonStop.
---
src/copy.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/copy.c b/src/copy.c
index 244313e..5c0ee1e 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -51,6 +51,7 @@
#include "ignore-value.h"
#include "ioblksize.h"
#include "quote.h"
+#include "root-uid.h"
#include "same.h"
#include "savedir.h"
#include "stat-size.h"
@@ -1127,7 +1128,7 @@ preserve_metadata:
{
bool access_changed = false;
- if (!(sb.st_mode & S_IWUSR) && geteuid () != 0)
+ if (!(sb.st_mode & S_IWUSR) && geteuid () != ROOT_UID)
access_changed = fchmod_or_lchmod (dest_desc, dst_name, 0600) == 0;
if (!copy_attr (src_name, source_desc, dst_name, dest_desc, x)
@@ -2718,7 +2719,7 @@ cp_options_default (struct cp_options *x)
priv_freeset (pset);
}
#else
- x->chown_privileges = x->owner_privileges = (geteuid () == 0);
+ x->chown_privileges = x->owner_privileges = (geteuid () == ROOT_UID);
#endif
}
--
1.7.7.6