--- /dev/null
+@@
+expression x, y;
+@@
+- ((x + y - 1) / y)
++ DIV_ROUND_UP(x, y)
+@@
+expression x, y;
+@@
+- ((x + (y - 1)) / y)
++ DIV_ROUND_UP(x, y)
+@@
+expression x, y;
+@@
+- (x + y - 1) / y
++ DIV_ROUND_UP(x, y)
+@@
+expression x, y;
+@@
+- (x + (y - 1)) / y
++ DIV_ROUND_UP(x, y)
} else if (c->repeat > 0) {
int k;
- k = start + c->repeat * ((*val - start + c->repeat - 1) / c->repeat);
+ k = start + c->repeat * DIV_ROUND_UP(*val - start, c->repeat);
if ((!d_set || k < d) && (stop < 0 || k <= stop)) {
d = k;
* default action terminating the process, and turn on alarm(). */
if (timeout != USEC_INFINITY)
- alarm((timeout + USEC_PER_SEC - 1) / USEC_PER_SEC);
+ alarm(DIV_ROUND_UP(timeout, USEC_PER_SEC));
STRV_FOREACH(path, paths) {
_cleanup_free_ char *t = NULL;
if (len <= 0)
return len;
- lines = (len + width - 1) / width;
+ lines = DIV_ROUND_UP(len, width);
slen = strlen_ptr(sep);
t = realloc(*prefix, plen + 1 + slen + (indent + width + 1) * lines);
param.timeout.timeout = 0;
else
/* Convert to seconds, rounding up. */
- param.timeout.timeout = (usec + USEC_PER_SEC - 1) / USEC_PER_SEC;
+ param.timeout.timeout = DIV_ROUND_UP(usec, USEC_PER_SEC);
if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, ¶m) < 0)
return -errno;
assert(n_columns > 0);
n = strv_length(x);
- per_column = (n + n_columns - 1) / n_columns;
+ per_column = DIV_ROUND_UP(n, n_columns);
break_lines = lines();
if (break_lines > 2)
}
/* Increase by larger blocks at once */
- new_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE;
+ new_size = DIV_ROUND_UP(new_size, FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE;
if (f->metrics.max_size > 0 && new_size > f->metrics.max_size)
new_size = f->metrics.max_size;
int sec, flags;
char buf[FORMAT_TIMESPAN_MAX];
- sec = (int) ((watchdog_timeout + USEC_PER_SEC - 1) / USEC_PER_SEC);
+ sec = (int) DIV_ROUND_UP(watchdog_timeout, USEC_PER_SEC);
r = ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &sec);
if (r < 0)
return log_warning_errno(errno, "Failed to set timeout to %is: %m", sec);
break;
}
case 't': {
+ int r, seconds;
usec_t s;
- int seconds;
- int r;
r = parse_sec(optarg, &s);
if (r < 0)
return log_error_errno(r, "Failed to parse timeout value '%s'.", optarg);
- if (((s + USEC_PER_SEC - 1) / USEC_PER_SEC) > INT_MAX)
+ if (DIV_ROUND_UP(s, USEC_PER_SEC) > INT_MAX)
log_error("Timeout value is out of range.");
else {
- seconds = s != USEC_INFINITY ? (int) ((s + USEC_PER_SEC - 1) / USEC_PER_SEC) : INT_MAX;
+ seconds = s != USEC_INFINITY ? (int) DIV_ROUND_UP(s, USEC_PER_SEC) : INT_MAX;
timeout = seconds;
rc = 0;
}