xref: /titanic_50/usr/src/cmd/bnu/statlog.c (revision 554ff184129088135ad2643c1c9832174a17be88)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1988 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include "uucp.h"
34 
35 int Retries;
36 
37 /*
38 	Report and log file transfer rate statistics.
39 	This is ugly because we are not using floating point.
40 */
41 
42 void
43 statlog( direction, bytes, millisecs, breakmsg)
44 char		*direction;
45 unsigned long	bytes;
46 time_t		millisecs;
47 char		*breakmsg; /* "PARTIAL FILE" or "" */
48 {
49 	char		text[ 100 ];
50 	unsigned long	bytes1000;
51 
52 	/* bytes1000 = bytes * 1000; */
53 	/* on fast machines, times(2) resolution may not be enough */
54 	/* so millisecs may be zero.  just use 1 as best guess */
55 	if ( millisecs == 0 )
56 		millisecs = 1;
57 
58 
59 	if (bytes < 1<<22)
60 		bytes1000 = (bytes*1000/millisecs);
61 	else
62 		bytes1000 = ((bytes/millisecs)*1000);
63 
64 	(void) sprintf(text, "%s %lu / %lu.%.3lu secs, %lu bytes/sec %s",
65 		direction, bytes, millisecs/1000, millisecs%1000,
66 		bytes1000, breakmsg );
67 	if (Retries) {
68 		sprintf(text + strlen(text), " %d retries", Retries);
69 		Retries = 0;
70 	}
71 		/* bytes1000/millisecs, breakmsg ); */
72 	CDEBUG(4, "%s\n", text);
73 	usyslog(text);
74 	return;
75 }
76 
77 static unsigned long	filesize;	/* size of file been
78 					transferred or received */
79 /*
80 	return the size of file been transferred or received
81 */
82 unsigned long
83 getfilesize()
84 {
85 	return(filesize);
86 }
87 
88 /*
89 	update the size of file been transferred or received
90 */
91 void
92 putfilesize(bytes)
93 unsigned long bytes;
94 {
95 	filesize = bytes;
96 	return;
97 }
98