summaryrefslogtreecommitdiff
path: root/lib/xnanosleep.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-08-02 23:00:15 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-08-02 23:00:15 +0000
commit126d5f94370e93fbf361b24dbba9ceba920c58fc (patch)
treeacba685fbd0bb0605cb070a65cd2976491cf18ba /lib/xnanosleep.c
parent3afb4dad992fc1cde1642bf96e8ea4aa5fd5aabf (diff)
downloadcoreutils-126d5f94370e93fbf361b24dbba9ceba920c58fc.tar.xz
Include limits.h, stdbool.h.
(CHAR_BIT): Remove. (timespec_subtract, xnanosleep): Use bool for booleans.
Diffstat (limited to 'lib/xnanosleep.c')
-rw-r--r--lib/xnanosleep.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/xnanosleep.c b/lib/xnanosleep.c
index 70badf431..4bb217a3d 100644
--- a/lib/xnanosleep.c
+++ b/lib/xnanosleep.c
@@ -1,5 +1,5 @@
/* xnanosleep.c -- a more convenient interface to nanosleep
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,16 +22,14 @@
# include <config.h>
#endif
+#include <limits.h>
+#include <stdbool.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <time.h>
-#ifndef CHAR_BIT
-# define CHAR_BIT 8
-#endif
-
/* The extra casts work around common compiler bugs. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
@@ -49,12 +47,12 @@
#include "xnanosleep.h"
/* Subtract the `struct timespec' values X and Y by computing X - Y.
- If the difference is negative or zero, return 0.
- Otherwise, return 1 and store the difference in DIFF.
+ If the difference is negative or zero, return false.
+ Otherwise, return true and store the difference in DIFF.
X and Y must have valid ts_nsec values, in the range 0 to 999999999.
If the difference would overflow, store the maximum possible difference. */
-static int
+static bool
timespec_subtract (struct timespec *diff,
struct timespec const *x, struct timespec const *y)
{
@@ -62,7 +60,7 @@ timespec_subtract (struct timespec *diff,
long int nsec = x->tv_nsec - y->tv_nsec;
if (x->tv_sec < y->tv_sec)
- return 0;
+ return false;
if (sec < 0)
{
@@ -71,7 +69,7 @@ timespec_subtract (struct timespec *diff,
nsec = 999999999;
}
else if (sec == 0 && nsec <= 0)
- return 0;
+ return false;
if (nsec < 0)
{
@@ -81,7 +79,7 @@ timespec_subtract (struct timespec *diff,
diff->tv_sec = sec;
diff->tv_nsec = nsec;
- return 1;
+ return true;
}
/* Sleep until the time (call it WAKE_UP_TIME) specified as
@@ -94,7 +92,7 @@ timespec_subtract (struct timespec *diff,
int
xnanosleep (double seconds)
{
- int overflow;
+ bool overflow;
double ns;
struct timespec ts_start;
struct timespec ts_sleep;