file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.sbin / sendmail / mailstats / mailstats.c
CommitLineData
aeb2545d 1/*
5e8b0e60 2 * Copyright (c) 1983 Eric P. Allman
502cf5c0
KB
3 * Copyright (c) 1988 Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms are permitted
5e8b0e60
KB
7 * provided that the above copyright notice and this paragraph are
8 * duplicated in all such forms and that any documentation,
9 * advertising materials, and other materials related to such
10 * distribution and use acknowledge that the software was developed
11 * by the University of California, Berkeley. The name of the
12 * University may not be used to endorse or promote products derived
13 * from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
502cf5c0 17 *
502cf5c0 18 */
aeb2545d
DF
19
20#ifndef lint
21char copyright[] =
502cf5c0 22"@(#) Copyright (c) 1988 Regents of the University of California.\n\
aeb2545d 23 All rights reserved.\n";
502cf5c0 24#endif /* not lint */
aeb2545d
DF
25
26#ifndef lint
7abf8d65 27static char sccsid[] = "@(#)mailstats.c 5.6 (Berkeley) %G%";
502cf5c0 28#endif /* not lint */
9064e1ea 29
502cf5c0
KB
30#include <sys/file.h>
31#include <sendmail.h>
32#include <mailstats.h>
7abf8d65 33#include "pathnames.h"
9064e1ea
EA
34
35main(argc, argv)
502cf5c0
KB
36 int argc;
37 char **argv;
9064e1ea 38{
502cf5c0
KB
39 extern char *optarg;
40 extern int optind;
9064e1ea 41 struct statistics stat;
9064e1ea 42 register int i;
502cf5c0
KB
43 int ch, fd;
44 char *sfile, *ctime();
9064e1ea 45
7abf8d65 46 sfile = _PATH_MAILSTATS;
502cf5c0
KB
47 while ((ch = getopt(argc, argv, "f:")) != EOF)
48 switch((char)ch) {
49 case 'f':
50 sfile = optarg;
51 break;
52 case '?':
53 default:
54 fputs("usage: mailstats [-f file]\n", stderr);
55 exit(EX_USAGE);
56 }
57 argc -= optind;
58 argv += optind;
59
60 if ((fd = open(sfile, O_RDONLY)) < 0) {
61 fputs("mailstats: ", stderr);
9064e1ea
EA
62 perror(sfile);
63 exit(EX_NOINPUT);
64 }
502cf5c0
KB
65 if (read(fd, &stat, sizeof(stat)) != sizeof(stat) ||
66 stat.stat_size != sizeof(stat)) {
67 fputs("mailstats: file size changed.\n", stderr);
9064e1ea
EA
68 exit(EX_OSERR);
69 }
70
387e90c7 71 printf("Statistics from %s", ctime(&stat.stat_itime));
9064e1ea
EA
72 printf(" M msgsfr bytes_from msgsto bytes_to\n");
73 for (i = 0; i < MAXMAILERS; i++)
502cf5c0
KB
74 if (stat.stat_nf[i] || stat.stat_nt[i])
75 printf("%2d %6ld %10ldK %6ld %10ldK\n", i,
76 stat.stat_nf[i], stat.stat_bf[i],
77 stat.stat_nt[i], stat.stat_bt[i]);
78 exit(0);
9064e1ea 79}