summaryrefslogtreecommitdiffstats
path: root/bin/dd/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dd/misc.c')
-rw-r--r--bin/dd/misc.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/bin/dd/misc.c b/bin/dd/misc.c
index 7e6932f..9b577ef 100644
--- a/bin/dd/misc.c
+++ b/bin/dd/misc.c
@@ -34,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: misc.c,v 1.2 1994/09/24 02:55:01 davidg Exp $
+ * $Id: misc.c,v 1.3 1996/11/12 23:09:15 phk Exp $
*/
#ifndef lint
@@ -42,6 +42,7 @@ static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/types.h>
+#include <sys/time.h>
#include <err.h>
#include <stdio.h>
@@ -49,7 +50,6 @@ static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <sys/time.h>
#include "dd.h"
#include "extern.h"
@@ -58,22 +58,13 @@ void
summary()
{
struct timeval tv;
- long msec;
+ double secs;
char buf[100];
- (void)gettimeofday(&tv, 0);
- tv.tv_sec -= st.start.tv_sec;
- tv.tv_usec -= st.start.tv_usec;
- if (tv.tv_usec < 0) {
- tv.tv_usec += 1000000;
- tv.tv_sec--;
- }
-
- msec = tv.tv_sec * 1000;
- msec += tv.tv_usec / 1000;
-
- if (msec == 0)
- msec = 1;
+ (void)gettimeofday(&tv, (struct timezone *)NULL);
+ secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
+ if (secs < 1e-6)
+ secs = 1e-6;
/* Use snprintf(3) so that we don't reenter stdio(3). */
(void)snprintf(buf, sizeof(buf),
"%u+%u records in\n%u+%u records out\n",
@@ -89,15 +80,9 @@ summary()
st.trunc, (st.trunc == 1) ? "block" : "blocks");
(void)write(STDERR_FILENO, buf, strlen(buf));
}
- if (msec > 1000000) {
- (void)snprintf(buf, sizeof(buf),
- "%u bytes transferred in %u.%03d secs (%u bytes/sec)\n",
- st.bytes, tv.tv_sec, 0, st.bytes / tv.tv_sec);
- } else {
- (void)snprintf(buf, sizeof(buf),
- "%u bytes transferred in %u.%03d secs (%u bytes/sec)\n",
- st.bytes, msec/1000, msec%1000, st.bytes*1000 / msec);
- }
+ (void)snprintf(buf, sizeof(buf),
+ "%u bytes transferred in %.6f secs (%.0f bytes/sec)\n",
+ st.bytes, secs, st.bytes / secs);
(void)write(STDERR_FILENO, buf, strlen(buf));
}
OpenPOWER on IntegriCloud