accton.c revision 201387
1264269Ssbruno/* 2264269Ssbruno * Copyright (c) 1988, 1993 3264269Ssbruno * The Regents of the University of California. All rights reserved. 4264269Ssbruno * 5264269Ssbruno * Redistribution and use in source and binary forms, with or without 6264269Ssbruno * modification, are permitted provided that the following conditions 7264269Ssbruno * are met: 8264269Ssbruno * 1. Redistributions of source code must retain the above copyright 9264269Ssbruno * notice, this list of conditions and the following disclaimer. 10264269Ssbruno * 2. Redistributions in binary form must reproduce the above copyright 11264269Ssbruno * notice, this list of conditions and the following disclaimer in the 12264269Ssbruno * documentation and/or other materials provided with the distribution. 13264269Ssbruno * 4. Neither the name of the University nor the names of its contributors 14264269Ssbruno * may be used to endorse or promote products derived from this software 15264269Ssbruno * without specific prior written permission. 16264269Ssbruno * 17264269Ssbruno * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18264269Ssbruno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19264269Ssbruno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20264269Ssbruno * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21264269Ssbruno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22264269Ssbruno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23264269Ssbruno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24264269Ssbruno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25264269Ssbruno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26264269Ssbruno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27264269Ssbruno * SUCH DAMAGE. 28264269Ssbruno */ 29264269Ssbruno 30264269Ssbruno#if 0 31264269Ssbruno#ifndef lint 32264269Ssbrunostatic const char copyright[] = 33264269Ssbruno"@(#) Copyright (c) 1988, 1993\n\ 34264269Ssbruno The Regents of the University of California. All rights reserved.\n"; 35264269Ssbruno#endif /* not lint */ 36264269Ssbruno 37264269Ssbruno#ifndef lint 38264269Ssbrunostatic char sccsid[] = "@(#)accton.c 8.1 (Berkeley) 6/6/93"; 39264269Ssbruno#endif /* not lint */ 40264269Ssbruno#endif 41264269Ssbruno#include <sys/cdefs.h> 42264269Ssbruno__FBSDID("$FreeBSD: head/usr.sbin/accton/accton.c 201387 2010-01-02 11:05:34Z ed $"); 43266272Ssbruno 44300060Spfg#include <sys/types.h> 45264269Ssbruno#include <err.h> 46264269Ssbruno#include <stdio.h> 47264269Ssbruno#include <stdlib.h> 48264269Ssbruno#include <string.h> 49264269Ssbruno#include <unistd.h> 50264269Ssbruno 51264269Ssbrunostatic void usage(void); 52264269Ssbruno 53264269Ssbrunoint 54264269Ssbrunomain(int argc, char *argv[]) 55264269Ssbruno{ 56264269Ssbruno int ch; 57264269Ssbruno 58264269Ssbruno while ((ch = getopt(argc, argv, "")) != -1) 59264269Ssbruno switch(ch) { 60264269Ssbruno case '?': 61264269Ssbruno default: 62264269Ssbruno usage(); 63264269Ssbruno } 64264269Ssbruno argc -= optind; 65264269Ssbruno argv += optind; 66264269Ssbruno 67264269Ssbruno switch(argc) { 68264269Ssbruno case 0: 69264269Ssbruno if (acct(NULL)) 70264269Ssbruno err(1, NULL); 71264269Ssbruno break; 72264269Ssbruno case 1: 73266272Ssbruno if (acct(*argv)) 74264269Ssbruno err(1, "%s", *argv); 75264269Ssbruno break; 76264269Ssbruno default: 77264269Ssbruno usage(); 78264269Ssbruno } 79264269Ssbruno exit(0); 80264269Ssbruno} 81264269Ssbruno 82264269Ssbrunostatic void 83264269Ssbrunousage(void) 84264269Ssbruno{ 85266272Ssbruno (void)fprintf(stderr, "usage: accton [file]\n"); 86264269Ssbruno exit(1); 87264269Ssbruno} 88264269Ssbruno