-/* Set B_NEW to the number of TOSIZE-byte blocks used by B FROMSIZE-byte
- blocks, rounding away from zero. TOSIZE must be positive. Return -1
- from invoking function if FROMSIZE is not positive. */
-
-#define ADJUST_BLOCKS(b_new, b, fromsize, tosize) \
- do \
- { \
- if ((tosize) <= 0) \
- abort (); \
- if ((fromsize) <= 0) \
- return -1; \
- \
- if ((fromsize) == (tosize)) /* E.g., from 512 to 512. */ \
- (b_new) = (b); \
- else if ((fromsize) > (tosize)) /* E.g., from 2048 to 512. */ \
- (b_new) = (b) * ((fromsize) / (tosize)); \
- else /* E.g., from 256 to 512. */ \
- (b_new) = ((b) + ((b) < 0 ? -1 : 1)) / ((tosize) / (fromsize)); \
- } \
- while (0)
+/* Many space usage primitives use all 1 bits to denote a value that is
+ not applicable or unknown. Propagate this information by returning
+ a uintmax_t value that is all 1 bits if the argument is all 1 bits,
+ even if the argument is unsigned and smaller than uintmax_t. */
+#define PROPAGATE_ALL_ONES(x) ((x) == -1 ? (uintmax_t) -1 : (uintmax_t) (x))
+
+/* Extract the top bit of X as an uintmax_t value. */
+#define EXTRACT_TOP_BIT(x) ((x) \
+ & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1)))
+
+/* If a value is negative, many space usage primitives store it into an
+ integer variable by assignment, even if the variable's type is unsigned.
+ So, if a space usage variable X's top bit is set, convert X to the
+ uintmax_t value V such that (- (uintmax_t) V) is the negative of
+ the original value. If X's top bit is clear, just yield X.
+ Use PROPAGATE_TOP_BIT if the original value might be negative;
+ otherwise, use PROPAGATE_ALL_ONES. */
+#define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1))
+
+int safe_read ();