xref: /illumos-gate/usr/src/cmd/bnu/statlog.c (revision 2a8bcb4e)
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 #include "uucp.h"
31 
32 int Retries;
33 
34 /*
35 	Report and log file transfer rate statistics.
36 	This is ugly because we are not using floating point.
37 */
38 
39 void
statlog(direction,bytes,millisecs,breakmsg)40 statlog( direction, bytes, millisecs, breakmsg)
41 char		*direction;
42 unsigned long	bytes;
43 time_t		millisecs;
44 char		*breakmsg; /* "PARTIAL FILE" or "" */
45 {
46 	char		text[ 100 ];
47 	unsigned long	bytes1000;
48 
49 	/* bytes1000 = bytes * 1000; */
50 	/* on fast machines, times(2) resolution may not be enough */
51 	/* so millisecs may be zero.  just use 1 as best guess */
52 	if ( millisecs == 0 )
53 		millisecs = 1;
54 
55 
56 	if (bytes < 1<<22)
57 		bytes1000 = (bytes*1000/millisecs);
58 	else
59 		bytes1000 = ((bytes/millisecs)*1000);
60 
61 	(void) sprintf(text, "%s %lu / %lu.%.3lu secs, %lu bytes/sec %s",
62 		direction, bytes, millisecs/1000, millisecs%1000,
63 		bytes1000, breakmsg );
64 	if (Retries) {
65 		sprintf(text + strlen(text), " %d retries", Retries);
66 		Retries = 0;
67 	}
68 		/* bytes1000/millisecs, breakmsg ); */
69 	CDEBUG(4, "%s\n", text);
70 	usyslog(text);
71 	return;
72 }
73 
74 static unsigned long	filesize;	/* size of file been
75 					transferred or received */
76 /*
77 	return the size of file been transferred or received
78 */
79 unsigned long
getfilesize()80 getfilesize()
81 {
82 	return(filesize);
83 }
84 
85 /*
86 	update the size of file been transferred or received
87 */
88 void
putfilesize(bytes)89 putfilesize(bytes)
90 unsigned long bytes;
91 {
92 	filesize = bytes;
93 	return;
94 }
95