xref: /csrg-svn/libexec/lfs_cleanerd/misc.c (revision 55495)
1*55495Sbostic /*-
2*55495Sbostic  * Copyright (c) 1991 The Regents of the University of California.
3*55495Sbostic  * All rights reserved.
4*55495Sbostic  *
5*55495Sbostic  * Redistribution and use in source and binary forms, with or without
6*55495Sbostic  * modification, are permitted provided that the following conditions
7*55495Sbostic  * are met:
8*55495Sbostic  * 1. Redistributions of source code must retain the above copyright
9*55495Sbostic  *    notice, this list of conditions and the following disclaimer.
10*55495Sbostic  * 2. Redistributions in binary form must reproduce the above copyright
11*55495Sbostic  *    notice, this list of conditions and the following disclaimer in the
12*55495Sbostic  *    documentation and/or other materials provided with the distribution.
13*55495Sbostic  * 3. All advertising materials mentioning features or use of this software
14*55495Sbostic  *    must display the following acknowledgement:
15*55495Sbostic  *	This product includes software developed by the University of
16*55495Sbostic  *	California, Berkeley and its contributors.
17*55495Sbostic  * 4. Neither the name of the University nor the names of its contributors
18*55495Sbostic  *    may be used to endorse or promote products derived from this software
19*55495Sbostic  *    without specific prior written permission.
20*55495Sbostic  *
21*55495Sbostic  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22*55495Sbostic  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23*55495Sbostic  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24*55495Sbostic  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25*55495Sbostic  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*55495Sbostic  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27*55495Sbostic  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28*55495Sbostic  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29*55495Sbostic  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30*55495Sbostic  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*55495Sbostic  * SUCH DAMAGE.
32*55495Sbostic  */
33*55495Sbostic 
34*55495Sbostic #ifndef lint
35*55495Sbostic static char sccsid[] = "@(#)misc.c	5.1 (Berkeley) 9/19/91";
36*55495Sbostic #endif /* not lint */
37*55495Sbostic 
38*55495Sbostic #include <sys/types.h>
39*55495Sbostic #include <unistd.h>
40*55495Sbostic #include <errno.h>
41*55495Sbostic #include <stdlib.h>
42*55495Sbostic #include <stdio.h>
43*55495Sbostic #include <string.h>
44*55495Sbostic #include "extern.h"
45*55495Sbostic 
46*55495Sbostic void
47*55495Sbostic get(fd, off, p, len)
48*55495Sbostic 	int fd;
49*55495Sbostic 	off_t off;
50*55495Sbostic 	void *p;
51*55495Sbostic 	size_t len;
52*55495Sbostic {
53*55495Sbostic 	int rbytes;
54*55495Sbostic 
55*55495Sbostic 	if (lseek(fd, off, SEEK_SET) < 0)
56*55495Sbostic 		err("%s: %s", special, strerror(errno));
57*55495Sbostic 	if ((rbytes = read(fd, p, len)) < 0)
58*55495Sbostic 		err("%s: %s", special, strerror(errno));
59*55495Sbostic 	if (rbytes != len)
60*55495Sbostic 		err("%s: short read (%d, not %d)", special, rbytes, len);
61*55495Sbostic }
62*55495Sbostic 
63*55495Sbostic #if __STDC__
64*55495Sbostic #include <stdarg.h>
65*55495Sbostic #else
66*55495Sbostic #include <varargs.h>
67*55495Sbostic #endif
68*55495Sbostic 
69*55495Sbostic void
70*55495Sbostic #if __STDC__
71*55495Sbostic err(const char *fmt, ...)
72*55495Sbostic #else
73*55495Sbostic err(fmt, va_alist)
74*55495Sbostic 	char *fmt;
75*55495Sbostic 	va_dcl
76*55495Sbostic #endif
77*55495Sbostic {
78*55495Sbostic 	va_list ap;
79*55495Sbostic #if __STDC__
80*55495Sbostic 	va_start(ap, fmt);
81*55495Sbostic #else
82*55495Sbostic 	va_start(ap);
83*55495Sbostic #endif
84*55495Sbostic 	(void)fprintf(stderr, "dumplfs: ");
85*55495Sbostic 	(void)vfprintf(stderr, fmt, ap);
86*55495Sbostic 	va_end(ap);
87*55495Sbostic 	(void)fprintf(stderr, "\n");
88*55495Sbostic 	exit(1);
89*55495Sbostic 	/* NOTREACHED */
90*55495Sbostic }
91