head.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <string.h>
#include <ctype.h>
#define DEF_LINE_COUNT 10
static void Usage();
/*
* head - give the first few lines of a stream or of each of a set of files
*
*/
int
{
int fileCount;
int around = 0;
int i;
int opt;
int error = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/* check for non-standard "-line-count" option */
for (i = 1; i < argc; i++) {
break;
"%s: Badly formed number\n"), argv[0]);
Usage();
}
10);
while (i < argc) {
i++;
}
argc--;
}
}
/* get options */
switch (opt) {
case 'n':
"%s: Missing -n argument\n"), argv[0]),
Usage();
}
if (linecnt <= 0) {
"%s: Invalid \"-n %s\" option\n"),
Usage();
}
break;
default:
Usage();
}
}
do {
break;
(void) close(0);
error = 1;
optind++;
continue;
}
}
if (around)
(void) putchar('\n');
if (fileCount > 1)
optind++;
around++;
return (error);
}
static void
{
/* only count as a line if buffer read ends with newline */
cnt--;
}
}
}
}
static void
Usage()
{
exit(1);
}