summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-11-11 06:07:57 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-11-11 06:07:57 +0000
commit9d8ce0f399c4b173e090ca375e353ecc8fa4c8f9 (patch)
tree3200e2cd05e1d88efb35ff5afef4e8808e798042
parentd2b4386d2918d43e48e4ea42fcae314af346edd2 (diff)
downloadcoreutils-9d8ce0f399c4b173e090ca375e353ecc8fa4c8f9.tar.xz
Sync from gnulib.
-rw-r--r--lib/ChangeLog3
-rw-r--r--lib/getdate.y23
-rw-r--r--lib/quotearg.c5
-rw-r--r--lib/strftime.c23
4 files changed, 43 insertions, 11 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index e90fd062e..76c16dcaf 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,6 +1,7 @@
2004-11-10 Paul Eggert <eggert@cs.ucla.edu>
- * allocsa.h, mbswidth.c, mktime.c, readlink.c: Sync from gnulib.
+ * allocsa.h, mbswidth.c, mktime.c, readlink.c, getdate.y,
+ quotearg.c, strftime.c: Sync from gnulib.
2004-11-06 Jim Meyering <jim@meyering.net>
diff --git a/lib/getdate.y b/lib/getdate.y
index a4a445da0..2f72f045a 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -84,6 +84,21 @@
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
+/* Shift A right by B bits portably, by dividing A by 2**B and
+ truncating towards minus infinity. A and B should be free of side
+ effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
+ INT_BITS is the number of useful bits in an int. GNU code can
+ assume that INT_BITS is at least 32.
+
+ ISO C99 says that A >> B is implementation-defined if A < 0. Some
+ implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
+ right in the usual way when A < 0, so SHR falls back on division if
+ ordinary A >> B doesn't seem to be the usual signed shift. */
+#define SHR(a, b) \
+ (-1 >> 1 == -1 \
+ ? (a) >> (b) \
+ : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
+
#define EPOCH_YEAR 1970
#define TM_YEAR_BASE 1900
@@ -734,12 +749,12 @@ tm_diff (struct tm const *a, struct tm const *b)
{
/* Compute intervening leap days correctly even if year is negative.
Take care to avoid int overflow in leap day calculations. */
- int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
- int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
+ int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
+ int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
int a100 = a4 / 25 - (a4 % 25 < 0);
int b100 = b4 / 25 - (b4 % 25 < 0);
- int a400 = a100 >> 2;
- int b400 = b100 >> 2;
+ int a400 = SHR (a100, 2);
+ int b400 = SHR (b100, 2);
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
long int ayear = a->tm_year;
long int years = ayear - b->tm_year;
diff --git a/lib/quotearg.c b/lib/quotearg.c
index 64fa67635..8c95b7ae5 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -84,7 +84,7 @@ struct quoting_options
/* Quote the characters indicated by this bit vector even if the
quoting style would not normally require them to be quoted. */
- int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
+ unsigned int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
};
/* Names of quoting styles. */
@@ -152,7 +152,8 @@ int
set_char_quoting (struct quoting_options *o, char c, int i)
{
unsigned char uc = c;
- int *p = (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
+ unsigned int *p =
+ (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
int shift = uc % INT_BITS;
int r = (*p >> shift) & 1;
*p ^= ((i & 1) ^ r) << shift;
diff --git a/lib/strftime.c b/lib/strftime.c
index 2ef27c22a..e74e35a2f 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -104,6 +104,21 @@ extern char *tzname[];
# endif
#endif
+/* Shift A right by B bits portably, by dividing A by 2**B and
+ truncating towards minus infinity. A and B should be free of side
+ effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
+ INT_BITS is the number of useful bits in an int. GNU code can
+ assume that INT_BITS is at least 32.
+
+ ISO C99 says that A >> B is implementation-defined if A < 0. Some
+ implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
+ right in the usual way when A < 0, so SHR falls back on division if
+ ordinary A >> B doesn't seem to be the usual signed shift. */
+#define SHR(a, b) \
+ (-1 >> 1 == -1 \
+ ? (a) >> (b) \
+ : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
+
#define TYPE_SIGNED(t) ((t) -1 < 0)
/* Bound on length of the string representing an integer value of type t.
@@ -279,12 +294,12 @@ tm_diff (const struct tm *a, const struct tm *b)
/* Compute intervening leap days correctly even if year is negative.
Take care to avoid int overflow in leap day calculations,
but it's OK to assume that A and B are close to each other. */
- int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
- int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3);
+ int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
+ int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
int a100 = a4 / 25 - (a4 % 25 < 0);
int b100 = b4 / 25 - (b4 % 25 < 0);
- int a400 = a100 >> 2;
- int b400 = b100 >> 2;
+ int a400 = SHR (a100, 2);
+ int b400 = SHR (b100, 2);
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
int years = a->tm_year - b->tm_year;
int days = (365 * years + intervening_leap_days