xref: /illumos-gate/usr/src/cmd/tail/extern.h (revision 72102e74)
1209e49b2SChris Love /*
2209e49b2SChris Love  * Copyright (c) 1991, 1993
3209e49b2SChris Love  *	The Regents of the University of California.  All rights reserved.
4209e49b2SChris Love  *
5209e49b2SChris Love  * Redistribution and use in source and binary forms, with or without
6209e49b2SChris Love  * modification, are permitted provided that the following conditions
7209e49b2SChris Love  * are met:
8209e49b2SChris Love  * 1. Redistributions of source code must retain the above copyright
9209e49b2SChris Love  *    notice, this list of conditions and the following disclaimer.
10209e49b2SChris Love  * 2. Redistributions in binary form must reproduce the above copyright
11209e49b2SChris Love  *    notice, this list of conditions and the following disclaimer in the
12209e49b2SChris Love  *    documentation and/or other materials provided with the distribution.
13209e49b2SChris Love  * 4. Neither the name of the University nor the names of its contributors
14209e49b2SChris Love  *    may be used to endorse or promote products derived from this software
15209e49b2SChris Love  *    without specific prior written permission.
16209e49b2SChris Love  *
17209e49b2SChris Love  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18209e49b2SChris Love  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19209e49b2SChris Love  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20209e49b2SChris Love  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21209e49b2SChris Love  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22209e49b2SChris Love  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23209e49b2SChris Love  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24209e49b2SChris Love  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25209e49b2SChris Love  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26209e49b2SChris Love  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27209e49b2SChris Love  * SUCH DAMAGE.
28209e49b2SChris Love  *
29209e49b2SChris Love  */
30209e49b2SChris Love 
31*72102e74SBryan Cantrill #ifndef	_TAIL_EXTERN_H
32*72102e74SBryan Cantrill #define	_TAIL_EXTERN_H
33*72102e74SBryan Cantrill 
34*72102e74SBryan Cantrill #include <sys/types.h>
35*72102e74SBryan Cantrill #include <sys/stat.h>
36*72102e74SBryan Cantrill #include <port.h>
37209e49b2SChris Love 
38209e49b2SChris Love #define	WR(p, size) do { \
39209e49b2SChris Love 	if (write(STDOUT_FILENO, p, size) != (ssize_t)size) \
40209e49b2SChris Love 		oerr(); \
41209e49b2SChris Love 	} while (0)
42209e49b2SChris Love 
43209e49b2SChris Love #define	TAILMAPLEN (4<<20)
44209e49b2SChris Love 
45209e49b2SChris Love struct mapinfo {
46209e49b2SChris Love 	off_t	mapoff;
47209e49b2SChris Love 	off_t	maxoff;
48209e49b2SChris Love 	size_t	maplen;
49209e49b2SChris Love 	char	*start;
50209e49b2SChris Love 	int	fd;
51209e49b2SChris Love };
52209e49b2SChris Love 
53209e49b2SChris Love struct file_info {
54209e49b2SChris Love 	FILE *fp;
55209e49b2SChris Love 	char *file_name;
56209e49b2SChris Love 	struct stat st;
57*72102e74SBryan Cantrill 	file_obj_t fobj[2];
58209e49b2SChris Love };
59209e49b2SChris Love 
60209e49b2SChris Love typedef struct file_info file_info_t;
61209e49b2SChris Love 
62209e49b2SChris Love enum STYLE { NOTSET = 0, FBYTES, FLINES, RBYTES, RLINES, REVERSE };
63209e49b2SChris Love 
64209e49b2SChris Love void follow(file_info_t *, enum STYLE, off_t);
65209e49b2SChris Love void forward(FILE *, const char *, enum STYLE, off_t, struct stat *);
66209e49b2SChris Love void reverse(FILE *, const char *, enum STYLE, off_t, struct stat *);
67209e49b2SChris Love 
68209e49b2SChris Love int bytes(FILE *, const char *, off_t);
69209e49b2SChris Love int lines(FILE *, const char *, off_t);
70209e49b2SChris Love 
71209e49b2SChris Love void ierr(const char *);
72209e49b2SChris Love void oerr(void);
73209e49b2SChris Love int mapprint(struct mapinfo *, off_t, off_t);
74209e49b2SChris Love int maparound(struct mapinfo *, off_t);
75209e49b2SChris Love 
76209e49b2SChris Love extern int Fflag, fflag, qflag, rflag, rval, no_files;
77*72102e74SBryan Cantrill 
78*72102e74SBryan Cantrill #endif	/* _TAIL_EXTERN_H */
79