Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:19

0001 /*-
0002  * Copyright (c) 1991, 1993, 1994
0003  *  The Regents of the University of California.  All rights reserved.
0004  *
0005  * This code is derived from software contributed to Berkeley by
0006  * Keith Muller of the University of California, San Diego and Lance
0007  * Visser of Convex Computer Corporation.
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  * 4. Neither the name of the University nor the names of its contributors
0018  *    may be used to endorse or promote products derived from this software
0019  *    without specific prior written permission.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0031  * SUCH DAMAGE.
0032  */
0033 
0034 #ifdef HAVE_CONFIG_H
0035 #include "config.h"
0036 #endif
0037 
0038 #ifndef lint
0039 #if 0
0040 static char sccsid[] = "@(#)misc.c  8.3 (Berkeley) 4/2/94";
0041 #endif
0042 #endif /* not lint */
0043 #if 0
0044 #include <sys/cdefs.h>
0045 __FBSDID("$FreeBSD: src/bin/dd/misc.c,v 1.27 2004/04/06 20:06:46 markm Exp $");
0046 #endif
0047 
0048 #include <sys/types.h>
0049 #include <sys/time.h>
0050 
0051 #include <errno.h>
0052 #include <inttypes.h>
0053 #include <stdio.h>
0054 #include <stdlib.h>
0055 #include <string.h>
0056 #include <unistd.h>
0057 
0058 #include "dd.h"
0059 #include "extern-dd.h"
0060 
0061 void
0062 summary(rtems_shell_dd_globals* globals)
0063 {
0064     struct timeval tv;
0065     double secs;
0066     char buf[100];
0067 
0068     (void)gettimeofday(&tv, (struct timezone *)NULL);
0069     secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
0070     if (secs < 1e-6)
0071         secs = 1e-6;
0072     /* Use snprintf(3) so that we don't reenter stdio(3). */
0073     (void)snprintf(buf, sizeof(buf),
0074         "%ju+%ju records in\n%ju+%ju records out\n",
0075         st.in_full, st.in_part, st.out_full, st.out_part);
0076     (void)write(STDERR_FILENO, buf, strlen(buf));
0077     if (st.swab) {
0078         (void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
0079              st.swab, (st.swab == 1) ? "block" : "blocks");
0080         (void)write(STDERR_FILENO, buf, strlen(buf));
0081     }
0082     if (st.trunc) {
0083         (void)snprintf(buf, sizeof(buf), "%ju truncated %s\n",
0084              st.trunc, (st.trunc == 1) ? "block" : "blocks");
0085         (void)write(STDERR_FILENO, buf, strlen(buf));
0086     }
0087     (void)snprintf(buf, sizeof(buf),
0088         "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
0089         st.bytes, secs, st.bytes / secs);
0090     (void)write(STDERR_FILENO, buf, strlen(buf));
0091 }
0092 
0093 /* ARGSUSED */
0094 void
0095 summaryx(rtems_shell_dd_globals* globals, int __unused_arg)
0096 {
0097     int save_errno = errno;
0098 
0099     summary(globals);
0100     errno = save_errno;
0101 }
0102 
0103 #if RTEMS_REMOVED
0104 /* ARGSUSED */
0105 void
0106 terminate(int sig)
0107 {
0108 
0109     summary();
0110     _exit(sig == 0 ? 0 : 1);
0111 }
0112 #endif